页面简介
正文摘录
Tired of limits? GLM Coding Plan — monthly access to world-class models for coding and office tasks, compatible with 20+ top agent tools. All from just $18/month. Try it now → Getting Started 1Get API Key Access Z.AI Open Platform, Register or Login. Access Billing Page to top up if needed. Create a Standard API Key in the API Keys management page. Copy your API Key for use. Z.AI Open PlatformAccess Z.AI Open Platform, Register or Login.API Keys ManagementCreate a Standard API Key in the API Keys management page. 2Choose Model The platform offers multiple models, and you can select the appropriate model based on your needs. For detailed model introductions, please refer to the Models & Agents. GLM-5.4Z.ai’s latest flagship model, delivering advanced generalized coding with the Loop Transformer architecture.GLM-5.3-FlashMultimodal Coding model, specializing in visual programming.3Choose the Calling MethodOur platform provides various development approaches; you can select the best fit for your project needs and tech stack.HTTP APIStandard RESTful API, compatible with all programming languages.Z.AI Python SDKOfficial Python SDK, featuring full type hints and async support.Z.AI Java SDKOfficial Java SDK, designed for high concurrency and availability.OpenAI Python SDKOpenAI SDK Compatibility, quickly migrating from OpenAI.API ReferenceComplete API documentation with parameter descriptions.4Make API CallAfter preparing your API Key and selecting a model, you can start making API calls. Here are examples using curl, Python SDK, and Java SDK:When using GLM Coding Plan, please follow the tutorial to configure your dedicated endpoint. 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." } ] }' 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); } } Get More API ReferenceAccess API Reference.Python SDKAccess Python SDK GithubJava SDKAccess Java SDK GithubWas this page helpful?YesNo