更新时间:2026-07-21 GMT+08:00
分享

OpenAI兼容接口

约束限制

该功能仅支持“西南-贵阳一”区域。

接口信息

名称

说明

取值

API地址

调用模型服务的API地址。

https://api.modelarts-maas.com/openai/v1/chat/completions

如果使用OpenAI SDK,base_url设置为https://api.modelarts-maas.com/openai/v1。

鉴权请求头

向服务器提供身份验证/授权凭证。

"Authorization":"Bearer $MaaS_API_Key"

支持模型

模型系列

模型名称

支持地域

model参数值

openPangu

openPangu-2.0-Flash

西南-贵阳一

openpangu-2.0-flash

GLM

GLM-5

西南-贵阳一

glm-5

GLM-5.1

西南-贵阳一

glm-5.1

GLM-5.2

西南-贵阳一

glm-5.2

Kimi

Kimi-K2.6

西南-贵阳一

kimi-k2.6

DeepSeek

DeepSeek-V4-Pro

西南-贵阳一

deepseek-v4-pro

DeepSeek-V4-Flash

西南-贵阳一

deepseek-v4-flash

DeepSeek-V3

西南-贵阳一

DeepSeek-V3

DeepSeek-R1-0528

西南-贵阳一

deepseek-r1-250528

DeepSeek-V3.1

西南-贵阳一

deepseek-v3.1-terminus

DeepSeek-V3.2

西南-贵阳一

deepseek-v3.2

Qwen3

Qwen3-235B-A22B

西南-贵阳一

qwen3-235b-a22b

Qwen3-32B

西南-贵阳一

qwen3-32b

Qwen3-30B-A3B

西南-贵阳一

qwen3-30b-a3b

您可以登录MaaS控制台,在“模型广场”页面的模型详情页面,查看模型的详细信息。

请求参数说明

参数类别

参数

参数类型

是否必填

说明

通用

model

string

参数解释:

用于生成内容的模型ID。取值请参考支持的模型中的model参数值

约束限制:

不涉及。

取值范围

取值请参考支持的模型中的model参数值

默认取值:

不涉及。

messages

object[]

参数解释:

对话组成的消息列表。不同模型支持不同类型的消息。消息结构请参考系统消息用户消息模型答复消息工具消息

约束限制:

不涉及。

系统消息

(System Message)

messages.role

string

参数解释:

发送消息的角色。

约束限制:

不涉及

取值范围

system:系统发送的消息

默认取值:

不涉及。

messages.content

string/object[]

参数解释:

角色发送的消息内容。

约束限制:

不涉及。

messages.content.type

string

参数解释:

角色发送的消息的类型。

约束限制:

不涉及。

取值范围

text:文本类型

默认值:

不涉及。

messages.content.text

string

参数解释:

文本消息的内容。

约束限制:

不涉及。

取值范围

不涉及。

默认值:

不涉及。

用户消息

(User Message)

messages.role

string

参数解释:

发送消息的角色。

约束限制:

不涉及。

取值范围

user:用户发送的消息

默认取值:

不涉及。

messages.content

string/object[]

参数解释:

角色发送的消息内容。

约束限制:

不涉及。

messages.content.type

string

参数解释:

角色发送的消息的类型。

约束限制:

不涉及。

取值范围

text:文本类型

默认值:

不涉及。

messages.content.text

string

参数解释:

文本消息的内容。

约束限制:

不涉及。

取值范围

不涉及。

默认值:

不涉及。

模型答复消息

(Assistant Message)

messages.role

string

参数解释:

发送消息的角色。

约束限制:

不涉及。

取值范围

assistant:模型回复的消息

默认取值:

不涉及。

messages.content

string/object[]

参数解释:

角色发送的消息内容。

约束限制:

不涉及。

messages.tool_calls

array

参数解释:

历史对话中,模型回复的工具调用信息。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

不涉及。

默认值:

不涉及。

messages.tool_calls.id

string

参数解释:

模型调用的工具的ID。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

不涉及。

默认值:

不涉及。

messages.tool_calls.type

string

参数解释:

工具类型。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

function:函数调用

默认值:

不涉及。

messages.tool_calls.function

object

参数解释:

模型调用工具对应的函数信息。

约束限制:

不涉及。

messages.tool_calls.function.arguments

string

参数解释:

模型生成的用于调用函数的JSON格式的参数。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

不涉及。

