{"openapi":"3.0.0","info":{"description":"Z.AI platform providing AI models, image generation, video generation, audio transcription, and agent capabilities through RESTful APIs.","version":[{"name":"v4","value":"v4"}]},"servers":[{"description":"Z.AI platform providing AI models, image generation, video generation, audio transcription, and agent capabilities through RESTful APIs.","url":"https://api.apirails.com/zai"}],"paths":{"/api/coding/paas/v4/chat/completions":{"post":{"tags":["Code Completion"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/llm/chat-completion","api_endpoint":"https://api.z.ai/api/coding/paas/v4/chat/completions"},"summary":"Code Completion","description":"Code Completion is a feature that allows you to generate code snippets based on a given prompt. It is a powerful tool for developers to quickly generate code snippets based on a given prompt.","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"do_sample":{"type":"boolean","description":"When do_sample is true, sampling strategy is enabled; when do_sample is false, sampling strategy parameters such as temperature and top_p will not take effect"},"max_tokens":{"type":"number","description":"The maximum number of tokens for model output, the GLM-4.7 GLM-4.6 series supports 128K maximum output, the GLM-4.5 series supports 96K maximum output"},"messages":{"type":"array","description":"The current conversation message list as the model's prompt input. Possible message types: system, user, assistant, tool. Messages use role/content format. Assistant messages can include tool_calls. Tool messages require tool_call_id","required":true,"items":{"type":"object","properties":{"role":{"type":"string","description":"Role of the message author","required":true,"enum":["system","user","assistant","tool"]},"content":{"type":"string","description":"Message content (text, or JSON string for tool results)","required":true},"tool_call_id":{"type":"string","description":"Tool call ID this message is responding to (required for role: tool)"},"tool_calls":{"type":"array","description":"Tool call messages generated by the model (only for role: assistant)"}}}},"model":{"type":"string","description":"The model code to be called. GLM-4.7 are the latest flagship model series, foundational models specifically designed for agent applications","required":true},"request_id":{"type":"string","description":"Passed by the user side, needs to be unique; used to distinguish each request. If not provided by the user side, the platform will generate one by default"},"response_format":{"type":"object","description":"Specifies the response format of the model. Defaults to text. When using JSON mode, request JSON output in the prompt","properties":{"type":{"type":"string","description":"Output format type","required":true,"enum":["text","json_object"]}}},"stop":{"type":"array","description":"Stop word list. Generation stops when the model encounters any specified string. Currently supports only one stop word","items":{"type":"string"}},"stream":{"type":"boolean","description":"This parameter should be set to false or omitted when using synchronous call. It indicates that the model returns all content at once after generating all content. If set to true, the model will return the generated content in chunks via standard Event Stream"},"temperature":{"type":"number","description":"Sampling temperature, controls the randomness of the output, must be a positive number within the range [0.0, 1.0]"},"thinking":{"type":"object","description":"Only supported by GLM-4.5 series and higher models. Controls whether the model enables chain of thought","properties":{"type":{"type":"string","description":"Whether to enable thinking","required":true,"enum":["enabled","disabled"]}}},"tool_choice":{"type":"string","description":"Controls how the model selects a tool"},"tool_stream":{"type":"boolean","description":"Whether to enable streaming response for Function Calls. Default value is false. Only supported by GLM-4.6"},"tools":{"type":"array","description":"A list of tools the model may call. Max 128 functions supported. Supports function, retrieval, and web_search tool types","items":{"type":"object","properties":{"type":{"type":"string","description":"Tool type","required":true,"enum":["function","retrieval","web_search"]},"function":{"type":"object","description":"Function definition (required when type is function)"}}}},"top_p":{"type":"number","description":"Another method of temperature sampling, value range is [0.01, 1.0]"},"user_id":{"type":"string","description":"Unique ID for the end user, 6–128 characters. Avoid using sensitive information"}}},"example":{"do_sample":true,"max_tokens":1024,"messages":[],"model":"glm-5.2","request_id":"","response_format":{},"stop":[],"stream":"","temperature":1,"thinking":{},"tool_choice":"auto","tool_stream":"","tools":[],"top_p":0.95,"user_id":""}}}}}},"/api/paas/v4/chat/completions":{"post":{"tags":["Chat"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/llm/chat-completion","api_endpoint":"https://api.z.ai/api/paas/v4/chat/completions"},"summary":"Create Chat Completion","description":"Create a chat completion model that generates AI replies for given conversation messages. It supports multimodal inputs (text, images, audio, video, file), offers configurable parameters (like temperature, max tokens, tool use), and supports both streaming and non-streaming output modes","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"do_sample":{"type":"boolean","description":"When do_sample is true, sampling strategy is enabled; when do_sample is false, sampling strategy parameters such as temperature and top_p will not take effect"},"max_tokens":{"type":"number","description":"The maximum number of tokens for model output, the GLM-4.7 GLM-4.6 series supports 128K maximum output, the GLM-4.5 series supports 96K maximum output"},"messages":{"type":"array","description":"The current conversation message list as the model's prompt input. Possible message types: system, user, assistant, tool. Messages use role/content format. Assistant messages can include tool_calls. Tool messages require tool_call_id","required":true,"items":{"type":"object","properties":{"role":{"type":"string","description":"Role of the message author","required":true,"enum":["system","user","assistant","tool"]},"content":{"type":"string","description":"Message content (text, or JSON string for tool results)","required":true},"tool_call_id":{"type":"string","description":"Tool call ID this message is responding to (required for role: tool)"},"tool_calls":{"type":"array","description":"Tool call messages generated by the model (only for role: assistant)"}}}},"model":{"type":"string","description":"The model code to be called. GLM-4.7 are the latest flagship model series, foundational models specifically designed for agent applications","required":true},"request_id":{"type":"string","description":"Passed by the user side, needs to be unique; used to distinguish each request. If not provided by the user side, the platform will generate one by default"},"response_format":{"type":"object","description":"Specifies the response format of the model. Defaults to text. When using JSON mode, request JSON output in the prompt","properties":{"type":{"type":"string","description":"Output format type","required":true,"enum":["text","json_object"]}}},"stop":{"type":"array","description":"Stop word list. Generation stops when the model encounters any specified string. Currently supports only one stop word","items":{"type":"string"}},"stream":{"type":"boolean","description":"This parameter should be set to false or omitted when using synchronous call. It indicates that the model returns all content at once after generating all content. If set to true, the model will return the generated content in chunks via standard Event Stream"},"temperature":{"type":"number","description":"Sampling temperature, controls the randomness of the output, must be a positive number within the range [0.0, 1.0]"},"thinking":{"type":"object","description":"Only supported by GLM-4.5 series and higher models. Controls whether the model enables chain of thought","properties":{"type":{"type":"string","description":"Whether to enable thinking","required":true,"enum":["enabled","disabled"]}}},"tool_choice":{"type":"string","description":"Controls how the model selects a tool"},"tool_stream":{"type":"boolean","description":"Whether to enable streaming response for Function Calls. Default value is false. Only supported by GLM-4.6"},"tools":{"type":"array","description":"A list of tools the model may call. Max 128 functions supported. Supports function, retrieval, and web_search tool types","items":{"type":"object","properties":{"type":{"type":"string","description":"Tool type","required":true,"enum":["function","retrieval","web_search"]},"function":{"type":"object","description":"Function definition (required when type is function)"}}}},"top_p":{"type":"number","description":"Another method of temperature sampling, value range is [0.01, 1.0]"},"user_id":{"type":"string","description":"Unique ID for the end user, 6–128 characters. Avoid using sensitive information"}}},"example":{"do_sample":true,"max_tokens":1024,"messages":[],"model":"glm-5.2","request_id":"","response_format":{},"stop":[],"stream":"","temperature":1,"thinking":{},"tool_choice":"auto","tool_stream":"","tools":[],"top_p":0.95,"user_id":""}}}}}},"/api/paas/v4/generate/image":{"post":{"tags":["Image"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/image/generate-image","api_endpoint":"https://api.z.ai/api/paas/v4/generate/image"},"summary":"Generate Image","description":"Generate images based on text prompts","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"model":{"type":"string","description":"The model code to be called for image generation","required":true},"n":{"type":"number","description":"Number of images to generate"},"prompt":{"type":"string","description":"Text prompt describing the image to generate","required":true},"size":{"type":"string","description":"The size of the generated image. Other sizes: 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440"}}},"example":{"model":"cogview-4-250304","n":1,"prompt":"A beautiful landscape with a river and mountains","size":"1024x1024"}}}}}},"/api/paas/v4/videos/generations":{"post":{"tags":["Video"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/video/generate-video","api_endpoint":"https://api.z.ai/api/paas/v4/videos/generations"},"summary":"Generate Video","description":"Generate video asynchronously based on text prompts","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"model":{"type":"string","description":"The model code to be called for video generation","required":true},"prompt":{"type":"string","description":"Text prompt describing the video to generate","required":true}}},"example":{"model":"","prompt":""}}}}}},"/api/paas/v4/async-result/{id}":{"get":{"tags":["Video"],"parameters":[{"name":"id","in":"path","description":"The ID returned from the video generation request","required":true,"schema":{"type":"string","example":""}}],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/video/get-video-status","api_endpoint":"https://api.z.ai/api/paas/v4/async-result/{id}"},"summary":"Retrieve Video Result Using ID","description":"Retrieve the status and result of an asynchronous video generation task","security":[{"bearerAuth":[]}]}},"/api/paas/v4/audio/transcriptions":{"post":{"tags":["Audio"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/audio/audio-transcriptions","api_endpoint":"https://api.z.ai/api/paas/v4/audio/transcriptions"},"summary":"Audio Transcriptions","description":"Transcribes audio into the input language","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":false,"content":{"multipart/form-data":{"schema":{"type":"object","required":[],"properties":{"file":{"type":"string","format":"binary","description":"The audio file to transcribe","required":true},"language":{"type":"string","description":"The language of the input audio"},"model":{"type":"string","description":"The model code to be called for audio transcription","required":true},"prompt":{"type":"string","description":"Optional text to guide the model's style or continue a previous audio segment"},"response_format":{"type":"string","description":"The format of the transcript output"},"temperature":{"type":"number","description":"The sampling temperature, between 0 and 1"}}},"example":{"file":"(binary)","language":"","model":"","prompt":"","response_format":"json|text|srt|verbose_json|vtt","temperature":""}}}}}},"/api/paas/v4/tokenizer":{"post":{"tags":["Tool"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/tools/tokenizer","api_endpoint":"https://api.z.ai/paas/v4/tokenizer"},"summary":"Tokenizer","description":"Tokenize text input using the specified model. This endpoint converts text strings into tokens according to the model's tokenization scheme, which is useful for understanding token counts, managing input length, and analyzing text structure","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"input":{"type":"string","description":"The text string to be tokenized. This is the input text that will be converted into tokens according to the specified model's tokenization scheme","required":true},"model":{"type":"string","description":"The model code to be used for tokenization. This should match one of the available models that support tokenization","required":true}}},"example":{"input":"","model":"glm-5.2"}}}}}},"/api/paas/v4/web_search":{"post":{"tags":["Tool"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/tools/web-search","api_endpoint":"https://api.z.ai/paas/v4/web_search"},"summary":"Web Search","description":"Perform web search and return relevant results. This endpoint allows you to search the web for information, articles, and resources based on a query string. The results include relevant URLs, titles, snippets, and metadata from web sources","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"max_results":{"type":"number","description":"Maximum number of search results to return. This parameter limits the number of search results that will be included in the response. If not specified, a default number of results will be returned"},"query":{"type":"string","description":"The search query string. This is the text that will be used to search the web for relevant information, articles, and resources","required":true}}},"example":{"max_results":10,"query":"latest AI developments|Python programming tutorials|machine learning best practices"}}}}}},"/api/paas/v4/reader":{"post":{"tags":["Tool"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/tools/web-reader","api_endpoint":"https://api.z.ai/paas/v4/reader"},"summary":"Web Reader","description":"Read and extract content from a webpage. This endpoint fetches a webpage from the provided URL and extracts its text content, making it available for analysis, summarization, or use in other AI operations. The extracted content includes the main text from the page while filtering out navigation, ads, and other non-content elements","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"url":{"type":"string","description":"The URL of the webpage to read and extract content from. This should be a valid HTTP or HTTPS URL pointing to a web page that you want to analyze or extract text content from","required":true}}},"example":{"url":"https://example.com/article|https://docs.example.com/page"}}}}}},"/api/v1/agents":{"post":{"tags":["Agent"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/agents/agent","api_endpoint":"https://api.z.ai/api/v1/agents"},"summary":"Agent Chat","description":"Chat with an AI agent","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"agent_id":{"type":"string","description":"The agent ID to use for the chat"},"messages":{"type":"array","description":"The conversation messages for the agent","required":true,"items":{"type":"object","properties":{"role":{"type":"string","description":"Role of the message author","required":true,"enum":["user","assistant","system"]},"content":{"type":"string","description":"Message content","required":true}}}},"model":{"type":"string","description":"The model code to be called for agent chat","required":true}}},"example":{"agent_id":"","messages":[],"model":""}}}}}},"/api/v1/agents/async-result":{"post":{"tags":["Agent"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/agents/get-async-result","api_endpoint":"https://api.z.ai/api/v1/agents/async-result"},"summary":"Retrieve Agent Result","description":"Retrieve the result of an asynchronous agent task","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"task_id":{"type":"string","description":"The task ID returned from an asynchronous agent request","required":true}}},"example":{"task_id":""}}}}}},"/api/v1/agents/conversation":{"post":{"tags":["Agent"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/agents/agent-conversation","api_endpoint":"https://api.z.ai/api/v1/agents/conversation"},"summary":"Conversation History","description":"Retrieve conversation history for an agent","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":true,"content":{"application/json":{"schema":{"type":"object","required":[],"properties":{"conversation_id":{"type":"string","description":"The conversation ID to retrieve history for","required":true},"limit":{"type":"number","description":"Maximum number of messages to retrieve"}}},"example":{"conversation_id":"","limit":50}}}}}},"/api/paas/v4/files":{"post":{"tags":["Agent"],"parameters":[],"responses":{"401":{"description":"Bearer token required (Authorization header)","content":{"application/json":{}}}},"externalDocs":{"api_ref":"https://docs.z.ai/api-reference/agents/file-upload","api_endpoint":"https://api.z.ai/api/paas/v4/files"},"summary":"File Upload","description":"API for uploading auxiliary files (such as glossaries, terminology lists) to support the translation service. It allows users to upload reference materials that can enhance translation accuracy and consistency.","security":[{"bearerAuth":[]}],"requestBody":{"description":"","required":false,"content":{"multipart/form-data":{"schema":{"type":"object","required":[],"properties":{"file":{"type":"string","format":"binary","description":"The file to upload. Limit to 100MB. Allowed formats: pdf, doc, xlsx, ppt, txt, jpg, png.","required":true},"purpose":{"type":"string","description":"The purpose of the file upload"}}},"example":{"file":"(binary)","purpose":"agent"}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"security":[{"bearerAuth":[]}]}