public abstract static class AbstractAiClient.AbstractBuilder<T extends AbstractAiClient,B extends AbstractAiClient.AbstractBuilder<T,B>> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected ZaiConfig |
config
Configuration object that accumulates all builder settings
|
| Constructor and Description |
|---|
AbstractBuilder() |
AbstractBuilder(String apiKey)
Creates a new builder with the specified API key.
|
AbstractBuilder(String baseUrl,
String apiKey)
Creates a new builder with a custom base URL and API secret key.
|
| Modifier and Type | Method and Description |
|---|---|
B |
apiKey(String apiKey)
Config the apikey
|
B |
baseUrl(String baseUrl)
Config the api service base url
|
abstract T |
build()
Builds and returns a new AI client instance with the configured settings.
|
B |
connectionPool(int maxIdleConnections,
long keepAliveDuration,
TimeUnit timeUnit)
Configures the HTTP connection pool settings.
|
B |
customHeaders(Map<String,String> customHeaders)
Config the custom headers
|
B |
disableTokenCache()
Disables token caching, forcing the client to use API keys for direct requests.
|
B |
enableTokenCache()
Enables token caching, allowing the client to use access tokens for requests.
|
B |
networkConfig(int requestTimeOut,
int connectTimeout,
int readTimeout,
int writeTimeout,
TimeUnit timeUnit)
Configures network request timeout settings.
|
protected B |
self()
Returns this builder instance with proper type casting for method chaining.
|
B |
tokenExpire(int expireMillis)
Sets the token expiration time in milliseconds.
|
protected final ZaiConfig config
public AbstractBuilder()
public AbstractBuilder(String apiKey)
apiKey - the API key for authenticationIllegalArgumentException - if apiKey is null or emptypublic AbstractBuilder(String baseUrl, String apiKey)
baseUrl - the custom base URL for the API endpointapiKey - the API secret key for authenticationIllegalArgumentException - if any parameter is null or emptyprotected B self()
public B baseUrl(String baseUrl)
baseUrl - base urlpublic B apiKey(String apiKey)
apiKey - api keypublic B customHeaders(Map<String,String> customHeaders)
customHeaders - custom headerspublic B disableTokenCache()
public B enableTokenCache()
public B connectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit)
maxIdleConnections - maximum number of idle connections to keep in the
poolkeepAliveDuration - how long to keep idle connections alivetimeUnit - the time unit for the keep alive durationpublic B tokenExpire(int expireMillis)
expireMillis - the token expiration time in millisecondspublic B networkConfig(int requestTimeOut, int connectTimeout, int readTimeout, int writeTimeout, TimeUnit timeUnit)
requestTimeOut - the overall request timeout, 0 is no timeoutconnectTimeout - the connection timeoutreadTimeout - the read timeoutwriteTimeout - the write timeouttimeUnit - the time unit for all timeout valuespublic abstract T build()
IllegalStateException - if the configuration is invalidCopyright © 2025. All rights reserved.