默认值:

不涉及。

messages.tool_calls.function.name

string

参数解释:

模型需要调用的函数名称。用户自定义的函数名称。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

不涉及。

默认取值:

不涉及。

工具消息

(Tool Message)

messages.role

string

参数解释:

发送消息的角色。

约束限制:

不涉及。

取值范围

tool:Function Call发送的消息。

默认取值:

不涉及。

messages.tool_call_id

string

参数解释:

模型调用的工具的ID。

约束限制:

当发送消息的角色是工具,也就是参数“messages.role”取值为“tool”时,该参数必传。

取值范围

不涉及。

默认值:

不涉及。

messages.content

string/object[]

参数解释:

角色发送的消息内容。

约束限制:

不涉及。

深度思考控制

chat_template_kwargs

dict[str, Any]

参数解释:

传递给模板渲染器的额外关键字参数,可用于控制模型是否开启深度思考模式。详情请参见深度思考模型思考控制开关支持情况

约束限制:

不涉及。

模型输出行为配置

max_completion_tokens

integer/null

参数解释:

控制模型输出的最大长度,包括两部分:模型回答(content部分)和模型思维链部分(reasoning_content)。

配置该参数后,模型输出的Token长度不会超过max_completion_tokens配置的值。

约束限制:

  • 不可与max_tokens字段同时设置,否则会直接报错。
  • 深度思考模型在关闭了思考模式的情况max_completions_tokens依然生效,只控制content部分的输出Token长度。

取值范围:

各个模型取值不同,详情请参见MaaS控制台模型详情页的最大输出长度最大思维链长度

默认取值

不涉及。

max_tokens

integer/null

参数解释:

模型回答最大长度,单位为Token。

约束限制:

  • 模型回答不包含思维链内容。

    模型回答=模型输出-模型思维链(如有)。

  • 输出Token的总长度还受模型的上下文长度限制。

取值范围:

各个模型取值不同,详情请参见MaaS控制台模型详情页的最大输出长度

默认取值

默认值:Kimi-K2.6为32K,其它模型为4K。

continue_final_message

boolean

参数解释:

模型是否开启前缀续写。

约束限制:

开启该功能时,需要将参数“add_generation_prompt”设置为false,否则会报错。

取值范围:

  • true:开启前缀续写
  • false:关闭前缀续写

默认取值:

false

add_generation_prompt

boolean

参数解释:

是否将模型生成的Prompt添加到聊天模板中。这是模型tokenizer配置中chat template使用的一个参数。

约束限制:

该参数与continue_final_message互斥,不可同时设置为true,否则会报错。

取值范围:

  • true:将模型生成的Prompt添加到聊天模板中。
  • false:不将模型生成的Prompt添加到聊天模板中

默认取值:

true

temperature

float/null

参数解释:

采样温度,用于控制模型生成内容的随机性。

较高的值(如大于1)会使模型输出更加随机、发散、创造性高,而较低的值(如 0.1)会使输出更加集中确定、保守。

约束限制:

建议仅调整temperature或top_p其中之一,不建议两者都修改。

取值范围:

[0,2]

默认取值:

DeepSeek-V3、DeepSeek-R1-0528和DeepSeek-V4系列会对输入值做特殊处理:

  • DeepSeek-V3:当temperature≤1时,乘以0.3;当temperature>1时,减去0.7;值为空时,默认为0.6。
  • DeepSeek-R1-0528:无论用户输入值多少均为0.6。
  • DeepSeek-V4系列:思考模式下,无论用户输入值多少均为1.0。

Kimi-K2.6会对输入值做特殊处理:思考模式下,无论用户输入值多少均为1.0;非思考模式下,无论用户输入值多少均为0.6。

openPangu-2.0-Flash模型默认值为1。

其它模型如果有输入值,以输入值为准;如果输入值为空,则默认为0.6。

top_p

float/null

参数解释:

核采样概率阈值,用于控制模型生成内容的多样性,和temperature参数类似,但原理不同,可以更精细地控制模型输出的词汇范围。

设置值接近0时,模型只从概率最高的极少数词中采样,输出非常保守、确定性强。设置值接近1时,则几乎不限制词库,输出更随机、更发散。

约束限制:

建议仅调整temperature或top_p其中之一,不建议两者都修改。

取值范围:

(0,1]

