MaaS Standard API V2
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/v2/chat/completions |
| 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 | Name | 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 Model ID 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.reasoning_content | string | No | Definition Chain-of-thought (CoT) content in the model response. Constraints N/A Range N/A Default Value N/A | |
| messages.tool_calls | array | No | Definition Tool call records from previous model responses in the dialog history. Constraints N/A | |
| messages.tool_calls.id | string | Yes | Definition ID of the tool called by the model. Constraints This parameter is mandatory when the role sending the message is a tool, meaning 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 N/A 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 N/A 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. User-defined function name. Constraints N/A Range N/A Default Value N/A | |
| messages.prefix | boolean | No | Definition Controls whether to enable continuation mode. In this mode, the user provides a message starting with assistant, and the model completes the rest based on that beginning and the input instruction. Constraints To use this feature, ensure that the last message in the messages list has the role set to assistant and the prefix parameter set to tTrue. Example: messages = [ {"role": "user", "content": "Write a snippet of Python code"}, {"role": "assistant", "content": "```python\n", "prefix": tTrue} ] Range
Default Value Default value: false | |
| 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 role sending the message is a tool, meaning when the value of messages.role is tool. Range N/A Default Value N/A | |
| messages.content | string/object[] | Yes | Definition Message sent by the current role. Default Value N/A | |
| Deep thinking control | thinking | object | No | Definition Controls whether to enable or disable the deep thinking mode for a model. Constraints N/A |
| thinking.type | string | Yes | Definition Enables or disables deep thinking mode. Constraints N/A Range
Default Value Default value: The default value varies depending on the model. For details, see Thinking Control for Deep Thinking Models. | |
| Model output behavior configuration | max_completion_tokens | integer/null | No | Definition Maximum length of the model output, including the model answer (content) and CoT (reasoning_content). After this parameter is set, the token length of the model output does not exceed the value of max_completion_tokens. Constraints
Range The value varies depending on the model. For details, see the maximum output length and maximum CoT length on the model details page of the MaaS console. Default Value N/A |
| max_tokens | integer/null | No | Definition Maximum length of a model response, in tokens. Constraints
Range The value varies depending on the model. For details, see the maximum output length on the model details page of the MaaS console. Default Value 4K | |
| 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 N/A | |
| 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 | |
| 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 | |
| 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 true: An additional chunk is returned before data: [DONE]. In this chunk, the usage field displays the token usage of the entire request, and the choices field is an empty array. 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": "parameter type",
"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 tool that the model needs to call. For this parameter, the value must be function. 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 Fixed as chat.completion. |
| choices | object[] | Definition Model output content of 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 output by the model. |
| choices.message.role | string | Definition Role of the output content. 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 Tool type. Currently, only function is supported. |
| 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 format 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 information of this request. |
| usage.completion_tokens | integer | Definition Number of tokens consumed by the model's output content. Range N/A |
| usage.prompt_tokens | integer | Definition Number of tokens consumed by the model to process the input. Range N/A Number of tokens input to the model for processing. |
| usage.total_tokens | integer | Definition Total number of tokens consumed by this request (input + output). Range N/A |
| usage.completion_tokens_details | object | Definition Details of tokens consumed by the model's output content. |
| usage.completion_tokens_details.reasoning_tokens | integer | Definition Number of tokens consumed by the output CoT content. Range N/A |
| usage.prompt_tokens_details | object | Definition Details about the number of input tokens processed by 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 Model ID used in this request. Range Model ID used in this request. |
| object | string | Definition Fixed as chat.completion.chunk. |
| choices | object[] | Definition Model output content of this request. |
| choices.finish_reason | string | Definition 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 Role of the output content. 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. 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 format 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 Number of tokens consumed by the model's output content. Range N/A |
| usage.prompt_tokens | integer | Definition Number of tokens consumed by the model to process the input. Range N/A |
| usage.total_tokens | integer | Definition Total number of tokens consumed by this request (input + output). Range N/A |
| usage.completion_tokens_details | object | Definition Details of tokens consumed by the model's output content. |
| usage.completion_tokens_details.reasoning_tokens | integer | Definition Number of tokens consumed by the output CoT content. Range N/A |
| usage.prompt_tokens_details | object | Definition Details of the number of tokens input 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 | thinking.type Default Value | thinking.type Options |
|---|---|---|
| DeepSeek-V4-Flash DeepSeek-V4-Pro | enabled |
|
| DeepSeek-R1-0528 | enabled | enabled |
| DeepSeek-V3.1 | disabled |
|
| DeepSeek-V3.2 | disabled |
|
| GLM-5 | enabled |
|
| GLM-5.1 | enabled |
|
| GLM-5.2 | enabled |
|
Tool Choices for Models
| Model | Supported Tool Choice |
|---|---|
| GLM-5.1 GLM-5.2 |
|
| GLM-5 |
|
| DeepSeek-V4-Flash DeepSeek-V4-Pro DeepSeek-V3.2 DeepSeek-R1-0528 |
|
| 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/v2/chat/completions" # API address
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": "Introduce yourself."}
]
}
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/v2/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":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"}}],"service_tier":"default","first_token_return_time":1782271081.6883674}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"What"}}],"service_tier":"default","first_token_return_time":1782271081.6885977}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"What can I do"}}],"service_tier":"default","first_token_return_time":1782271081.8549478}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"for you"}}],"service_tier":"default","first_token_return_time":1782271081.9053752}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"?"}}],"service_tier":"default","first_token_return_time":1782271081.9563594}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}],"service_tier":"default","first_token_return_time":1782271081.9563594}
data: {"id":"346ebea908644dffac013c1a44e3ba8e","object":"chat.completion.chunk","created":1782271081,"model":"glm-5.2","choices":[],"usage":{"prompt_tokens":14,"total_tokens":23,"completion_tokens":9,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":0}},"service_tier":"default","first_token_return_time":1782271081.9564166}
data: [DONE] Example 2: Prefix Continuation
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/v2/chat/completions" # API address
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":False,
"messages": [
{"role": "user", "content": "You are a calculator. Please calculate: 1 + 1"},
{
"role": "assistant",
"content": "=",
"prefix": True
}
]
}
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/v2/chat/completions \
--header 'authorization: Bearer $MAAS_API_KEY' \
--header 'content-type: application/json' \
--data '{
"model": "glm-5.2",
"stream": false,
"messages": [
{
"role": "user",
"content": "You are a calculator. Please calculate: 1 + 1"
},
{
"role": "assistant",
"content": "=",
"prefix": true
}
]
}' {
"id": "2d7f837e0a5f4196b6ff4480301021f5",
"object": "chat.completion",
"created": 1782271333,
"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/v2/chat/completions" # API address
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":False,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant. Keep your responses concise and avoid markdown formatting."
},
{
"role": "user",
"content": "Recommend a programming book for beginners."
},
{
"role": "assistant",
"content": "I recommend 'Python Crash Course' by Eric Matthes. 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?"
}
]
}
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/v2/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. Keep your responses concise and avoid markdown formatting."
},
{
"role": "user",
"content": "Recommend a programming book for beginners."
},
{
"role": "assistant",
"content": "I recommend 'Python Crash Course' by Eric Matthes. 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": "4b1697596b304f9aac8256995c7b00e4",
"object": "chat.completion",
"created": 1782270913,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "The book is suitable. However, for a focus on data analysis, 'Python for Data Analysis' by Wes McKinney is highly recommended. It is a classic introductory text in this field."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 70,
"total_tokens": 98,
"completion_tokens": 28,
"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/v2/chat/completions" # API address
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": False,
"messages": [{
"role": "system",
"content": "You are a helpful assistant."
}, {
"role": "user",
"content": "What is the weather in Beijing today?"
}, {
"role": "assistant",
"reasoning_content": "The user is asking about the weather in Beijing today.",
"content": "",
"tool_calls": [{
"id": "call_df646371a477403597ad63c4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Beijing\", \"unit\": \"celsius\"}"
}
}
]
}, {
"role": "tool",
"tool_call_id": "call_df646371a477403597ad63c4",
"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"
}
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/v2/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",
"reasoning_content": "The user is asking about the weather in Beijing today.",
"content": "",
"tool_calls": [
{
"id": "call_df646371a477403597ad63c4",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Beijing\", \"unit\": \"celsius\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_df646371a477403597ad63c4",
"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": "f47fb7165d5147f6bc9365893ba9b935",
"object": "chat.completion",
"created": 1782270476,
"model": "glm-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "The function returned the weather data for Beijing.",
"content": "The weather forecast for Beijing today is as follows:\n\n- ️ **Weather**: Sunny\n- ️ **Temperature**: 26°C\n\nToday is sunny in Beijing with a temperature of 26°C, which is ideal for outdoor activities. Please remember to use sun protection. "
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 263,
"total_tokens": 327,
"completion_tokens": 64,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 10
}
},
"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