Class OkHttpClient.Builder
-
- All Implemented Interfaces:
public final class OkHttpClient.Builder
-
-
Method Summary
Modifier and Type Method Description final OkHttpClient.Buildertimeout(Timeout timeout)final OkHttpClient.Buildertimeout(Duration timeout)final OkHttpClient.Builderproxy(Proxy proxy)final OkHttpClient.BuildersslSocketFactory(SSLSocketFactory sslSocketFactory)final OkHttpClient.BuildertrustManager(X509TrustManager trustManager)final OkHttpClient.BuilderhostnameVerifier(HostnameVerifier hostnameVerifier)final OkHttpClient.Builderdispatcher(Dispatcher dispatcher)Sets a custom OkHttp Dispatcher for managing HTTP call execution. final OkHttpClientbuild()-
-
Method Detail
-
timeout
final OkHttpClient.Builder timeout(Timeout timeout)
-
timeout
final OkHttpClient.Builder timeout(Duration timeout)
-
proxy
final OkHttpClient.Builder proxy(Proxy proxy)
-
sslSocketFactory
final OkHttpClient.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory)
-
trustManager
final OkHttpClient.Builder trustManager(X509TrustManager trustManager)
-
hostnameVerifier
final OkHttpClient.Builder hostnameVerifier(HostnameVerifier hostnameVerifier)
-
dispatcher
final OkHttpClient.Builder dispatcher(Dispatcher dispatcher)
Sets a custom OkHttp Dispatcher for managing HTTP call execution.
The Dispatcher controls the maximum number of concurrent requests and requests per host. If not set, a default optimized dispatcher will be created based on the machine's CPU cores.
Important Notes:
The custom dispatcher will be used as-is. The SDK will NOT modify its configuration.
You should manually configure
maxRequestsandmaxRequestsPerHostaccording to your needs.It's recommended to set
maxRequestsPerHost = maxRequestsfor optimal performance when making requests to the same host (which is typical for OpenAI API calls).The dispatcher's lifecycle is managed by the OkHttpClient. When the client is closed, the dispatcher's executor service will be automatically shut down.
Do not share the same Dispatcher instance across multiple OkHttpClient instances.
Example:
val customDispatcher = okhttp3.Dispatcher().apply { maxRequests = 100 maxRequestsPerHost = 100 // Recommended: same as maxRequests } val client = OkHttpClient.builder() .dispatcher(customDispatcher) .build()- Parameters:
dispatcher- The custom dispatcher to use, or null to use the optimized default
-
build
final OkHttpClient build()
-
-
-
-