默认取值:

  • Kimi-K2.6:思考模式和非思考模式均为0.95,不支持修改。
  • DeepSeek-V4系列:思考模式下,无论用户输入值多少均为1.0。
  • 其它模型0.7。

top_k

integer

参数解释:

控制模型生成时每次只从概率最高的k个词里挑选,用来控制生成文本的随机性。取值越大,生成的随机性越高;取值越小,生成的确定性越高。

约束限制:

不涉及。

取值范围:

>=0

默认取值:

20。

frequency_penalty

number/null

参数解释:

频率惩罚系数,是一个用于控制模型输出多样性的重要参数。

根据词语已经出现的次数,按比例降低该词再次出现的概率。出现的次数越多,再次被使用的概率就越低。

约束限制:

DeepSeek-V4系列:不支持该参数。

取值范围:

[-2,2]

  • 0:不做任何惩罚。
  • 正值:增加惩罚,值越大,模型越倾向于引入新的词汇和话题,避免内容重复。
  • 负值:减少惩罚(实际上是奖励)。模型更倾向于重复使用已经出现过的词汇,这通常会导致文本极其啰嗦和重复(一般不推荐使用)。

默认取值

0

presence_penalty

number/null

参数解释:

存在惩罚系数,是一个用于控制模型输出多样性的重要参数。降低模型重复谈论已经出现过的话题或词汇的概率,从而鼓励模型去谈论“新事物”。

只要某个词在之前已经生成的文本中出现过至少一次,模型就会对该词施加一个固定的惩罚,降低它再次被选中的概率。模型会根据新Token截止目前是否已出现对其进行惩罚。如果值为正,会增加模型生成新内容的可能性。

约束限制:

DeepSeek-V4系列:不支持该参数。

取值范围:

[-2,2]

  • 0:不做任何惩罚
  • 正值:增加惩罚,值越大,模型越倾向于引入新的词汇和话题,避免内容重复。
  • 负值:减少惩罚(实际上是奖励)。模型更倾向于重复使用已经出现过的词汇,这通常会导致文本极其啰嗦和重复(一般不推荐使用)。

默认取值:

0

logit_bias

map/null

参数解释:

逻辑偏置。调整指定Token在模型输出内容中出现的概率。输入为JSON对象,该对象将Token映射到一个范围为[-100, 100]的相关偏置值 。

值越小则可能性越低,越高则会增加选择的可能性。

示例:{Token ID:偏置值,Token ID:偏置值,...} 。Token ID是指某个特定词的数字ID。

约束限制:

带深度思考能力模型不支持该字段。

取值范围:

偏置值取值范围为[-100, 100]。

-100:完全禁止选择该Token,

100:会导致仅可选择该Token。

该参数的实际效果可能因模型而异。

默认取值:

null

logprobs

boolean/null

参数解释:

对数概率。控制模型是否返回输出Token的对数概率。

约束限制:

不涉及。

取值范围:

  • true:开启返回对数概率的功能。
  • false:关闭返回对数概率的功能。

默认取值

false

top_logprobs

integer/null

参数解释:

对数概率个数。如果值为N,则控制模型返回N个输出Token的对数概率。

约束限制:

仅当参数logprobs值为true时该参数才生效。

取值范围:

[0, 20]之间的整数

默认取值:

0

stream

boolean/null

参数解释:

响应内容是否流式返回。

约束限制:

不涉及。

取值范围:

  • false:模型生成完所有内容后一次性返回结果。
  • true:逐块返回模型生成内容,最后以data: [DONE]结束消息。

默认取值:

false

stream_options

object/null

参数解释:

流式响应的选项。

约束限制:

当stream为true时,可设置stream_options字段。

stream_options.include_usage

boolean

参数解释:

模型流式输出时,是否在输出结束前输出本次请求的Token用量信息。

约束限制:

当前暂不支持关闭。

取值范围:

  • true:在data: [DONE]消息之前会返回一个额外的chunk。此chunk中, usage字段中输出整个请求的Token用量,choices字段为空数组。
  • false:不输出本次请求的Token用量信息。

默认取值:

true

stop

string / string[] / null

参数解释:

当模型遇到stop字段中所指定的字符串时将停止继续生成,这个字符本身也不会出现在响应中。停止Token不会命中思维链中的Token,仅会命中正式回答content中的部分。

约束限制:

最多支持4个字符串。

取值范围:

不涉及。

默认取值:

不涉及。

reasoning_effort

string

参数解释:

