public class ZaiClient extends AbstractClientBaseService
The client supports both Z.ai and ZHIPU AI endpoints and provides thread-safe lazy initialization of services.
Example usage:
ZaiClient client = new ZaiClient.Builder("your-api-key")
.networkConfig(30, 10, 30, 30, TimeUnit.SECONDS)
.build();
ChatService chatService = client.chat();
// Use the chat service...
client.close(); // Don't forget to close when done
| Modifier and Type | Class and Description |
|---|---|
static class |
ZaiClient.Builder
Builder class for creating ZaiClient instances with custom configurations.
|
mapper| Constructor and Description |
|---|
ZaiClient(ZaiConfig config)
Constructs a new ZaiClient with the specified configuration.
|
| Modifier and Type | Method and Description |
|---|---|
AgentService |
agents()
Returns the agent service for AI agent management.
|
AssistantService |
assistants()
Returns the assistant service for AI assistant functionality.
|
AudioService |
audio()
Returns the audio service for audio processing.
|
BatchService |
batches()
Returns the batch service for batch processing operations.
|
<Data,F,Param,TReq extends ClientRequest<Param>,TResp extends BiFlowableClientResponse<Data,F>> |
biStreamRequest(TReq request,
FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier,
Class<TResp> tRespClass,
Class<F> tStreamDataClass)
Executes a streaming API request and returns a BiFlowableClientResponse where
response body and stream element type can differ.
|
static ZaiClient.Builder |
builder()
Creates a new Builder instance for constructing ZaiClient.
|
ChatService |
chat()
Returns the chat service for conversational AI operations.
|
void |
close()
Closes the ZAi client and releases all associated resources.
|
DocumentService |
documents()
Returns the document service for document processing.
|
EmbeddingService |
embeddings()
Returns the embedding service for text embeddings.
|
<Data,Param,TReq extends ClientRequest<Param>,TResp extends ClientResponse<Data>> |
executeRequest(TReq request,
RequestSupplier<Param,Data> requestSupplier,
Class<TResp> tRespClass)
Executes a synchronous API request and returns the response.
|
FileService |
files()
Returns the file service for file operations.
|
FineTuningService |
fineTuning()
Returns the fine-tuning service for model customization.
|
ImageService |
images()
Returns the image service for image generation and processing.
|
KnowledgeService |
knowledge()
Returns the knowledge service for knowledge base operations.
|
static ZaiClient.Builder |
ofZHIPU()
Creates a ZaiClient configured for ZHIPU AI platform with the specified API key.
|
static ZaiClient.Builder |
ofZHIPU(String apiKey)
Creates a ZaiClient configured for ZHIPU AI platform with the specified API key.
|
retrofit2.Retrofit |
retrofit()
Returns the underlying Retrofit instance used for API communication.
|
<Data,Param,TReq extends ClientRequest<Param>,TResp extends FlowableClientResponse<Data>> |
streamRequest(TReq request,
FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier,
Class<TResp> tRespClass,
Class<Data> tDataClass)
Executes a streaming API request and returns a FlowableClientResponse with stream
elements of type Data.
|
VideosService |
videos()
Returns the videos service for video processing.
|
WebSearchService |
webSearch()
Returns the web search service for internet search capabilities.
|
execute, stream, stream, streampublic ZaiClient(ZaiConfig config)
config - the configuration object containing API keys, timeouts, and other
settingsIllegalArgumentException - if config is null or invalidpublic ChatService chat()
public AgentService agents()
public EmbeddingService embeddings()
public FileService files()
public AudioService audio()
public ImageService images()
public BatchService batches()
public FineTuningService fineTuning()
public WebSearchService webSearch()
public VideosService videos()
public KnowledgeService knowledge()
public DocumentService documents()
public AssistantService assistants()
public retrofit2.Retrofit retrofit()
public void close()
Important: Always call this method when you're done with the client to prevent resource leaks.
public <Data,Param,TReq extends ClientRequest<Param>,TResp extends ClientResponse<Data>> TResp executeRequest(TReq request, RequestSupplier<Param,Data> requestSupplier, Class<TResp> tRespClass)
executeRequest in class AbstractClientBaseServiceData - the type of data expected in the responseParam - the type of parameters for the requestTReq - the type of client requestTResp - the type of client responserequest - the client request containing parametersrequestSupplier - the supplier that creates the actual API calltRespClass - the class of the response typepublic <Data,F,Param,TReq extends ClientRequest<Param>,TResp extends BiFlowableClientResponse<Data,F>> TResp biStreamRequest(TReq request, FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier, Class<TResp> tRespClass, Class<F> tStreamDataClass)
biStreamRequest in class AbstractClientBaseServiceData - type of response bodyF - type of each element in the stream (can be same as Data)Param - request param typeTReq - request typeTResp - response type (must extend BiFlowableClientResponse)request - the request objectrequestSupplier - the streaming API suppliertRespClass - the client response class (must implement
BiFlowableClientResponse)tStreamDataClass - the stream data element classpublic <Data,Param,TReq extends ClientRequest<Param>,TResp extends FlowableClientResponse<Data>> TResp streamRequest(TReq request, FlowableRequestSupplier<Param,retrofit2.Call<okhttp3.ResponseBody>> requestSupplier, Class<TResp> tRespClass, Class<Data> tDataClass)
streamRequest in class AbstractClientBaseServiceData - data type for both response and streamParam - request param typeTReq - request typeTResp - response type (must extend FlowableClientResponserequest - the request objectrequestSupplier - the streaming API suppliertRespClass - the client response class (must implement
FlowableClientResponse)tDataClass - the class representing stream data typepublic static ZaiClient.Builder builder()
public static ZaiClient.Builder ofZHIPU(String apiKey)
apiKey - the API key for authenticationIllegalArgumentException - if apiKey is null or emptypublic static ZaiClient.Builder ofZHIPU()
IllegalArgumentException - if apiKey is null or emptyCopyright © 2025. All rights reserved.