接口文档
更新时间 2026-09-26 00:42:53
最近更新时间: 2026-09-26 00:42:53
接口信息
API Path
/aipaas/algo/v1/telechat-29b/v1/chat/completions
请求协议
HTTPS POST
服务鉴权
本算法采用OpenAI协议鉴权(Bearer Token)。
在请求头中携带API Key:`Authorization: Bearer <用户申请的API-KEY>。请在API Key页面获取长效API Key。
请求头部:
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | - | - | application/json | application/json |
| traceparent | 否 | W3C Trace Context链路追踪头,格式:{version}-{trace-id}-{parent-id}-{flags} | [string] | - | - | - | 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 |
| session-id | 否 | 多轮对话场景下传入,不同session传入不同session-id,非多轮对话场景请不要设置此字段设备管理-设备uuid | [string] | - | - | - | - |
| Authorization | 是 | Bearer Token鉴权,格式:Bearer <用户申请的API-KEY> | [string] | - | - | - | Bearer sk-xxxx |
traceparent字段说明
| 字段 | 示例值 | 说明 |
|---|---|---|
| version | 00 | W3C版本号,默认00 |
| trace-id | 0af7651916cd43dd8448eb211c80319c | 32位十六进制,整条链路唯一ID |
| parent-id | b7ad6b7169203331 | 16位十六进制,当前请求span ID |
| flags | 01 | 默认01即可 |
请求参数
Json Object
| 参数名 | 说明 | 必填 | 类型 |
|---|---|---|---|
| model | 固定值 XingChen4-29B-A4B | 是 | [string] |
| messages | 消息数组,按对话顺序排列 | 是 | [array] |
| messages>>role | 角色 | 是 | [string] |
| messages>>content | 消息内容,支持纯文本或内容块数组 | 是 | [string/array] |
| messages>>name | 参与者名称,用于区分同名角色 | 否 | [string] |
| messages>>tool_calls | 助手消息触发的工具调用(仅assistant) | 否 | [array] |
| messages>>tool_call_id | 关联的工具调用ID(tool角色必填) | 否 | [string] |
| frequency_penalty | 频率惩罚,范围-2.0~2.0,默认0 | 否 | [number] |
| logprobs | 是否返回每个输出token的对数概率,默认false | 否 | [boolean] |
| top_logprobs | 每个token返回概率最高的前N个备选,0~20,需logprobs=true | 否 | [integer] |
| max_tokens | 已弃用,请改用max_completion_tokens | 否 | [integer] |
| max_completion_tokens | 生成的最大token数(含推理token) | 否 | [integer] |
| n | 生成的候选回复数,默认1 | 否 | [integer] |
| presence_penalty | 存在惩罚,范围-2.0~2.0,默认0 | 否 | [number] |
| response_format | 输出格式约束 | 否 | [object] |
| response_format>>type | text:默认文本输出;json_object:JSON对象输出(提示词中需包含「json」字样);json_schema:按JSON Schema约束输出 | 否 | [string] |
| response_format>>json_schema | JSON Schema约束定义(type为json_schema时使用) | 否 | [object] |
| response_format>>json_schema>>name | Schema名称 | 否 | [string] |
| response_format>>json_schema>>description | Schema描述 | 否 | [string] |
| response_format>>json_schema>>schema | JSON Schema定义 | 否 | [object] |
| seed | 随机种子,用于可复现采样 | 否 | [integer] |
| stop | 停止序列,最多4个 | 否 | [string/array] |
| stream | 是否流式返回,默认false | 否 | [boolean] |
| stream_options | 流式附加选项 | 否 | [object] |
| stream_options>>include_usage | 为true时,流式末尾额外返回一个仅含usage的chunk | 否 | [boolean] |
| temperature | 采样温度,范围0~2,默认1 | 否 | [number] |
| top_p | 核采样,范围0~1,默认1 | 否 | [number] |
| tools | 工具定义数组 | 否 | [array] |
| tools>>type | 工具类型,当前为function | 是 | [string] |
| tools>>function | 函数定义 | 是 | [object] |
| tools>>function>>name | 函数名 | 是 | [string] |
| tools>>function>>description | 函数描述 | 否 | [string] |
| tools>>function>>parameters | JSON Schema形式的参数定义 | 否 | [object] |
| tool_choice | 工具调用策略:none(不调用)/auto(自动决定)/required(必须调用),或指定具体函数 | 否 | [string/object] |
| parallel_tool_calls | 是否允许并行调用多个工具,默认true | 否 | [boolean] |
| chat_template_kwargs | 深度思考模式参数,传入 {"enable_thinking": true} 启用深度思考 | 否 | [object] |
| chat_template_kwargs>>enable_thinking | 传入true启用深度思考 | 否 | [boolean] |
注:system与developer角色均为系统级指令;developer仅部分模型支持,优先使用system
返回结果
非流式返回
| 参数名 | 说明 | 必填 | 类型 |
|---|---|---|---|
| id | 本次完成的唯一ID | 是 | [string] |
| object | 固定为chat.completion | 是 | [string] |
| created | 创建时间(Unix秒级时间戳) | 是 | [integer] |
| model | 实际使用的模型 | 是 | [string] |
| choices | 候选回复列表 | 是 | [array] |
| choices>>index | 候选序号 | 是 | [integer] |
| choices>>message | 回复消息对象 | 是 | [object] |
| choices>>message>>role | 固定为assistant | 是 | [string] |
| choices>>message>>content | 回复内容 | 是 | [string] |
| choices>>message>>reasoning | 深度思考 | 否 | [string] |
| choices>>message>>refusal | 拒绝回答时的说明 | 否 | [string/null] |
| choices>>message>>tool_calls | 工具调用列表(触发工具时返回) | 否 | [array] |
| choices>>message>>tool_calls>>id | 工具调用ID | 否 | [string] |
| choices>>message>>tool_calls>>type | 类型,为function | 否 | [string] |
| choices>>message>>tool_calls>>function | 函数调用信息 | 否 | [object] |
| choices>>message>>tool_calls>>function>>name | 函数名 | 否 | [string] |
| choices>>message>>tool_calls>>function>>arguments | 函数参数(JSON字符串) | 否 | [string] |
| choices>>finish_reason | 结束原因 | 是 | [string] |
| choices>>logprobs | 输出token的对数概率(开启logprobs时返回) | 否 | [object] |
| usage | token用量 | 是 | [object] |
| usage>>prompt_tokens | 输入token数 | 是 | [integer] |
| usage>>completion_tokens | 输出token数 | 是 | [integer] |
| usage>>total_tokens | 总token数 | 是 | [integer] |
| usage>>prompt_tokens_details>>cached_tokens | 命中的缓存token数 | 否 | [integer] |
注:非流式返回JSON示例中还包含service_tier、system_fingerprint、usage.completion_tokens_details等字段,参见下方请求示例中的非流式返回示例
流式返回(SSE,stream=true)
每个chunk的object为chat.completion.chunk,choices[].delta增量返回内容:
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 完成ID | 是 | [string] | - | - | - |
| object | 固定为chat.completion.chunk | 是 | [string] | - | - | - |
| created | 创建时间 | 是 | [integer] | - | - | - |
| model | 模型 | 是 | [string] | - | - | - |
| choices | 候选列表 | 是 | [array] | - | - | - |
| choices>>index | 候选序号 | 是 | [integer] | - | - | - |
| choices>>delta | 增量内容,字段与消息一致(如content、tool_calls) | 是 | [object] | - | - | - |
| choices>>finish_reason | 结束时返回原因 | 否 | [string/null] | - | - | - |
| choices>>logprobs | 增量logprobs(可选) | 否 | [object] | - | - | - |
| usage | 仅当stream_options.include_usage=true时,在最后一个chunk返回 | 否 | [object] | - | - | - |
finish_reason取值说明
| 返回码 | 说明 |
|---|---|
| stop | 正常结束(命中停止序列) |
| length | 达到token上限 |
| content_filter | 内容被安全策略拦截 |
| tool_calls | 模型发起工具调用 |
请求示例
请求体示例
{
"model": "TeleChat3-438B-A24B",
"messages": [
{ "role": "system", "content": "你是乐于助人的助手。" },
{ "role": "user", "content": "你好,一句话介绍一下你自己" }
],
"stream": true,
"stream_options": { "include_usage": true },
"temperature": 0.7,
"max_completion_tokens": 1024,
"top_p": 0.9,
"frequency_penalty": 0,
"presence_penalty": 0,
"seed": 42,
"response_format": { "type": "text" }
}非流式返回示例
{
"id": "chatcmpl-xxxxxxxx",
"object": "chat.completion",
"created": 1731691468,
"model": "TeleChat3-438B-A24B",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我是TeleChat大模型,由中电信人工智能科技研发。",
"refusal": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 20,
"total_tokens": 35,
"prompt_tokens_details": { "cached_tokens": 0 },
"completion_tokens_details": { "reasoning_tokens": 0 }
},
"service_tier": "default",
"system_fingerprint": "fp_xxxxxxxx"
}流式返回示例(SSE)
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1731691468,"model":"TeleChat3-438B-A24B","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1731691468,"model":"TeleChat3-438B-A24B","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1731691468,"model":"TeleChat3-438B-A24B","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1731691468,"model":"TeleChat3-438B-A24B","choices":[],"usage":{"prompt_tokens":15,"completion_tokens":20,"total_tokens":35}}
data: [DONE]curl调用示例
curl --location 'https://openapi.teleagi.cn/aipaas/algo/v1/telechat3-438b-a24b/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <用户申请的API-KEY>' \
--data '{
"model": "TeleChat3-438B-A24B",
"messages": [
{ "role": "user", "content": "你好,一句话介绍一下你自己" }
],
"stream": true
}'Python调用示例
import requests
url = "https://openapi.teleagi.cn/aipaas/algo/v1/telechat3-438b-a24b/v1/chat/completions"
api_key = "<用户申请的API-KEY>"
payload = {
"model": "TeleChat3-438B-A24B",
"messages": [{"role": "user", "content": "你好,一句话介绍一下你自己"}],
"stream": True,
}
resp = requests.post(
url,
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
},
json=payload,
stream=True,
)
# 流式解析 SSE
for line in resp.iter_lines(decode_unicode=True):
if line and line.startswith("data:"):
data = line[len("data:"):].strip()
if data == "[DONE]":
break
print(data)Java调用示例(OkHttp + Jackson)
import okhttp3.*;
import com.fasterxml.jackson.databind.ObjectMapper;
public class ChatCompletionsExample {
public static void main(String[] args) throws Exception {
String url = "https://openapi.teleagi.cn/aipaas/algo/v1/telechat3-438b-a24b/v1/chat/completions";
String apiKey = "<用户申请的API-KEY>";
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(java.util.Map.of(
"model", "TeleChat3-438B-A24B",
"messages", java.util.List.of(
java.util.Map.of("role", "user", "content", "你好,一句话介绍一下你自己")
),
"stream", true
));
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer " + apiKey)
.post(RequestBody.create(json, MediaType.get("application/json")))
.build();
try (Response response = client.newCall(request).execute()) {
// 非流式:直接打印 body
System.out.println(response.body().string());
// 流式:通过 ResponseBody.source() 逐行读取 SSE,遇 [DONE] 结束
}
}
}