控制思考强度的参数。

约束限制:

思考模式下该字段才生效。

涉及的模型:DeepSeek-V4系列、GLM-5.2

取值范围:

  • high

默认取值:

high

工具调用

tools

object[]/null

参数解释:

待调用工具的列表,模型返回信息中可包含。当您需要让模型返回待调用工具时,需要配置该结构体。

约束限制:

不涉及。

tools.type

string

参数解释:

工具类型。

约束限制:

不涉及。

取值范围:

function:函数调用

默认取值:

不涉及。

tools.function

object

参数解释:

模型返回内容中包含待调用的工具。

约束限制:

不涉及。

tools.function.name

string

参数解释:

调用的函数的名称。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

tools.function.description

string

参数解释:

调用的函数的描述,模型会基于该描述判断当前任务是否需要使用该工具。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

tools.function.parameters

object

参数解释:

函数请求参数,以JSON格式描述。示例如下:

{
  "type": "object",
  "properties": {
    "参数名": {
      "type": "string | number | boolean | object | array",
      "description": "参数说明"
    }
  },
  "required": ["必填参数"]
}

parameters必须符合JSON规范。

约束限制:

不涉及。

tool_choice

string/object

参数解释:

控制模型调用工具的模式。对应模型支持的类型请参考工具调用模型支持情况

约束限制:

不涉及。

取值范围:

  • none :不调用任何工具。
  • auto :模型自行判断是否进行工具调用。
  • 指定函数调用(named):模型必须调用指定的函数,通过 tool_choice.type 和 tool_choice.function 字段指定必须调用的函数。

默认取值:

  • 当未提供待调用工具列表时默认为none。
  • 当有提供待调用工具列表时默认为auto。

tool_choice.type

string

参数解释:

指定模型需要调用的工具类型,此处应为function。

约束限制:

不涉及。

取值范围:

function:函数调用

默认取值:

不涉及。

tool_choice.function

object

参数解释:

指定模型需要调用的函数信息。

约束限制:

不涉及。

tool_choice.function.name

string

参数解释:

指定模型需要调用的函数名称,在待调用工具列表中声明函数定义。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

响应参数说明(非流式)

参数

参数类型

说明

created

integer

参数解释:

本次请求创建时间的Unix时间戳(秒)。

值范围:

不涉及。

id

string

参数解释:

本次请求的唯一标识。

取值范围:

不涉及。

model

string

参数解释:

本次请求使用的模型ID。

取值范围:

本次请求使用的模型ID。

object

string

参数解释:

模型API类型。

取值范围:

chat.completion。

choices

object[]

参数解释:

本次请求的模型输出内容。

choices.finish_reason

string

参数解释:

模型停止生成的原因:

取值范围:

  • stop:模型输出自然结束,或命中了请求参数stop中指定的字段。
  • length:模型输出触发max_tokens限制(思维链内容+回答内容的长度限制)。
  • tool_calls:模型触发了工具调用。

choices.index

integer

参数解释:

当前元素在choices列表的索引。

取值范围:

不涉及。

choices.message

object

参数解释:

模型输出的内容。

choices.message.role

string

参数解释:

内容输出的角色。

取值范围:

  • assistant:模型回复的消息
  • tool:Function Call发送的消息

choices.message.content

string

参数解释:

模型生成的消息内容。

取值范围:

不涉及。

choices.message.reasoning_content

string/null

参数解释:

模型生成的思维链内容,仅深度思考模型返回此字段。

取值范围:

不涉及。

choices.message.tool_calls

object[]/null

参数解释:

模型生成的工具调用信息,触发了工具调用才会返回该参数。

choices.message.tool_calls.id

string

参数解释:

调用的工具的ID。

取值范围:

不涉及。

choices.message.tool_calls.type

string

参数解释:

工具类型。

取值范围:

function:函数调用

choices.message.tool_calls.function

object

参数解释:

模型调用的函数。

choices.message.tool_calls.function.name

string

参数解释:

模型调用的函数的名称。

取值范围:

不涉及。

choices.message.tool_calls.function.arguments

string

参数解释:

模型生成的用于调用函数的JSON格式输入。

取值范围:

不涉及。

choices.logprobs

object/null

参数解释:

当前内容的对数概率信息。

choices.logprobs.content

object[]/null

参数解释:

模型返回的消息内容中每个Token的对数概率信息。

choices.logprobs.content.token

