Class ClientOptions.Builder
-
- All Implemented Interfaces:
public final class ClientOptions.Builder
A builder for ClientOptions.
-
-
Method Summary
-
-
Method Detail
-
httpClient
final ClientOptions.Builder httpClient(HttpClient httpClient)
The HTTP client to use in the SDK.
Use the one published in
openai-java-client-okhttp
or implement your own.
-
checkJacksonVersionCompatibility
final ClientOptions.Builder checkJacksonVersionCompatibility(Boolean checkJacksonVersionCompatibility)
Whether to throw an exception if any of the Jackson versions detected at runtime are incompatible with the SDK's minimum supported Jackson version (2.13.4).
Defaults to true. Use extreme caution when disabling this option. There is no guarantee that the SDK will work correctly when using an incompatible Jackson version.
-
jsonMapper
final ClientOptions.Builder jsonMapper(JsonMapper jsonMapper)
The Jackson JSON mapper to use for serializing and deserializing JSON.
Defaults to com.openai.core.jsonMapper. The default is usually sufficient and rarely needs to be overridden.
-
streamHandlerExecutor
final ClientOptions.Builder streamHandlerExecutor(Executor streamHandlerExecutor)
The executor to use for running AsyncStreamResponse.Handler callbacks.
Defaults to a dedicated cached thread pool.
-
clock
final ClientOptions.Builder clock(Clock clock)
The clock to use for operations that require timing, like retries.
This is primarily useful for using a fake clock in tests.
Defaults to Clock.systemUTC.
-
baseUrl
final ClientOptions.Builder baseUrl(String baseUrl)
The base URL to use for every request.
Defaults to the production environment:
https://api.openai.com/v1
.
-
baseUrl
final ClientOptions.Builder baseUrl(Optional<String> baseUrl)
Alias for calling Builder.baseUrl with
baseUrl.orElse(null)
.
-
responseValidation
final ClientOptions.Builder responseValidation(Boolean responseValidation)
Whether to call
validate
on every response before returning it.Defaults to false, which means the shape of the response will not be validated upfront. Instead, validation will only occur for the parts of the response that are accessed.
-
timeout
final ClientOptions.Builder timeout(Timeout timeout)
Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding retries.
Defaults to Timeout.default.
-
timeout
final ClientOptions.Builder timeout(Duration timeout)
Sets the maximum time allowed for a complete HTTP call, not including retries.
See Timeout.request for more details.
For fine-grained control, pass a Timeout object.
-
maxRetries
final ClientOptions.Builder maxRetries(Integer maxRetries)
The maximum number of times to retry failed requests, with a short exponential backoff between requests.
Only the following error types are retried:
Connection errors (for example, due to a network connectivity problem)
408 Request Timeout
409 Conflict
429 Rate Limit
5xx Internal
The API may also explicitly instruct the SDK to retry or not retry a request.
Defaults to 2.
-
apiKey
final ClientOptions.Builder apiKey(String apiKey)
-
credential
final ClientOptions.Builder credential(Credential credential)
-
azureServiceVersion
final ClientOptions.Builder azureServiceVersion(AzureOpenAIServiceVersion azureServiceVersion)
-
organization
final ClientOptions.Builder organization(String organization)
-
organization
final ClientOptions.Builder organization(Optional<String> organization)
Alias for calling Builder.organization with
organization.orElse(null)
.
-
project
final ClientOptions.Builder project(String project)
-
project
final ClientOptions.Builder project(Optional<String> project)
Alias for calling Builder.project with
project.orElse(null)
.
-
webhookSecret
final ClientOptions.Builder webhookSecret(String webhookSecret)
-
webhookSecret
final ClientOptions.Builder webhookSecret(Optional<String> webhookSecret)
Alias for calling Builder.webhookSecret with
webhookSecret.orElse(null)
.
-
headers
final ClientOptions.Builder headers(Headers headers)
-
putHeader
final ClientOptions.Builder putHeader(String name, String value)
-
putHeaders
final ClientOptions.Builder putHeaders(String name, Iterable<String> values)
-
putAllHeaders
final ClientOptions.Builder putAllHeaders(Headers headers)
-
putAllHeaders
final ClientOptions.Builder putAllHeaders(Map<String, Iterable<String>> headers)
-
replaceHeaders
final ClientOptions.Builder replaceHeaders(String name, String value)
-
replaceHeaders
final ClientOptions.Builder replaceHeaders(String name, Iterable<String> values)
-
replaceAllHeaders
final ClientOptions.Builder replaceAllHeaders(Headers headers)
-
replaceAllHeaders
final ClientOptions.Builder replaceAllHeaders(Map<String, Iterable<String>> headers)
-
removeHeaders
final ClientOptions.Builder removeHeaders(String name)
-
removeAllHeaders
final ClientOptions.Builder removeAllHeaders(Set<String> names)
-
queryParams
final ClientOptions.Builder queryParams(QueryParams queryParams)
-
queryParams
final ClientOptions.Builder queryParams(Map<String, Iterable<String>> queryParams)
-
putQueryParam
final ClientOptions.Builder putQueryParam(String key, String value)
-
putQueryParams
final ClientOptions.Builder putQueryParams(String key, Iterable<String> values)
-
putAllQueryParams
final ClientOptions.Builder putAllQueryParams(QueryParams queryParams)
-
putAllQueryParams
final ClientOptions.Builder putAllQueryParams(Map<String, Iterable<String>> queryParams)
-
replaceQueryParams
final ClientOptions.Builder replaceQueryParams(String key, String value)
-
replaceQueryParams
final ClientOptions.Builder replaceQueryParams(String key, Iterable<String> values)
-
replaceAllQueryParams
final ClientOptions.Builder replaceAllQueryParams(QueryParams queryParams)
-
replaceAllQueryParams
final ClientOptions.Builder replaceAllQueryParams(Map<String, Iterable<String>> queryParams)
-
removeQueryParams
final ClientOptions.Builder removeQueryParams(String key)
-
removeAllQueryParams
final ClientOptions.Builder removeAllQueryParams(Set<String> keys)
-
fromEnv
final ClientOptions.Builder fromEnv()
Updates configuration using system properties and environment variables.
See this table for the available options:
System properties take precedence over environment variables.
-
build
final ClientOptions build()
Returns an immutable instance of ClientOptions.
Further updates to this Builder will not mutate the returned instance.
The following fields are required:
.httpClient() .apiKey()
-
-
-
-