Class OkHttpClient.Builder

    • Constructor Detail

    • Method Detail

      • 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 maxRequests and maxRequestsPerHost according to your needs.

        • It's recommended to set maxRequestsPerHost = maxRequests for 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