string

参数解释:

模型返回的消息内容中的Token。

取值范围:

不涉及。

choices.logprobs.content.logprob

float

参数解释:

模型返回的消息内容中的Token的对数概率。

取值范围:

不涉及。

choices.logprobs.content.bytes

integer[]/null

参数解释:

当前Token的UTF-8值,为一个整数列表。如果Token没有UTF-8值则为空。

choices.logprobs.content.top_logprobs

object[]

参数解释:

在当前Token位置上概率最高的候选Token及其对数概率的列表。

choices.logprobs.content.top_logprobs.token

string

参数解释:

候选Token。

取值范围:

不涉及。

choices.logprobs.content.top_logprobs.logprob

float

参数解释:

候选Token的对数概率。

取值范围:

不涉及。

choices.logprobs.content.top_logprobs.bytes

integer[]/null

参数解释:

候选Token的UTF-8值,为一个整数列表。如果Token没有UTF-8值则为空。

usage

object

参数解释:

本次请求的Token用量信息。

usage.completion_tokens

integer

参数解释:

模型输出内容消耗的Token数量。

取值范围:

不涉及。

usage.prompt_tokens

integer

参数解释:

模型处理输入内容消耗的Token数量。

取值范围:

不涉及。

usage.total_tokens

integer

参数解释:

本次请求消耗的总Token数量(输入+输出)。

取值范围:

不涉及。

usage.completion_tokens_details

object

参数解释:

模型输出内容消耗的Token详情。

usage.completion_tokens_details.reasoning_tokens

integer

参数解释:

输出思维链内容消耗的Token数。

取值范围:

不涉及。

usage.prompt_tokens_details

object

参数解释:

给模型输入的Token数量的详细信息。

usage.prompt_tokens_details.cached_tokens

integer

参数解释:

缓存输入内容的Token用量。

取值范围:

不涉及。

service_tier

string

参数解释:

本次请求使用的服务层级。

取值范围:

default。

响应参数说明(流式)

参数

参数类型

说明

created

integer

参数解释:

本次请求创建时间的Unix时间戳(秒)。

取值范围:

不涉及。

id

string

参数解释:

本次请求的唯一标识。

取值范围:

不涉及。

model

string

参数解释:

本次请求实际使用的模型ID名称和版本。

取值范围:

本次请求实际使用的模型ID

object

string

参数解释:

固定为chat.completion.chunk。

choices

object[]

参数解释:

本次请求的模型输出内容。

choices.finish_reason

string

参数解释:

模型停止生成Token的原因。

取值范围:模型停止生成Token的原因。取值范围:

  • stop:模型输出自然结束,或因命中请求参数stop中指定的字段而被截断。
  • length:模型输出因达到模型输出限制而被截断。
  • tool_calls:模型调用了工具。

choices.index

integer

参数解释:

当前元素在choices列表的索引。

取值范围:

不涉及。

choices.delta

object

参数解释:

模型输出的增量内容。

choices.delta.role

string

参数解释:

内容输出的角色。

取值范围:

  • system:系统发送的消息
  • user:用户发送的消息
  • assistant:模型回复的消息
  • tool:Function Call发送的消息

choices.delta.content

string

参数解释:

模型生成的消息内容。

取值范围:

不涉及。

choices.delta.reasoning_content

string/null

参数解释:

模型处理问题的思维链内容。

取值范围:

不涉及。

choices.delta.tool_calls

object[]/null

参数解释:

模型生成的工具调用信息。

choices.message.tool_calls.id

string

参数解释:

调用的工具的ID。

取值范围:

不涉及。

choices.message.tool_calls.type

string

参数解释:

工具类型,当前仅支持function。

取值范围:

function:函数调用

choices.message.tool_calls.function

object

参数解释:

模型调用的函数。

choices.message.tool_calls.function.name

string

参数解释:

模型调用的函数的名称。

取值范围:

不涉及。

choices.message.tool_calls.function.arguments

string

参数解释:

模型生成的用于调用函数的参数,格式为JSON。

模型并不总是生成有效的JSON,并且可能会虚构出一些您的函数参数规范中未定义的参数。在调用函数之前,请在您的代码中验证这些参数是否有效。

取值范围:

不涉及。

choices.logprobs

object/null

参数解释:

当前内容的对数概率信息。

choices.logprobs.content

object[]/null

参数解释:

