# Client configuration

Canonical page: https://docs.ovok.com/java-sdk/client-configuration

Build an `OvokConfig` and pass it to `new Ovok(config)`.

```java
Ovok ovok = new Ovok(OvokConfig.builder()
        .baseUrl("https://api.sandbox.ovok.com")
        .tenantCode("your-tenant")
        .timeout(Duration.ofSeconds(30))
        .maxNetworkRetries(2)
        .build());
```

| Option | Default | Description |
| --- | --- | --- |
| `baseUrl` | required | Absolute `http` or `https` URL of the Ovok API. Accepts a `String` or `URI`. |
| `tenantCode` | required | Tenant the client signs in to. CMS reads always include it. |
| `fhirPath` | `fhir` | Path of the FHIR API under `baseUrl`. |
| `clientId` | none | OAuth client ID. Required when `clientSecret` is set. |
| `clientSecret` | none | Switches the client to [machine credentials](#machine-clients). |
| `storage` | in memory | `OvokStorage` that keeps the user session. |
| `transport` | `HttpClient.newHttpClient()` | Java `HttpClient`, for proxy or executor settings. |
| `timeout` | 30 seconds | Default request timeout. |
| `maxNetworkRetries` | 2 | Retries for transient failures of idempotent requests. |
| `onUnauthenticated` | no-op | Receives an `UnauthenticatedReason` when the token service rejects the session. |

An invalid option throws `OvokConfigException` from `build()`.

## Session storage [#session-storage]

The default storage keeps the session in memory, so it is lost when the process exits. To keep it, implement `OvokStorage`:

```java
public interface OvokStorage {
    String getItem(String key);
    void setItem(String key, String value);
    void removeItem(String key);
}
```

The client stores the session under `ovok:<tenantCode>:session`.

## Machine clients [#machine-clients]

Set `clientId` and `clientSecret` to use client credentials. The client fetches and refreshes its own token. User sign-in methods such as `login` throw `OvokConfigException` on a machine client.

```java
Ovok machineClient = new Ovok(OvokConfig.builder()
        .baseUrl("https://api.sandbox.ovok.com")
        .tenantCode("your-tenant")
        .clientId(System.getenv("OVOK_CLIENT_ID"))
        .clientSecret(System.getenv("OVOK_CLIENT_SECRET"))
        .build());
```
