### Java SDK Quick Start Example Source: https://docs.z.ai/guides/overview/quick-start This example demonstrates how to initialize the Z.AI client and create a chat completion request. ```java import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; import com.openai.models.chat.completions.ChatCompletion; import com.openai.models.chat.completions.ChatCompletionCreateParams; public class QuickStart { public static void main(String[] args) { // Initialize client OpenAIClient client = OpenAIOkHttpClient.builder() .apiKey("your-Z.AI-api-key") .baseUrl("https://api.z.ai/api/paas/v4/") .build(); // Create chat completion request ChatCompletionCreateParams params = ChatCompletionCreateParams.builder() .addSystemMessage("You are a helpful AI assistant.") .addUserMessage("Hello, please introduce yourself.") .model("glm-5.2") .build(); // Send request and get response ChatCompletion chatCompletion = client.chat().completions().create(params); Object response = chatCompletion.choices().get(0).message().content(); System.out.println(response); } } ``` -------------------------------- ### Install OpenAI Node.js SDK Source: https://docs.z.ai/guides/overview/quick-start Install or upgrade the OpenAI Node.js SDK using npm or yarn. ```bash # Install or upgrade to latest version npm install openai # Or using yarn yarn add openai ``` -------------------------------- ### Verify Z.AI Python SDK Installation Source: https://docs.z.ai/guides/overview/quick-start Verify the installation by printing the installed SDK version. ```python import zai print(zai.__version__) ``` -------------------------------- ### Install OpenAI Python SDK Source: https://docs.z.ai/guides/overview/quick-start Install or upgrade to the latest version of the OpenAI Python SDK. ```bash # Install or upgrade to latest version pip install --upgrade 'openai>=1.0' ``` -------------------------------- ### Z.AI Java SDK Usage Example Source: https://docs.z.ai/guides/overview/quick-start Initialize the ZaiClient and create a chat completion request. Replace 'YOUR_API_KEY' with your actual API key. ```java import ai.z.openapi.ZaiClient; import ai.z.openapi.service.model.*; import java.util.Arrays; public class QuickStart { public static void main(String[] args) { // Initialize client ZaiClient client = ZaiClient.builder().ofZAI() .apiKey("YOUR_API_KEY") .build(); // Create chat completion request ChatCompletionCreateParams request = ChatCompletionCreateParams.builder() .model("glm-5.2") .messages(Arrays.asList( ChatMessage.builder() .role(ChatMessageRole.USER.value()) .content("Hello, who are you?") .build() )) .stream(false) .build(); // Send request ChatCompletionResponse response = client.chat().createChatCompletion(request); // Get response System.out.println(response.getData().getChoices().get(0).getMessage().getContent()); } } ``` -------------------------------- ### Verify OpenAI Python SDK Installation Source: https://docs.z.ai/guides/overview/quick-start Verify the installation of the OpenAI Python SDK. ```python python -c "import openai; print(openai.__version__)" ``` -------------------------------- ### Z.AI Python SDK Usage Example Source: https://docs.z.ai/guides/overview/quick-start Initialize the ZaiClient and create a chat completion request. Ensure you replace 'YOUR_API_KEY' with your actual API key. ```python from zai import ZaiClient # Initialize client client = ZaiClient(api_key="YOUR_API_KEY") # Create chat completion request response = client.chat.completions.create( model="glm-5.2", messages=[ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ] ) # Get response print(response.choices[0].message.content) ``` -------------------------------- ### Install Z.AI Python SDK Source: https://docs.z.ai/guides/overview/quick-start Install the latest version of the Z.AI Python SDK using pip. You can also specify a version. ```bash # Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.2.3 ``` -------------------------------- ### OpenAI Python SDK Usage Example Source: https://docs.z.ai/guides/overview/quick-start Initialize the OpenAI client with your Z.AI API key and base URL. Then, create a chat completion request. ```python from openai import OpenAI client = OpenAI( api_key="your-Z.AI-api-key", base_url="https://api.z.ai/api/paas/v4/" ) completion = client.chat.completions.create( model="glm-5.2", messages=[ {"role": "system", "content": "You are a smart and creative novelist"}, {"role": "user", "content": "Please write a short fairy tale story as a fairy tale master"} ] ) print(completion.choices[0].message.content) ``` -------------------------------- ### OpenAI Node.js SDK Usage Example Source: https://docs.z.ai/guides/overview/quick-start Initialize the OpenAI client with your Z.AI API key and base URL. Then, create a chat completion request asynchronously. ```javascript import OpenAI from "openai"; const client = new OpenAI({ apiKey: "your-Z.AI-api-key", baseURL: "https://api.z.ai/api/paas/v4/" }); async function main() { const completion = await client.chat.completions.create({ model: "glm-5.2", messages: [ { role: "system", content: "You are a helpful AI assistant." }, { role: "user", content: "Hello, please introduce yourself." } ] }); console.log(completion.choices[0].message.content); } main(); ``` -------------------------------- ### Install Z.AI Java SDK with Maven Source: https://docs.z.ai/guides/overview/quick-start Add the Z.AI Java SDK dependency to your Maven project. ```xml ai.z.openapi zai-sdk 0.3.5 ``` -------------------------------- ### Install Z.AI Java SDK with Gradle Source: https://docs.z.ai/guides/overview/quick-start Add the Z.AI Java SDK dependency to your Gradle project. ```groovy implementation 'ai.z.openapi:zai-sdk:0.3.5' ``` -------------------------------- ### Install OpenAI Java SDK with Maven Source: https://docs.z.ai/guides/overview/quick-start Add the OpenAI Java SDK dependency to your Maven project. ```xml com.openai openai-java 2.20.1 ``` -------------------------------- ### Make Chat Completion API Call with cURL Source: https://docs.z.ai/guides/overview/quick-start Use this cURL command to make a chat completion API call. Ensure you replace 'YOUR_API_KEY' with your actual API key and select the appropriate model and endpoint. ```bash curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \ -H "Content-Type: application/json" \ -H "Accept-Language: en-US,en" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "model": "glm-5.2", "messages": [ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ] }' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.