模型返回的消息内容中每个Token的对数概率信息。

choices.logprobs.content.token

string

参数解释:

模型返回的消息内容中的Token。

取值范围:

不涉及。

choices.logprobs.content.logprob

float

参数解释:

模型返回的消息内容中的Token的对数概率。

取值范围:

不涉及。

choices.logprobs.content.bytes

integer[]/null

参数解释:

当前Token的UTF-8值,为一个整数列表。如果Token没有UTF-8值则为空。

choices.logprobs.content.top_logprobs

object[]

参数解释:

在当前Token位置上概率最高的候选Token及其对数概率的列表。

choices.logprobs.content.top_logprobs.token

string

参数解释:

候选Token。

取值范围:

不涉及。

choices.logprobs.content.top_logprobs.logprob

float

参数解释:

候选Token的对数概率。

取值范围:

不涉及。

choices.logprobs.content.top_logprobs.bytes

integer[]/null

参数解释:

候选Token的UTF-8值,为一个整数列表。如果Token没有UTF-8值则为空。

usage

object

参数解释:

本次请求的Token用量。

usage.completion_tokens

integer

参数解释:

模型输出内容花费所消耗的Token数量。

取值范围:

不涉及。

usage.prompt_tokens

integer

参数解释:

输入给模型处理输入的内容所消耗的Token数量。

取值范围:

不涉及。

usage.total_tokens

integer

参数解释:

本次请求消耗的总Token数量(输入+输出)。

取值范围:

不涉及。

usage.completion_tokens_details

object

参数解释:

模型输出内容消耗的Token详情。

usage.completion_tokens_details.reasoning_tokens

integer

参数解释:

输出思维链内容消耗的Token数。

取值范围:

不涉及。

usage.prompt_tokens_details

object

参数解释:

输入给模型的Token数量的细节。

usage.prompt_tokens_details.cached_tokens

integer

参数解释:

缓存输入内容的Token用量。

取值范围:

不涉及。

service_tier

string

参数解释:

本次请求使用的服务层级。

取值范围:

default。

first_token_return_time

float

参数解释:

该chunk首Token返回时间。

取值范围:

不涉及。

深度思考模型思考控制开关支持情况

模型名称

默认模式

思考控制开关

openPangu-2.0-Flash

深度思考

"chat_template_kwargs": {"thinking": True}

GLM-5.2

GLM-5.1

GLM-5

深度思考

"chat_template_kwargs": {"thinking": True}

Kimi-K2.6

深度思考

"chat_template_kwargs": {"thinking": True}

DeepSeek-V4-Flash

DeepSeek-V4-Pro

深度思考

"chat_template_kwargs": {"thinking": True}

DeepSeek-R1-0528

深度思考

不支持关闭。

DeepSeek-V3.1

非思考

"chat_template_kwargs": {"thinking": True}

DeepSeek-V3.2

非思考

"chat_template_kwargs": {"thinking": True}

Qwen3-235B-A22B

深度思考

"chat_template_kwargs": {"enable_thinking": True}

Qwen3-32B

Qwen3-30B-A3B

工具调用模型支持情况

模型名称

支持的tool choice

openPangu-2.0-Flash

  • none
  • auto

GLM-5.2

GLM-5.1

  • none
  • auto
  • 指定的函数

GLM-5

  • none
  • auto

Kimi-K2.6

  • none
  • auto

DeepSeek-V4-Flash

DeepSeek-V4-Pro

DeepSeek-R1-0528

DeepSeek-V3.2

  • none
  • auto
  • 指定的函数

DeepSeek-V3

DeepSeek-V3.1

  • auto
  • 指定的函数

Qwen3-235B-A22B

  • none
  • auto
  • 指定的函数

示例一:流式输出

请求示例如下:

import requests
import json
if __name__ == '__main__':
    url = "https://api.modelarts-maas.com/openai/v1/chat/completions"  # API地址
    api_key = "MAAS_API_KEY"  # 把MAAS_API_KEY替换成已获取的API Key

    # Send request.
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {api_key}'
    }
    data = {
        "model": "glm-5.2",  # model参数,您可按需更换模型参数
        "stream":True,
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "你好"}
        ]
    }
    response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
    # Print result.
    print(response.status_code)
    print(response.text)

Linux环境下执行如下命令:

curl --request POST \
  --url https://api.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": "你好"
    }
  ]
}'
响应示例:
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.7822666148251362E9}

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.7822666148726385E9}

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.7822666149221663E9}

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.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]

