OpenAI-compatible APIs
Constraints
This function is only supported in CN-Hong Kong.
API Information
| Parameter | Description | Example Value |
|---|---|---|
| API URL | API URL for calling the model service. | https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions If the OpenAI SDK is used, set base_url to https://api-ap-southeast-1.modelarts-maas.com/openai/v1. |
| Authentication request header | Provides the server with identity authentication/authorization credentials. | "Authorization": "Bearer $MaaS_API_Key" |
Supported Models
You can log in to the MaaS console and enable the following models on the Model Inference > Real-Time Inference > Built-in Services page. On the model details page in the Model Square, you can view detailed information about the models.
| Model | Version | Supported Region | Value of model |
|---|---|---|---|
| GLM | GLM-5 | CN-Hong Kong | glm-5 |
| GLM-5.1 | CN-Hong Kong | glm-5.1 | |
| GLM-5.2 | CN-Hong Kong | glm-5.2 | |
| DeepSeek | DeepSeek-V4-Pro | CN-Hong Kong | deepseek-v4-pro |
| DeepSeek-V4-Flash | CN-Hong Kong | deepseek-v4-flash | |
| DeepSeek-V3.1 | CN-Hong Kong | deepseek-v3.1-terminus | |
| DeepSeek-V3 | CN-Hong Kong | DeepSeek-V3 | |
| DeepSeek-V3.2 | CN-Hong Kong | deepseek-v3.2 | |
| DeepSeek-R1-0528 | CN-Hong Kong | deepseek-r1-250528 |
Request Parameters
| Category | Parameter | Type | Mandatory | Description |
|---|---|---|---|---|
| General | model | string | Yes | Definition ID of the model used for generating content. For details about its value, see the model values in Supported models. Constraints N/A Range For details about its value, see the model values in Supported models. Default Value N/A |
| messages | object[] | Yes | Definition List of messages in a dialog. Different models support different types of messages. For details about the message structure, see the System message, User message, Assistant message, and Tool message. Constraints N/A | |
| System message | messages.role | string | Yes | Definition Role that sends a message. Constraints N/A Range system: A message sent by the system. Default Value N/A |
| messages.content | string/object[] | Yes | Definition Content of the message sent by the specified role. Constraints N/A | |
| messages.content.type | string | Yes | Definition Type of the message sent by the specified role. Constraints N/A Range text: Text message. Default Value N/A | |
| messages.content.text | string | Yes | Definition Content of a text message. Constraints N/A Range N/A Default Value N/A | |
| User message | messages.role | string | Yes | Definition Role that sends a message. Constraints N/A Range user: A message sent by a user. Default Value N/A |
| messages.content | string/object[] | Yes | Definition Content of the message sent by the specified role. Constraints N/A | |
| messages.content.type | string | Yes | Definition Type of the message sent by the specified role. Constraints N/A Range text: Text message. Default Value N/A | |
| messages.content.text | string | Yes | Definition Content of a text message. Constraints N/A Range N/A Default Value N/A | |
| Assistant message | messages.role | string | Yes | Definition Role that sends a message. Constraints N/A Range assistant: A message returned by the model. Default Value N/A |
| messages.content | string/object[] | Yes | Definition Content of the message sent by the specified role. Constraints N/A | |
| messages.tool_calls | array | No | Definition Tool call records from previous model responses in the dialog history. Constraints This parameter is mandatory when the value of messages.role is tool. Range N/A Default Value N/A | |
| messages.tool_calls.id | string | Yes | Definition ID of the tool called by the model. Constraints This parameter is mandatory when the value of messages.role is tool. Range N/A Default Value N/A | |
| messages.tool_calls.type | string | Yes | Definition Tool type. Constraints This parameter is mandatory when the value of messages.role is tool. Range function: Function calling. Default Value N/A | |
| messages.tool_calls.function | object | Yes | Definition Function information corresponding to the tool called by the model. Constraints N/A | |
| messages.tool_calls.function.arguments | string | Yes | Definition JSON parameters generated by the model for calling the function. Constraints This parameter is mandatory when the value of messages.role is tool. Range N/A Default Value N/A | |
| messages.tool_calls.function.name | string | Yes | Definition Name of the function to be called by the model. This is the user-defined function name. Constraints This parameter is mandatory when the value of messages.role is tool. Range N/A Default Value N/A | |
| Tool message | messages.role | string | Yes | Definition Role that sends a message. Constraints N/A Range tool: A message sent by a function call. Default Value N/A |
| messages.tool_call_id | string | Yes | Definition ID of the tool called by the model. Constraints This parameter is mandatory when the value of messages.role is tool. Range N/A Default Value N/A | |
| messages.content | string/object[] | Yes | Definition Content of the message sent by the specified role. Constraints N/A | |
| Deep thinking control | chat_template_kwargs | dict[str, Any] | No | Definition Additional keyword parameters passed to the template renderer, which can be used to control whether the model enables deep thinking mode. For details, see Thinking Control for Deep Thinking Models. Constraints N/A |
| Model output behavior configuration | max_completion_tokens | integer/null | No | |
| max_tokens | integer/null | No | ||
| continue_final_message | boolean | No | Definition Specifies whether to enable prefix continuation. Constraints To enable this function, set add_generation_prompt to false. Otherwise, an error is reported. Range
Default Value false | |
| add_generation_prompt | boolean | No | Definition Whether to add the prompt generated by the model to the chat template. This is a parameter used by the chat template in the tokenizer configuration of the model. Constraints This parameter and continue_final_message are mutually exclusive and cannot be both set to true. Range
Default Value true | |
| temperature | float/null | No | Definition Sampling temperature, used to control the randomness of the content generated by the model. A higher value (for example, greater than 1) will make the model output more random, divergent, and creative, while a lower value (for example, 0.1) will make the output more focused, deterministic, and conservative. Constraints It is recommended that you adjust either temperature or top_p. Range [0,2] Default Value DeepSeek-V3, DeepSeek-R1-0528, and DeepSeek-V4 apply special handling to inputs:
For other models, the input is used if provided; otherwise, it defaults to 0.6. | |
| top_p | float/null | No | Definition Nucleus sampling probability threshold, used to control the diversity of the content generated by the model. Similar to the temperature parameter but operates differently, allowing finer control over the vocabulary range of the model's output. When set close to 0, the model samples from only the most probable tokens, resulting in very conservative and highly deterministic outputs. When set close to 1, there is virtually no restriction on the vocabulary, leading to more random and divergent outputs. Constraints It is recommended that you adjust either temperature or top_p. Range (0,1] Default Value
| |
| top_k | integer | No | Definition Controls the model to select only from the top k most probable tokens during generation, influencing the randomness of the generated text. Higher values increase randomness, while lower values enhance determinism. Constraints N/A Range >=0 Default Value 20 | |
| frequency_penalty | number/null | No | Definition Frequency penalty coefficient, which is an important parameter used to control the diversity of model outputs. The probability of a token reappearing decreases proportionally based on its frequency in the generated text. The more frequently a token appears, the lower its likelihood of being used again. Constraints DeepSeek-V4 series: This parameter is not supported. Range [-2,2]
Default Value 0 | |
| presence_penalty | number/null | No | Definition Presence penalty coefficient, which is an important parameter used to control the diversity of model outputs. This reduces the probability that the model will repeatedly use previously mentioned tokens or topics, thereby encouraging it to generate new content. As long as a token has appeared at least once in the previously generated text, the model imposes a fixed penalty on it to reduce the probability of it being selected again. The model determines this penalty based solely on whether the token has appeared so far. A positive value increases the likelihood of the model generating novel content. Constraints DeepSeek-V4 series: This parameter is not supported. Range [-2,2]
Default Value 0 | |
| logit_bias | map/null | No | Definition Logit bias. It adjusts the probability of a specified token appearing in the model's output. The input is a JSON object mapping tokens to bias values ranging from [-100, 100]. Lower values decrease the likelihood, while higher values increase the chance of selection. Example: {Token ID: Bias value, Token ID: Bias value, ...}. A token ID is the numeric identifier of a specific token. Constraints This parameter is not supported by models with deep thinking capabilities. Range [-100, 100] -100: Completely prevents the token from being selected. 100: Ensures only this token can be selected. Actual effects may vary by model. Default Value null | |
| logprobs | boolean/null | No | Definition Log probability. Controls whether the model returns the log probabilities of the output tokens. Constraints N/A Range
Default Value false | |
| top_logprobs | integer/null | No | Definition Number of log probabilities to return. If the value is N, the model returns the log probabilities of N output tokens. Constraints This parameter is valid only when logprobs is set to true. Range An integer from 0 to 20 Default Value 0 | |
| stream | boolean/null | No | Definition Determines whether the response content is returned as a stream. Constraints N/A Range
Default Value false | |
| stream_options | object/null | No | Definition Options for streaming responses. Constraints This parameter can be set only when stream is true. | |
| stream_options.include_usage | boolean | No | Definition Indicates whether to output token usage information of the current request before the streaming response ends. Constraints Currently, this feature cannot be disabled. Range
Default Value true | |
| stop | string / string[] / null | No | Definition When the model encounters the string specified in the stop field, the generation stops and the string itself does not appear in the response. The stop token does not hit the token in the CoT, but only hits the part in the formal answer content. Constraints A maximum of four strings are supported. Range N/A Default Value N/A | |
| reasoning_effort | string | No | Definition Controls the reasoning intensity. Constraints This field takes effect only in thinking mode. Involved models: DeepSeek-V4 series and GLM-5.2 Range
Default Value high | |
| Tool call | tools | object[]/null | No | Definition List of tools available for the model to call, which may be included in the model's response. Configure this structure when you require the model to specify the tools to be called. Constraints N/A |
| tools.type | string | Yes | Definition Tool type. Constraints N/A Range function: Function calling. Default Value N/A | |
| tools.function | object | Yes | Definition Controls whether the model's response contains the tools to be called. Constraints N/A | |
| tools.function.name | string | Yes | Definition Name of the function to be called. Constraints N/A Range N/A Default Value N/A | |
| tools.function.description | string | No | Definition Description of the function to be called. The model will determine if the tool is needed for the current task based on this description. Constraints N/A Range N/A Default Value N/A | |
| tools.function.parameters | object | No | Definition Function request parameters, described in JSON format. Example: {
"type": "object",
"properties": {
"parameter name": {
"type": "string | number | boolean | object | array",
"description": "Parameter description"
}
},
"required": ["Mandatory parameters"]
} Parameters must conform to JSON specifications. Constraints N/A | |
| tool_choice | string/object | No | Definition Controls how the model calls tools. For details about the types supported by the model, see Tool Choices for Models. Constraints N/A Range
Default Value
| |
| tool_choice.type | string | Yes | Definition Type of the call, which should be function here. Constraints N/A Range function: Function calling. Default Value N/A | |
| tool_choice.function | object | Yes | Definition Information about the function to be called by the model. Constraints N/A | |
| tool_choice.function.name | string | Yes | Definition Name of the function to be called by the model. This function must be declared in the tools parameter list. Constraints N/A Range N/A Default Value N/A |
Response Parameters (Non-Streaming)
| Parameter | Type | Description |
|---|---|---|
| created | integer | Definition Unix timestamp (in seconds) indicating when the request was created. Range N/A |
| id | string | Definition Unique identifier of this request. Range N/A |
| model | string | Definition Model ID used in this request. Range Model ID used in this request. |
| object | string | Definition Model API type. Range chat.completion. |
| choices | object[] | Definition A list of model-generated completion choices for this request. |
| choices.finish_reason | string | Definition Reason why the model stopped generating: Range
|
| choices.index | integer | Definition Index of the current element in the choices list. Range N/A |
| choices.message | object | Definition Content generated by the model. |
| choices.message.role | string | Definition The role of the author of this message. Range
|
| choices.message.content | string | Definition Message content generated by the model. Range N/A |
| choices.message.reasoning_content | string/null | Definition CoT content generated by the model, only returned by deep thinking models. Range N/A |
| choices.message.tool_calls | object[]/null | Definition Tool call information generated by the model, returned only if tool calls were triggered. |
| choices.message.tool_calls.id | string | Definition ID of the called tool. Range N/A |
| choices.message.tool_calls.type | string | Definition Tool type. Range function: Function calling. |
| choices.message.tool_calls.function | object | Definition Function called by the model. |
| choices.message.tool_calls.function.name | string | Definition Name of the function called by the model. Range N/A |
| choices.message.tool_calls.function.arguments | string | Definition JSON input generated by the model for calling the function. Range N/A |
| choices.logprobs | object/null | Definition Log probability information for the content. |
| choices.logprobs.content | object[]/null | Definition Log probability information for each token in the generated message. |
| choices.logprobs.content.token | string | Definition Token in the generated message. Range N/A |
| choices.logprobs.content.logprob | float | Definition Log probability of the token in the generated message. Range N/A |
| choices.logprobs.content.bytes | integer[]/null | Definition List of integers representing the UTF-8 byte values of the token. This field is empty if the token does not have a valid UTF-8 representation. |
| choices.logprobs.content.top_logprobs | object[] | Definition List of the most likely candidate tokens at this position, along with their respective log probabilities. |
| choices.logprobs.content.top_logprobs.token | string | Definition Candidate token. Range N/A |
| choices.logprobs.content.top_logprobs.logprob | float | Definition Log probability of the candidate token. Range N/A |
| choices.logprobs.content.top_logprobs.bytes | integer[]/null | Definition List of integers representing the UTF-8 byte values of the candidate token. This field is empty if the token does not have a valid UTF-8 representation. |
| usage | object | Definition Token usage of this request. |
| usage.completion_tokens | integer | Definition The number of tokens consumed by the model to generate the completion response. Range N/A |
| usage.prompt_tokens | integer | Definition The number of tokens consumed by the model to process the input prompt. Range N/A |
| usage.total_tokens | integer | Definition The total number of tokens consumed by this request (including input and output tokens). Range N/A |
| usage.completion_tokens_details | object | Definition A detailed breakdown of the tokens consumed by the model's generated output. |
| usage.completion_tokens_details.reasoning_tokens | integer | Definition The number of tokens consumed by the model to generate the chain-of-thought output. Range N/A |
| usage.prompt_tokens_details | object | Definition A detailed breakdown of the input prompt tokens provided to the model.. |
| usage.prompt_tokens_details.cached_tokens | integer | Definition Token usage of the cached input content. Range N/A |
| service_tier | string | Definition Service tier used for this request. Range default |
Response Parameters (Streaming)
| Parameter | Type | Description |
|---|---|---|
| created | integer | Definition Unix timestamp (in seconds) indicating when the request was created. Range N/A |
| id | string | Definition Unique identifier of this request. Range N/A |
| model | string | Definition Name and version of the model used in this request. Range Model ID used in this request. |
| object | string | Definition Fixed as chat.completion.chunk. |
| choices | object[] | Definition A list of model-generated completion choices for this request. |
| choices.finish_reason | string | Definition Reason why the model stops generating tokens. Range: reason why the model stops generating tokens. Range:
|
| choices.index | integer | Definition Index of the current element in the choices list. Range N/A |
| choices.delta | object | Definition Incremental output from the model. |
| choices.delta.role | string | Definition The role of the author of this message. Range
|
| choices.delta.content | string | Definition Message content generated by the model. Range N/A |
| choices.delta.reasoning_content | string/null | Definition The model's CoT process. Range N/A |
| choices.delta.tool_calls | object[]/null | Definition Tool call information generated by the model. |
| choices.message.tool_calls.id | string | Definition ID of the called tool. Range N/A |
| choices.message.tool_calls.type | string | Definition Tool type. Currently, it only supports function. Range function: Function calling. |
| choices.message.tool_calls.function | object | Definition Function called by the model. |
| choices.message.tool_calls.function.name | string | Definition Name of the function called by the model. Range N/A |
| choices.message.tool_calls.function.arguments | string | Definition JSON parameters generated by the model for calling the function. The model does not always generate valid JSON, and may fabricate some parameters that are not defined in your function parameter specifications. Before calling a function, verify that these parameters are valid in your code. Range N/A |
| choices.logprobs | object/null | Definition Log probability information for the content. |
| choices.logprobs.content | object[]/null | Definition Log probability information for each token in the generated message. |
| choices.logprobs.content.token | string | Definition Token in the generated message. Range N/A |
| choices.logprobs.content.logprob | float | Definition Log probability of the token in the generated message. Range N/A |
| choices.logprobs.content.bytes | integer[]/null | Definition List of integers representing the UTF-8 byte values of the token. This field is empty if the token does not have a valid UTF-8 representation. |
| choices.logprobs.content.top_logprobs | object[] | Definition List of the most likely candidate tokens at this position, along with their respective log probabilities. |
| choices.logprobs.content.top_logprobs.token | string | Definition Candidate token. Range N/A |
| choices.logprobs.content.top_logprobs.logprob | float | Definition Log probability of the candidate token. Range N/A |
| choices.logprobs.content.top_logprobs.bytes | integer[]/null | Definition List of integers representing the UTF-8 byte values of the candidate token. This field is empty if the token does not have a valid UTF-8 representation. |
| usage | object | Definition Token usage of this request. |
| usage.completion_tokens | integer | Definition The number of tokens consumed by the model to generate the completion response. Range N/A |
| usage.prompt_tokens | integer | Definition The number of tokens consumed by the model to process the input prompt. Range N/A |
| usage.total_tokens | integer | Definition The total number of tokens consumed by this request (including input and output tokens). Range N/A |
| usage.completion_tokens_details | object | Definition A detailed breakdown of the tokens consumed by the model's generated output. |
| usage.completion_tokens_details.reasoning_tokens | integer | Definition The number of tokens consumed by the model to generate the chain-of-thought output. Range N/A |
| usage.prompt_tokens_details | object | Definition A detailed breakdown of the input prompt tokens provided to the model. |
| usage.prompt_tokens_details.cached_tokens | integer | Definition Token usage of the cached input content. Range N/A |
| service_tier | string | Definition Service tier used for this request. Range default |
| first_token_return_time | float | Definition Time when the model returned the first token of the chunk. Range N/A |
Thinking Control for Deep Thinking Models
| Model | Default Mode | Thinking Control |
|---|---|---|
| GLM-5.2 GLM-5.1 GLM-5 | Deep thinking | "chat_template_kwargs": {"thinking": True} |
| DeepSeek-V4-Flash DeepSeek-V4-Pro | Deep thinking | "chat_template_kwargs": {"thinking": True} |
| DeepSeek-R1-0528 | Deep thinking | Cannot be disabled. |
| DeepSeek-V3.1 | Non-thinking | "chat_template_kwargs": {"thinking": True} |
| DeepSeek-V3.2 | Non-thinking | "chat_template_kwargs": {"thinking": True} |
Tool Choices for Models
| Model | Supported Tool Choice |
|---|---|
| GLM-5.2 GLM-5.1 |
|
| GLM-5 |
|
| DeepSeek-V4-Flash DeepSeek-V4-Pro DeepSeek-R1-0528 DeepSeek-V3.2 |
|
| DeepSeek-V3 DeepSeek-V3.1 |
|
Example 1: Streaming response
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions" # API URL
api_key = "MAAS_API_KEY" # Replace MAAS_API_KEY with the obtained API key.
# Send request.
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
data = {
"model": "glm-5.2", # Model parameter. You can change the model parameter as required.
"stream":True,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello"}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
# Print result.
print(response.status_code)
print(response.text) Run the following commands in the Linux environment:
curl --request POST \
--url https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions \
--header 'authorization: Bearer $MAAS_API_KEY' \
--header 'content-type: application/json' \
--data '{
"model": "glm-5.2",
"stream": true,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello"
}
]
}' data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":"Hello!"}}],"service_tier":"default","first_token_return_time":1.7822666148251362E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":" How"}}],"service_tier":"default","first_token_return_time":1.7822666148726385E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":"can I help"}}],"service_tier":"default","first_token_return_time":1.7822666149221663E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":"you"}}],"service_tier":"default","first_token_return_time":1.7822666149709113E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":"?"}}],"service_tier":"default","first_token_return_time":1.782266615021146E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}],"service_tier":"default","first_token_return_time":1.782266615021146E9}
data: {"id":"8697e7dad55f4ad5ae65f006ba18f2fc","object":"chat.completion.chunk","created":1782266611,"model":"glm-5.2","choices":[],"usage":{"prompt_tokens":20,"total_tokens":134,"completion_tokens":114,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":105}},"service_tier":"default","first_token_return_time":1.7822666150211895E9}
data: [DONE] Example 2: Prefix Continuation
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions" # API URL
api_key = "MAAS_API_KEY" # Replace MAAS_API_KEY with the obtained API key.
# Send request.
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
data = {
"model": "glm-5.2",
"continue_final_message": True,
"add_generation_prompt": False,
"messages": [
{
"role": "user",
"content": "You are a calculator. Please calculate: 1 + 1."
},
{
"role": "assistant",
"content": "="
}
],
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
# Print result.
print(response.status_code)
print(response.text) Run the following commands in the Linux environment:
curl --request POST \
--url https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions \
--header 'authorization: Bearer $MAAS_API_KEY' \
--header 'content-type: application/json' \
--data '{
"model": "glm-5.2",
"continue_final_message": true,
"add_generation_prompt": false,
"messages": [
{
"role": "user",
"content": "You are a calculator. Please calculate: 1 + 1."
},
{
"role": "assistant",
"content": "="
}
],
"stream": false
}' {
"id": "784f6f4091a7430b993c561bc4f1d216",
"object": "chat.completion",
"created": 1782268057,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": " 2"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 21,
"total_tokens": 24,
"completion_tokens": 3,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"service_tier": "default"
} Example 3: Multi-Turn Conversation
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions" # API URL
api_key = "MAAS_API_KEY" # Replace MAAS_API_KEY with the obtained API key.
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/v2/chat/completions" # API URL
api_key = "MAAS_API_KEY" # Replace MAAS_API_KEY with the obtained API key.
# Send request.
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
data = {
"model": "glm-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Recommend a programming book for beginners."
},
{
"role": "assistant",
"content": "I recommend Python Crash Course: A Hands-On, Project-Based Introduction to Programming. It is perfect for beginners with no prior programming experience."
},
{
"role": "user",
"content": "I want to learn data analysis. Is this book suitable for that?"
}
],
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
# Print result.
print(response.status_code)
print(response.text) Run the following commands in the Linux environment:
curl --request POST \
--url https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions \
--header 'authorization: Bearer $MAAS_API_KEY' \
--header 'content-type: application/json' \
--data '{
"model": "glm-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Recommend a programming book for beginners."
},
{
"role": "assistant",
"content": "I recommend Python Crash Course: A Hands-On, Project-Based Introduction to Programming. It is perfect for beginners with no prior programming experience."
},
{
"role": "user",
"content": "I want to learn data analysis. Is this book suitable for that?"
}
],
"stream": false
}' {
"id": "814f0581080f422bb06ccff00dc3ea51",
"object": "chat.completion",
"created": 1782269006,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "That's a good choice. Python is the dominant language for data analysis, and the foundational chapters of this book will help you build a solid base. Once you finish it, you can move on to Python for Data Analysis to focus specifically on your data analysis skills."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 65,
"total_tokens": 103,
"completion_tokens": 38,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"service_tier": "default"
} Example 4: Tool Calling
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions" # API URL
api_key = "MAAS_API_KEY" # Replace MAAS_API_KEY with the obtained API key.
# Send request.
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
data = {
"model": "glm-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the weather in Beijing today?"
},
{
"role": "assistant",
"tool_calls": [
{
"id": "call_e8d8a81c1f3942868443360f",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Beijing\", \"unit\": \"celsius\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_e8d8a81c1f3942868443360f",
"content": "{\"city\": \"Beijing\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"Sunny\"}"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a specified city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example, Beijing."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "Temperature unit"
}
},
"required": [
"city"
]
}
}
}
],
"tool_choice": "auto",
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
# Print result.
print(response.status_code)
print(response.text) Run the following commands in the Linux environment:
curl --request POST \
--url https://api-ap-southeast-1.modelarts-maas.com/openai/v1/chat/completions \
--header 'authorization: Bearer $MAAS_API_KEY' \
--header 'content-type: application/json' \
--data '{
"model": "glm-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the weather in Beijing today?"
},
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_e8d8a81c1f3942868443360f",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Beijing\", \"unit\": \"celsius\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_e8d8a81c1f3942868443360f",
"content": "{\"city\": \"Beijing\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"Sunny\"}"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a specified city.",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example, Beijing."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "Temperature unit"
}
},
"required": [
"city"
]
}
}
}
],
"tool_choice": "auto",
"stream": false
}' {
"id": "d41eba20c8a545c69864003a3fcd5ae2",
"object": "chat.completion",
"created": 1782270016,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Here is the weather information for Beijing today: \n\n- ️ Weather Conditions: Sunny \n- ️ Temperature: 26°C \n\n It is sunny in Beijing today with a comfortable temperature of 26°C, making it a perfect day to go out! If you need to check the weather for any other city, feel free to let me know anytime~"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 246,
"total_tokens": 306,
"completion_tokens": 60,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"service_tier": "default"
} Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot