Anthropic-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/anthropic/v1/messages |
| Authentication request header | Provides the server with identity authentication/authorization credentials. | "x-api-key":"$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 | 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 parameter 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 |
| system | string | No | Definition System prompt, which can be used to assign a specific goal or role to the model. Constraints N/A Range N/A Default Value N/A | |
| messages | object[] | Yes | Definition List of messages in a dialog. Different models support different types of messages. | |
| messages.role | enum<string> | Yes | Definition Role that sends a message. Constraints N/A Range
Default Value N/A | |
| messages.content | string/array | Yes | Definition Message sent by the current role. Constraints N/A Range N/A Default Value N/A | |
| messages.content.type | enum<string> | Yes | Definition Message type. Constraints N/A Range
Default Value N/A | |
| Tool call result | messages.content.tool_use_id | string | Yes | Definition ID of the tool called by the model. Constraints This parameter is mandatory when messages.content.type is set to tool_result. Range N/A Default Value N/A |
| messages.content.content | string | No | Definition Content obtained after the tool is called. Constraints This parameter is mandatory when messages.content.type is set to tool_result. Range N/A Default Value N/A | |
| Deep thinking control | thinking | object | No | Definition Controls whether to enable the deep thinking mode for a model. Constraints For details about the supported models, see Thinking Control for Deep Thinking Models. |
| thinking.type | string | Yes | Definition Controls whether to enable the deep thinking mode for a model. Constraints For details about the supported models, see Thinking Control for Deep Thinking Models. Range
Default Value The default value varies depending on the model. For details, see Thinking Control for Deep Thinking Models. | |
| Model output behavior configuration | max_tokens | integer/null | No | Definition Maximum length of the content part of the model answer. After this parameter is set, the token length of the model output content does not exceed the value of max_tokens. Constraints N/A Range The default value varies depending on the model. For details, see the maximum output length and maximum CoT length on the model details page. Default Value 4K |
| temperature | number | 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, it influences randomness, but offers finer control by dynamically adjusting the pool of possible tokens.
Constraints It is recommended that you adjust either temperature or top_p. Range (0,1] Default Value
| |
| stream | boolean/null | No | Definition Determines whether the response is returned as a stream. Constraints N/A Range
Default Value false | |
| stop_sequences | string[] | No | Definition Stops the model from generating content when it encounters the string specified in the stop_sequences field. The stop token does not hit the token in the CoT, but only hits the part in the formal answer content. Constraints N/A 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 GLM-5.2:
DeepSeek-V4 series: high Default Value GLM-5.2: max DeepSeek-V4 series: high | |
| Tool calling | tools | array | 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.name | string | Yes | Definition Name of the function to be called. Constraints N/A Range N/A Default Value N/A | |
| tools.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.input_schema | 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 |
Response Parameters (Non-Streaming)
| Parameter | Type | Description | |
|---|---|---|---|
| id | string | Definition Unique identifier of this request. Range N/A | |
| type | enum<string> | Definition The type of the response message. Range message | |
| role | string | Definition The role of the author of this message. Range assistant: A message returned by the model. | |
| model | string | Definition Model parameter used in this request. Range Model parameter used in this request. | |
| content | array | Definition Content generated by the model. | |
| content.type | enum<string> | Definition Type of the generated content. Range
| |
| Deep thinking response (type: thinking) | content.thinking | string | Definition Deep thinking content of the model. Range N/A |
| content.signature | string | Definition Complete encrypted thinking content. Range N/A | |
| Formal reply (type: text) | content.text | string | Definition Formal reply content of the model. Range N/A |
| Tool input response (type: tool_use) | content.id | string | Definition ID of the tool called. Range N/A |
| content.name | string | Definition Name of the tool called. Range N/A | |
| content.input | object | Definition Structured input required to call the tool. Range N/A | |
| stop_reason | enum<string>/null | Definition Reason why the model stops generating tokens. Range
| |
| stop_sequence | string/null | Definition Indicates which custom stop_sequence was matched. The model returns null if none were matched. Range N/A | |
| usage | object | Definition Number of tokens consumed by this request. Range N/A | |
| usage.output_tokens | integer | Definition The number of tokens consumed by the model to generate the completion response. Range N/A | |
| usage.input_tokens | integer | Definition The number of tokens consumed by the model to process the input. Range N/A | |
| usage.cache_creation_input_tokens | integer | Definition Number of input tokens newly written to the cache in this request. Range N/A | |
| usage.cache_read_input_tokens | integer | Definition Number of input tokens served from the cache in this request. Range N/A | |
| usage.service_tier | string | Definition Service tier used for this request. Range default | |
| usage.total_tokens | integer | Definition The total number of tokens consumed by the model to process the input and generate the output. Range N/A | |
Response Parameters (Streaming)
| Parameter | Type | Description | |
|---|---|---|---|
| event | - | Definition ID of a returned message. Range
| |
| event: message_start | type | string | Definition Type of the chunk. Range message_start: the first chunk. |
| message | object[] | Definition Response message. | |
| message.id | string | Definition Unique ID of a request. Range N/A | |
| message.type | string | Definition The type of the response message. Range message | |
| message.role | string | Definition The role of the information. Range assistant | |
| message.model | string | Definition Model parameter called. Range Model parameter used in this request. | |
| message.stop_sequence | string/null | Definition Hit stop sequence. Range If no match is found in the cache, the output is null. | |
| message.usage | object | Definition Token usage statistics of the current request. | |
| message.usage.input_tokens | integer | Definition The number of tokens consumed by the model to process the input. Range N/A | |
| message.usage.output_tokens | integer | Definition The number of tokens consumed by the model to generate the completion response. Range N/A | |
| message.usage.cache_creation_input_tokens | integer | Definition Number of input tokens newly written to the cache in this request. Range N/A | |
| message.usage.cache_read_input_tokens | integer | Definition Number of input tokens served from the cache in this request. Range N/A | |
| message.usage.service_tier | string | Definition Service tier used for this request. Range default | |
| message.usage.total_tokens | integer | Definition The total number of tokens consumed by the model to process the input and generate the output. Range N/A | |
| message.content | array | Definition Content generated by the model. | |
| message.stop_reason | enum<string>/null | Definition Reason why the model stops outputting. Range If the model does not stop outputting, the value is null. | |
| event: content_block_start | type | string | Definition Type of the chunk. Range content_block_start: the start chunk of the formal reply. |
| index | integer | Definition Index of the current element. Range N/A | |
| content_block | object | Definition Details about the content generated by the model. | |
| content_block.type | string | Definition Type of the content generated by the model. Range text | |
| content_block.thinking | string | Definition Deep thinking content of the model. Range N/A | |
| content_block.text | string | Definition Formal reply content of the model. Range N/A | |
| content_block.id | string | Definition ID of the tool called. Range N/A | |
| content_block.name | string | Definition Name of the tool called. Range N/A | |
| content_block.input | object | Definition Structured input required to call the tool. Range N/A | |
| event: content_block_delta | type | string | Definition Type of the chunk. Range content_block_delta: contains the text of the formal reply, input_json for tool calls, and thinking for deep thinking. |
| index | integer | Definition Index of the current element. Range N/A | |
| delta | object | Definition Incremental output from the model. | |
| delta.type | string | Definition Incremental content type. Range text_delta | |
| delta.text | string | Definition Incremental text output from the model. Range N/A | |
| delta.partial_json | string | Definition JSON data required for tool calls during streaming output. | |
| event: content_block_stop | type | string | Definition Type of the chunk. Range content_block_stop: indicates that a segment of content has been fully output. |
| index | integer | Definition Index of the current element. Range N/A | |
| event: message_delta | type | string | Definition Type of the chunk. Range message_delta: contains stop_reason, stop_sequence, and usage information. |
| delta | object | Definition Incremental content of the message. | |
| delta.stop_sequence | string/null | Definition Hit stop sequence. Range If no match is found in the cache, the model returns null. | |
| delta.stop_reason | string | Definition Reason why the model stops outputting. Range
| |
| usage | enum<string>/null | Definition Token usage statistics of the current request. | |
| usage.output_tokens | integer | Definition The number of tokens consumed by the model to generate the completion response. Range N/A | |
| usage.input_tokens | integer | Definition The number of tokens consumed by the model to process the input. Range N/A | |
| usage.cache_creation_input_tokens | integer | Definition Number of input tokens newly written to the cache in this request. Range N/A | |
| usage.cache_read_input_tokens | integer | Definition Number of input tokens served from the cache in this request. Range N/A | |
| usage.total_tokens | integer | Definition The total number of tokens consumed by the model to process the input and generate the output. Range N/A | |
| event: message_stop | type | string | Definition Type of the chunk. Range message_stop: indicates that all messages have been returned. |
Thinking Control for Deep Thinking Models
| Model | thinking.type Default Value | thinking.type Options |
|---|---|---|
| GLM-5.2 GLM-5.1 GLM-5 | enabled |
|
| DeepSeek-V4-Flash DeepSeek-V4-Pro | enabled |
|
| DeepSeek-R1-0528 | enabled | enabled |
| DeepSeek-V3.2 | disabled |
|
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 |
|
Example 1: Streaming Output
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/anthropic/v1/messages" # 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/anthropic/v1/messages \
--header 'content-type: application/json' \
--header 'x-api-key: $MaaS_API_Key' \
--data '{
"model": "glm-5.2",
"stream": true,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello"
}
]
}' Example response:
event: message_start
data: {"type":"message_start","message":{"id":"22cadffad9724d5893e4f9ffed41a695","type":"message","role":"assistant","model":"glm-5.2","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"service_tier":"default"}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"delta":{"type":"text_delta","text":"Hello!"},"type":"content_block_delta","index":0}
event: content_block_delta
data: {"delta":{"type":"text_delta","text":"Is there anything"},"type":"content_block_delta","index":0}
event: content_block_delta
data: {"delta":{"type":"text_delta","text":"I can help"},"type":"content_block_delta","index":0}
event: content_block_delta
data: {"delta":{"type":"text_delta","text":"you with"},"type":"content_block_delta","index":0}
event: content_block_delta
data: {"delta":{"type":"text_delta","text":"?"},"type":"content_block_delta","index":0}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":9,"input_tokens":18,"total_tokens":27,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
event: message_stop
data: {"type":"message_stop"}
data: [DONE] Example 2: Tool Calling
Example request:
import requests
import json
if __name__ == '__main__':
url = "https://api-ap-southeast-1.modelarts-maas.com/anthropic/v1/messages" # 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",
"thinking": {
"type": "disabled"
},
"stream": False,
"system": "You are a helpful assistant. Keep replies concise.",
"messages": [
{
"role": "user",
"content": "What is the weather in Beijing today?"
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "call_664e61ca7977429db860d513",
"input": {
"city": "Beijing",
"unit": "celsius"
},
"name": "get_weather"
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "call_664e61ca7977429db860d513",
"content": "{\"city\": \"Beijing\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"Sunny\"}"
}
]
}
],
"tools": [
{
"name": "get_weather",
"description": "Get the current weather for a specified city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example, Beijing."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "Temperature unit"
}
},
"required": [
"city"
]
}
}
]
}
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/anthropic/v1/messages \
--header 'content-type: application/json' \
--header 'x-api-key: $MaaS_API_Key' \
--data '{
"model": "glm-5.2",
"thinking": {
"type": "disabled"
},
"stream": false,
"system": "You are a helpful assistant. Keep replies concise.",
"messages": [
{
"role": "user",
"content": "What is the weather in Beijing today?"
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "call_664e61ca7977429db860d513",
"input": {
"city": "Beijing",
"unit": "celsius"
},
"name": "get_weather"
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "call_664e61ca7977429db860d513",
"content": "{\"city\": \"Beijing\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"Sunny\"}"
}
]
}
],
"tools": [
{
"name": "get_weather",
"description": "Get the current weather for a specified city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, for example, Beijing."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "Temperature unit"
}
},
"required": [
"city"
]
}
}
]
}' {
"content": [
{
"text": "Today's weather in Beijing: **Sunny**, temperature **26°C**. The weather is great for travel! ☀️",
"type": "text"
}
],
"id": "1d3756ed5704491f980c2fd40054bfd7",
"model": "glm-5.2",
"role": "assistant",
"stop_reason": "end_turn",
"stop_sequence": null,
"type": "message",
"usage": {
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"input_tokens": 250,
"output_tokens": 23,
"service_tier": "default",
"total_tokens": 273
}
} 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