示例二:前缀续写

请求示例如下:

import requests
import json
if __name__ == '__main__':
    url = "https://api.modelarts-maas.com/openai/v1/chat/completions"  # API地址
    api_key = "MAAS_API_KEY"  # 把MAAS_API_KEY替换成已获取的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": "你是一个计算器,请计算: 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)

Linux环境下执行如下命令:

curl --request POST \
--url https://api.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": "你是一个计算器,请计算: 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"
}

示例三:多轮对话

请求示例如下:

import requests
import json
if __name__ == '__main__':
    url = "https://api.modelarts-maas.com/openai/v1/chat/completions"  # API地址
    api_key = "MAAS_API_KEY"  # 把MAAS_API_KEY替换成已获取的API Key

import requests
import json
if __name__ == '__main__':
    url = "https://api.modelarts-maas.com/v2/chat/completions"  # API地址
    api_key = "MAAS_API_KEY"  # 把MAAS_API_KEY替换成已获取的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": "帮我推荐一本适合入门的编程书。"
            },
            {
                "role": "assistant",
                "content": "推荐《Python编程:从入门到实践》,非常适合零基础新手。"
            },
            {
                "role": "user",
                "content": "我想学习数据分析,这本书合适吗?"
            }
        ],
        "stream": False
    }
    response = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
    # Print result.
    print(response.status_code)
    print(response.text)

Linux环境下执行如下命令:

curl --request POST \
  --url https://api.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": "帮我推荐一本适合入门的编程书。"
    },
    {
      "role": "assistant",
      "content": "推荐《Python编程:从入门到实践》,非常适合零基础新手。"
    },
    {
      "role": "user",
      "content": "我想学习数据分析,这本书合适吗?"
    }
  ],
  "stream": false
}'
响应示例:
{
  "id": "814f0581080f422bb06ccff00dc3ea51",
  "object": "chat.completion",
  "created": 1782269006,
  "model": "glm-5.2",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "合适。Python是数据分析的主流语言,这本书的Python基础部分能帮你打好底子。学完后可以再接着看《利用Python进行数据分析》来专门学习数据分析技能。"
      },
      "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"
}

示例四:工具调用

请求示例如下:

import requests
import json
if __name__ == '__main__':
    url = "https://api.modelarts-maas.com/openai/v1/chat/completions" # API地址
    api_key = "MAAS_API_KEY" # 把MAAS_API_KEY替换成已获取的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": "北京今天天气怎么样?"
            },
            {
                "role": "assistant",
                "tool_calls": [
                    {
                        "id": "call_e8d8a81c1f3942868443360f",
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "arguments": "{\"city\": \"北京\", \"unit\": \"celsius\"}"
                        }
                    }
                ]
            },
            {
                "role": "tool",
                "tool_call_id": "call_e8d8a81c1f3942868443360f",
                "content": "{\"city\": \"北京\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"晴\"}"
            }
        ],
        "tools": [
            {
                "type": "function",
                "function": {
                    "name": "get_weather",
                    "description": "查询指定城市的实时天气",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "city": {
                                "type": "string",
                                "description": "城市名称,例如:北京"
                            },
                            "unit": {
                                "type": "string",
                                "enum": [
                                    "celsius",
                                    "fahrenheit"
                                ],
                                "description": "温度单位"
                            }
                        },
                        "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)

Linux环境下执行如下命令:

curl --request POST \
  --url https://api.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": "北京今天天气怎么样?"
    },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_e8d8a81c1f3942868443360f",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\": \"北京\", \"unit\": \"celsius\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_e8d8a81c1f3942868443360f",
      "content": "{\"city\": \"北京\", \"temperature\": 26, \"unit\": \"celsius\", \"condition\": \"晴\"}"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "查询指定城市的实时天气",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string",
              "description": "城市名称,例如:北京"
            },
            "unit": {
              "type": "string",
              "enum": [
                "celsius",
                "fahrenheit"
              ],
              "description": "温度单位"
            }
          },
          "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": "北京今天的天气情况如下:\n\n- ️ **天气状况**:晴\n- ️ **温度**:26°C\n\n今天北京天气晴朗,气温26摄氏度,非常舒适,适合外出活动!如果您还需要了解其他城市的天气,随时告诉我哦~"
      },
      "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"
}

相关文档