翻篇收录说明
翻篇网页快照

Introduction - Overview - Z.AI DEVELOPER DOCUMENT

https://docs.z.ai/api-reference/introduction

最近抓取:2026-12-04 04:04:04(北京时间)

最近内容变化:2026-12-04 04:04:04(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

正文摘录

The API reference describes the RESTful APIs you can use to interact with the Z.AI platform. Z.AI provides standard HTTP API interfaces that support multiple programming languages and development environments, with SDKs also available. API Endpoint Z.ai Platform’s general API endpoint is as follows: https://api.z.ai/api/paas/v4 When using GLM Coding Plan, please follow the tutorial to configure your dedicated endpoint. Authentication The Z.AI API uses the standard HTTP Bearer for authentication. A Standard API Key is required, which you can create or manage on the API Keys Page. API keys should be provided via HTTP Bearer Authentication in HTTP Request Headers. Authorization: Bearer ZAI_API_KEY Playground The API Playground allows developers to quickly try out API calls. Simply click Try it on the API details page to get started. On the API details page, there are many interactive options, such as switching input types, switching tabs, and adding new content. You can click Add an item or Add new property to add more properties the API need. Note that when switching the tabs, the previous properties value you need re-input or re-switch. API Usage Bundle Billing Rules If you purchase an API usage bundle for a model, we will prioritize consuming the included usage quota from that bundle. Once the bundle is exhausted, your API access remains fully unaffected — you can continue making calls as usual with no service interruption whatsoever. The only change is that, going forward, each API call will be billed at the standard pay-as-you-go rate, with the corresponding charges deducted directly from your account. Call Examples cURL Official Python SDK Official Java SDK OpenAI Python SDK OpenAI NodeJs SDK OpenAI Java SDKcurl -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.4", "messages": [ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ], "temperature": 1.0, "stream": true }' Install SDK# Install latest version pip install zai-sdk # Or specify version pip install zai-sdk==0.2.3 Verify Installationimport zai print(zai.__version__) Usage Examplefrom zai import ZaiClient # Initialize client client = ZaiClient(api_key="YOUR_API_KEY") # Create chat completion request response = client.chat.completions.create( model="glm-5.4", 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 SDKMaven<dependency> <groupId>ai.z.openapi</groupId> <artifactId>zai-sdk</artifactId> <version>0.3.5</version> </dependency> Gradle (Groovy)implementation 'ai.z.openapi:zai-sdk:0.3.5' Usage Exampleimport 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.4") .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()); } } Install SDK# Install or upgrade to latest version pip install --upgrade 'openai>=1.0' Verify Installationpython -c "import openai; print(openai.__version__)" Usage Examplefrom 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.4", 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) Install SDK# Install or upgrade to latest version npm install openai # Or using yarn yarn add openai Usage Exampleimport 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.4", 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 SDKMaven<dependency> <groupId>com.openai</groupId> <artifactId>openai-java</artifactId> <version>2.20.1</version> </dependency> Gradle (Groovy)implementation 'com.openai:openai-java:2.20.1' Usage Exampleimport 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.4") .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); } } Was this page helpful?YesNo