Chat
Chat completions
针对特定模型只支持
Anthropic、CodeX协议。
请求说明
- 基本信息
标准模型请求地址:https://api.tiangangaitp.com/v1/chat/completions
TokenPlan 专用请求地址:https://token-plan.tiangangaitp.com/v1/chat/completions
注:针对claude模型,仅支持Anthropic协议
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| messages | array(message) | 是 | 聊天上下文信息。支持Qwen VL系列模型。 纯文本示例:messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Knock knock."},{"role": "assistant", "content": "Who's there?"},{"role": "user", "content": "Orange."}] 多模态示例:{"messages":[{"role":"user","content":[{"type":"text","text":"describe the image in 100 words or less"},{"type":"image_url","image_url":{"url":"xxx","detail":"high"}}]}]}} |
| model | string | 是 | 模型 |
| tools | array | 否 | 工具列表,只支持function |
| stream | bool | 否 | 是否以流式接口的形式返回数据,默认false |
| max_tokens | integer | 否 | 模型回复最大长度(单位 token) |
| temperature | number | 否 | 较高的数值会使输出更加随机,而较低的数值会使其更加集中。默认值1.0,取值范围[0,2.0]。 |
| top_p | number | 否 | 影响输出文本的多样性,取值越大,生成文本的多样性越强。默认值1.0。 |
| stop | array(string) | 否 | 停止生成更多Tokens的最多4个字符串。 |
| presence_penalty | number | 否 | 通过对已生成的token增加惩罚,减少重复生成的现象。默认值0,取值范围:[-2.0, 2.0]。 |
| frequency_penalty | number | 否 | 根据新词在当前文本中的频率进行惩罚,降低模型逐字重复同一行的可能性。 默认值0,取值范围:[-2.0, 2.0]。 |
| logprobs | boolean | 否 | 默认值false。是否返回输出 tokens 的对数概率。 |
| top_logprobs | integer | 否 | 默认值0,取值范围为 [0, 20]。指定每个输出 token 位置最有可能返回的 token 数量,每个 token 都有关联的对数概率。仅当 logprobs为true 时可以设置 top_logprobs 参数。 |
| response_format | object | 否 | 指定模型必须输出的格式的对象。 默认值: { "type": "text" } 设置为 { "type": "json_object" } 可启用 JSON 模式,这保证模型生成的消息是有效的 JSON。 重要:使用 JSON 模式时,您还必须通过系统或用户消息提示模型自行生成JSON。 |
| chat_template_kwargs.enable_thinking | bool | 否 | 是否开启思考模式。 |
| thinking.type | string | 否 | 思考模式,此为兼容接口,效果同chat_template_kwargs.enable_thinking,可填"enabled","disabled",仅支持GLM-4.5系列模型 |
| enable_thinking | bool | 否 | 思考模式,此为兼容接口,效果同chat_template_kwargs.enable_thinking |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | 流式:text/event-stream非流式:application/json |
- 响应体参数
a.非流式
| 名称 | 类型 | 描述 |
|---|---|---|
| object | string | 回包类型 chat.completion.chunk:多轮对话返回 |
| created | int | 时间戳 |
| model | string | 模型 示例值:Qwen/Qwen2.5-72B-Instruct |
| choices | array | |
| choices[0].index | int | 索引 |
| choices[0].finish_reason | string | 结束原因 正常结束:stop,token超长截断结束:length |
| choices[0].message | object | 模型回答 |
| choices[0].message.tool_calls | array | 工具列表 |
| choices[0].message.tool_calls[0].function | object | 函数调用信息 |
| choices[0].refs | array | 引用列表,调用自定义模型且模型输出包含文档引用时存在。在非流式调用中,会在最终结果内输出此次回答包含的所有引用来源信息。 |
| choices[0].refs[0].index | int | 引用来源出现顺序 |
| choices[0].refs[0].title | string | 引用数据标题 |
| choices[0].refs[0].content | string | 引用数据内容 |
| choices[0].refs[0].type | string | 引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索 |
| choices[0].refs[0].url | string | 引用数据url,其中,file和qa数据url访问需配置apikey,web数据url访问无需配置apikey |
b.流式
| 名称 | 类型 | 描述 |
|---|---|---|
| object | string | 回包类型 chat.completion.chunk:多轮对话返回 |
| created | int | 时间戳 |
| model | string | 模型 示例值:Qwen/Qwen2.5-72B-Instruct |
| choices | array | |
| choices[0].index | int | 索引 |
| choices[0].finish_reason | string | 结束原因 正常结束:stop,token超长截断结束:length |
| choices[0].delta | object | 模型回答 |
| choices[0].refs | array | 引用列表,调用自定义模型且模型输出包含文档引用时存在。在流式响应过程中,会实时于存在引用的位置输出引用来源信息,并在finish_reason不为空时输出此次回答包含的所有引用来源信息。 |
| choices[0].refs[0].index | int | 引用来源出现顺序 |
| choices[0].refs[0].title | string | 引用数据标题 |
| choices[0].refs[0].content | string | 引用数据内容 |
| choices[0].refs[0].type | string | 引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索 |
| choices[0].refs[0].url | string | 引用数据url,其中,file和qa数据url访问需配置apikey,web数据url访问无需配置apikey |
请求示例
示例如下,请将参数示例值替换为实际值。
- 纯文本请求示例
powershell
curl --location -g --request POST 'https://api.tiangangaitp.com/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [
{
"role": "system",
"content": "你是Tgic的智能助手"
},
{
"role": "user",
"content": "你可以帮我做什么"
}
],
"model":"Qwen2.5-72B-Instruct"
}'curl --location -g --request POST 'https://api.tiangangaitp.com/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [
{
"role": "system",
"content": "你是Tgic的智能助手"
},
{
"role": "user",
"content": "你可以帮我做什么"
}
],
"model":"Qwen2.5-72B-Instruct"
}'响应示例
流式 (event-stream)
powershell
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"我可以","role":"assistant"},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"提供","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"智能问答","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"和帮助。","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":null,"role":null},"finish_reason":"stop"}]}data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"我可以","role":"assistant"},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"提供","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"智能问答","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"和帮助。","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":null,"role":null},"finish_reason":"stop"}]}非流式 (Json)
powershell
{
"object": "chat.completion",
"created": 1724652804,
"model": "Qwen/Qwen2.5-72B-Instruct",
"choices": [
{
"index": 0,
"message": {
"content": "作为Tgic智能助手,我可以帮助你完成多种任务。如果你有具体的需求或问题,请告诉我!",
"role": "assistant"
},
"finish_reason": "stop"
}
]
}{
"object": "chat.completion",
"created": 1724652804,
"model": "Qwen/Qwen2.5-72B-Instruct",
"choices": [
{
"index": 0,
"message": {
"content": "作为Tgic智能助手,我可以帮助你完成多种任务。如果你有具体的需求或问题,请告诉我!",
"role": "assistant"
},
"finish_reason": "stop"
}
]
}Anthropic 协议
请求地址:
https://api.tiangangaitp.com/v1/messages
支持的模型列表,所有的Claude相关模型,具体支持的模型列表。
CodeX 协议
请求地址:
https://api.tiangangaitp.com/v1/responses
支持的模型列表,所有的CodeX相关模型,具体支持的模型列表