Class OpenAIOkHttpClient.Builder
-
- All Implemented Interfaces:
public final class OpenAIOkHttpClient.Builder
A builder for OpenAIOkHttpClient.
-
-
Method Summary
Modifier and Type Method Description final OpenAIOkHttpClient.Builder
proxy(Proxy proxy)
final OpenAIOkHttpClient.Builder
proxy(Optional<Proxy> proxy)
Alias for calling Builder.proxy with proxy.orElse(null)
.final OpenAIOkHttpClient.Builder
sslSocketFactory(SSLSocketFactory sslSocketFactory)
The socket factory used to secure HTTPS connections. final OpenAIOkHttpClient.Builder
sslSocketFactory(Optional<SSLSocketFactory> sslSocketFactory)
Alias for calling Builder.sslSocketFactory with sslSocketFactory.orElse(null)
.final OpenAIOkHttpClient.Builder
trustManager(X509TrustManager trustManager)
The trust manager used to secure HTTPS connections. final OpenAIOkHttpClient.Builder
trustManager(Optional<X509TrustManager> trustManager)
Alias for calling Builder.trustManager with trustManager.orElse(null)
.final OpenAIOkHttpClient.Builder
hostnameVerifier(HostnameVerifier hostnameVerifier)
The verifier used to confirm that response certificates apply to requested hostnames for HTTPS connections. final OpenAIOkHttpClient.Builder
hostnameVerifier(Optional<HostnameVerifier> hostnameVerifier)
Alias for calling Builder.hostnameVerifier with hostnameVerifier.orElse(null)
.final OpenAIOkHttpClient.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). final OpenAIOkHttpClient.Builder
jsonMapper(JsonMapper jsonMapper)
The Jackson JSON mapper to use for serializing and deserializing JSON. final OpenAIOkHttpClient.Builder
streamHandlerExecutor(Executor streamHandlerExecutor)
The executor to use for running AsyncStreamResponse.Handler callbacks. final OpenAIOkHttpClient.Builder
clock(Clock clock)
The clock to use for operations that require timing, like retries. final OpenAIOkHttpClient.Builder
baseUrl(String baseUrl)
The base URL to use for every request. final OpenAIOkHttpClient.Builder
baseUrl(Optional<String> baseUrl)
Alias for calling Builder.baseUrl with baseUrl.orElse(null)
.final OpenAIOkHttpClient.Builder
responseValidation(Boolean responseValidation)
Whether to call validate
on every response before returning it.final OpenAIOkHttpClient.Builder
timeout(Timeout timeout)
Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding retries. final OpenAIOkHttpClient.Builder
timeout(Duration timeout)
Sets the maximum time allowed for a complete HTTP call, not including retries. final OpenAIOkHttpClient.Builder
maxRetries(Integer maxRetries)
The maximum number of times to retry failed requests, with a short exponential backoff between requests. final OpenAIOkHttpClient.Builder
apiKey(String apiKey)
final OpenAIOkHttpClient.Builder
credential(Credential credential)
final OpenAIOkHttpClient.Builder
azureServiceVersion(AzureOpenAIServiceVersion azureServiceVersion)
final OpenAIOkHttpClient.Builder
organization(String organization)
final OpenAIOkHttpClient.Builder
organization(Optional<String> organization)
Alias for calling Builder.organization with organization.orElse(null)
.final OpenAIOkHttpClient.Builder
project(String project)
final OpenAIOkHttpClient.Builder
project(Optional<String> project)
Alias for calling Builder.project with project.orElse(null)
.final OpenAIOkHttpClient.Builder
webhookSecret(String webhookSecret)
final OpenAIOkHttpClient.Builder
webhookSecret(Optional<String> webhookSecret)
Alias for calling Builder.webhookSecret with webhookSecret.orElse(null)
.final OpenAIOkHttpClient.Builder
headers(Headers headers)
final OpenAIOkHttpClient.Builder
headers(Map<String, Iterable<String>> headers)
final OpenAIOkHttpClient.Builder
putHeader(String name, String value)
final OpenAIOkHttpClient.Builder
putHeaders(String name, Iterable<String> values)
final OpenAIOkHttpClient.Builder
putAllHeaders(Headers headers)
final OpenAIOkHttpClient.Builder
putAllHeaders(Map<String, Iterable<String>> headers)
final OpenAIOkHttpClient.Builder
replaceHeaders(String name, String value)
final OpenAIOkHttpClient.Builder
replaceHeaders(String name, Iterable<String> values)
final OpenAIOkHttpClient.Builder
replaceAllHeaders(Headers headers)
final OpenAIOkHttpClient.Builder
replaceAllHeaders(Map<String, Iterable<String>> headers)
final OpenAIOkHttpClient.Builder
removeHeaders(String name)
final OpenAIOkHttpClient.Builder
removeAllHeaders(Set<String> names)
final OpenAIOkHttpClient.Builder
queryParams(QueryParams queryParams)
final OpenAIOkHttpClient.Builder
queryParams(Map<String, Iterable<String>> queryParams)
final OpenAIOkHttpClient.Builder
putQueryParam(String key, String value)
final OpenAIOkHttpClient.Builder
putQueryParams(String key, Iterable<String> values)
final OpenAIOkHttpClient.Builder
putAllQueryParams(QueryParams queryParams)
final OpenAIOkHttpClient.Builder
putAllQueryParams(Map<String, Iterable<String>> queryParams)
final OpenAIOkHttpClient.Builder
replaceQueryParams(String key, String value)
final OpenAIOkHttpClient.Builder
replaceQueryParams(String key, Iterable<String> values)
final OpenAIOkHttpClient.Builder
replaceAllQueryParams(QueryParams queryParams)
final OpenAIOkHttpClient.Builder
replaceAllQueryParams(Map<String, Iterable<String>> queryParams)
final OpenAIOkHttpClient.Builder
removeQueryParams(String key)
final OpenAIOkHttpClient.Builder
removeAllQueryParams(Set<String> keys)
final OpenAIOkHttpClient.Builder
fromEnv()
Updates configuration using system properties and environment variables. final OpenAIClient
build()
Returns an immutable instance of OpenAIClient. -
-
Method Detail
-
proxy
final OpenAIOkHttpClient.Builder proxy(Proxy proxy)
-
proxy
final OpenAIOkHttpClient.Builder proxy(Optional<Proxy> proxy)
Alias for calling Builder.proxy with
proxy.orElse(null)
.
-
sslSocketFactory
final OpenAIOkHttpClient.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory)
The socket factory used to secure HTTPS connections.
If this is set, then trustManager must also be set.
If unset, then the system default is used. Most applications should not call this method, and instead use the system default. The default include special optimizations that can be lost if the implementation is modified.
-
sslSocketFactory
final OpenAIOkHttpClient.Builder sslSocketFactory(Optional<SSLSocketFactory> sslSocketFactory)
Alias for calling Builder.sslSocketFactory with
sslSocketFactory.orElse(null)
.
-
trustManager
final OpenAIOkHttpClient.Builder trustManager(X509TrustManager trustManager)
The trust manager used to secure HTTPS connections.
If this is set, then sslSocketFactory must also be set.
If unset, then the system default is used. Most applications should not call this method, and instead use the system default. The default include special optimizations that can be lost if the implementation is modified.
-
trustManager
final OpenAIOkHttpClient.Builder trustManager(Optional<X509TrustManager> trustManager)
Alias for calling Builder.trustManager with
trustManager.orElse(null)
.
-
hostnameVerifier
final OpenAIOkHttpClient.Builder hostnameVerifier(HostnameVerifier hostnameVerifier)
The verifier used to confirm that response certificates apply to requested hostnames for HTTPS connections.
If unset, then a default hostname verifier is used.
-
hostnameVerifier
final OpenAIOkHttpClient.Builder hostnameVerifier(Optional<HostnameVerifier> hostnameVerifier)
Alias for calling Builder.hostnameVerifier with
hostnameVerifier.orElse(null)
.
-
checkJacksonVersionCompatibility
final OpenAIOkHttpClient.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 OpenAIOkHttpClient.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 OpenAIOkHttpClient.Builder streamHandlerExecutor(Executor streamHandlerExecutor)
The executor to use for running AsyncStreamResponse.Handler callbacks.
Defaults to a dedicated cached thread pool.
-
clock
final OpenAIOkHttpClient.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 OpenAIOkHttpClient.Builder baseUrl(String baseUrl)
The base URL to use for every request.
Defaults to the production environment:
https://api.openai.com/v1
.
-
baseUrl
final OpenAIOkHttpClient.Builder baseUrl(Optional<String> baseUrl)
Alias for calling Builder.baseUrl with
baseUrl.orElse(null)
.
-
responseValidation
final OpenAIOkHttpClient.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 OpenAIOkHttpClient.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 OpenAIOkHttpClient.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 OpenAIOkHttpClient.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 OpenAIOkHttpClient.Builder apiKey(String apiKey)
-
credential
final OpenAIOkHttpClient.Builder credential(Credential credential)
-
azureServiceVersion
final OpenAIOkHttpClient.Builder azureServiceVersion(AzureOpenAIServiceVersion azureServiceVersion)
-
organization
final OpenAIOkHttpClient.Builder organization(String organization)
-
organization
final OpenAIOkHttpClient.Builder organization(Optional<String> organization)
Alias for calling Builder.organization with
organization.orElse(null)
.
-
project
final OpenAIOkHttpClient.Builder project(String project)
-
project
final OpenAIOkHttpClient.Builder project(Optional<String> project)
Alias for calling Builder.project with
project.orElse(null)
.
-
webhookSecret
final OpenAIOkHttpClient.Builder webhookSecret(String webhookSecret)
-
webhookSecret
final OpenAIOkHttpClient.Builder webhookSecret(Optional<String> webhookSecret)
Alias for calling Builder.webhookSecret with
webhookSecret.orElse(null)
.
-
headers
final OpenAIOkHttpClient.Builder headers(Headers headers)
-
putHeader
final OpenAIOkHttpClient.Builder putHeader(String name, String value)
-
putHeaders
final OpenAIOkHttpClient.Builder putHeaders(String name, Iterable<String> values)
-
putAllHeaders
final OpenAIOkHttpClient.Builder putAllHeaders(Headers headers)
-
putAllHeaders
final OpenAIOkHttpClient.Builder putAllHeaders(Map<String, Iterable<String>> headers)
-
replaceHeaders
final OpenAIOkHttpClient.Builder replaceHeaders(String name, String value)
-
replaceHeaders
final OpenAIOkHttpClient.Builder replaceHeaders(String name, Iterable<String> values)
-
replaceAllHeaders
final OpenAIOkHttpClient.Builder replaceAllHeaders(Headers headers)
-
replaceAllHeaders
final OpenAIOkHttpClient.Builder replaceAllHeaders(Map<String, Iterable<String>> headers)
-
removeHeaders
final OpenAIOkHttpClient.Builder removeHeaders(String name)
-
removeAllHeaders
final OpenAIOkHttpClient.Builder removeAllHeaders(Set<String> names)
-
queryParams
final OpenAIOkHttpClient.Builder queryParams(QueryParams queryParams)
-
queryParams
final OpenAIOkHttpClient.Builder queryParams(Map<String, Iterable<String>> queryParams)
-
putQueryParam
final OpenAIOkHttpClient.Builder putQueryParam(String key, String value)
-
putQueryParams
final OpenAIOkHttpClient.Builder putQueryParams(String key, Iterable<String> values)
-
putAllQueryParams
final OpenAIOkHttpClient.Builder putAllQueryParams(QueryParams queryParams)
-
putAllQueryParams
final OpenAIOkHttpClient.Builder putAllQueryParams(Map<String, Iterable<String>> queryParams)
-
replaceQueryParams
final OpenAIOkHttpClient.Builder replaceQueryParams(String key, String value)
-
replaceQueryParams
final OpenAIOkHttpClient.Builder replaceQueryParams(String key, Iterable<String> values)
-
replaceAllQueryParams
final OpenAIOkHttpClient.Builder replaceAllQueryParams(QueryParams queryParams)
-
replaceAllQueryParams
final OpenAIOkHttpClient.Builder replaceAllQueryParams(Map<String, Iterable<String>> queryParams)
-
removeQueryParams
final OpenAIOkHttpClient.Builder removeQueryParams(String key)
-
removeAllQueryParams
final OpenAIOkHttpClient.Builder removeAllQueryParams(Set<String> keys)
-
fromEnv
final OpenAIOkHttpClient.Builder fromEnv()
Updates configuration using system properties and environment variables.
-
-
-
-