API Path
/aipaas/lm/v1/telechat/completions35
请求协议
HTTPS
请求方法
POST
请求头部 :
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | ||||
| X-APP-ID | 是 | 控制台--应用管理--AppID | [string] | ||||
| Order-Num | 是 | 买家中心-订单管理-订单编号 | [string] | ||||
| Authorization | 是 | 鉴权信息 | [string] |
请求参数 Json
Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| messages | 对话内容。多轮对话场景下,完整的content 长度不可超过模型最大输入。(新版本 messages 子字段内的 content允许为空) | 是 | [array] | |||
| messages>>content | 消息的内容string/array类型,例: “content”:”你好” “content”:[{“type”:”text”,”text”:”你好”}] | 是 | [object] | |||
| messages>>refusal | 助理的拒绝消息 | 否 | [string] | |||
| messages>>role | 消息作者的角色 | 是 | [string] | |||
| messages>>name | 参与者的可选名称。提供模型信息以区分同一角色的参与者,最大长度为 30 | 否 | [string] | |||
| messages>>tool_call_id | 此消息正在响应的工具调用,最大长度为64 | 否 | [string] | |||
| messages>>tool_calls | 模型生成的工具调用 | 否 | [array] | |||
| messages>>tool_calls>>id | 工具调用的 ID | 是 | [string] | |||
| messages>>tool_calls>>type | 工具的类型。目前仅支持 function | 是 | [string] | |||
| messages>>tool_calls>>function | 模型调用的函数 | 是 | [object] | |||
| messages>>tool_calls>>function>>name | 要调用的函数的名称 | 是 | [string] | |||
| messages>>tool_calls>>function>>arguments | 用于调用函数的参数,由模型以 JSON格式生成 | 是 | [object] | |||
| model | 要使用的模型的ID(Chat),最大长度为 64 | 是 | [string] | |||
| max_completion_tokens | 最大生成词元数量。输入词元和生成词元的总长度受模型上下文长度的限制。兼容传入max_tokens,但不允许两个参数同时存在,范围在1到模型最大输出长度(例如:2000) | 是 | [int] | |||
| presence_penalty | 默认值为 0,在 -2.0 到 2.0 之间。正值会基于新生成词是否已经出现在当前文本中进行惩罚,增加模型谈论新主题的可能性。 | 否 | [number] | |||
| stream | 默认值为 false,如果设置true,回答内容讲使用流式传输 | 否 | [boolean] | |||
| stream_options | 流式响应的选项。仅当您设置 stream:true 时 设 置 此 项 才 生 效 。 " s tream_options":{"include_usage": true}如果设置,则在 data: [DONE]之前流式传输的一个块中 usage 此块上的字段显示整个请求的 token 使用情况统计信息。 | 否 | [object] | |||
| tools | 模型可以调用的工具列表。 | 否 | [array] | |||
| tools>>type | 工具的类型。目前仅支持function | 是 | [string] | |||
| tools>>function | 模型调用的函数 | 是 | [object] | |||
| tools>>function>>description | 函数用途的描述,模型使用它来选择何时以及如何调用函数,最大长度2000 | 否 | [string] | |||
| tools>>function>>name | 要调用的函数的名称。必须是 a-z、A-Z、0-9 或包含下划线和短划线,最大长度为 64 | 是 | [string] | |||
| tools>>function>>parameters | 函数接受的参数,描述为 JSON Schema 对象。请参阅 指南 有关示例,请参阅 JSON 架构参考 有关格式的文档 | 否 | [object] | |||
| tools>>function>>strict | 是否在生成函数调用时启用严格的架构遵循。如果设置为 true,则模型将遵循字段中定义的确切架构。当 is 时,仅支持 JSON 架构的子集。在函数调用指南中了解有关结构化输出的更多信息 | 否 | [boolean] | |||
| tool_choice | 控制模型调用工具。 none表示模型不会调用任何工具,而是生成一条消息。 auto表示模型可以在生成消息或调用一个或多个工具之间进行选择 | 否 | [string] | |||
| temperature | 默认值为 0.3,使用的采样温度,范围 [0,2]。较高的值如 0.8 会使输出更随机,而较低的值如 0.2 会使输出更集中且具有确定性,取0时会关闭采样,无随机输出。 | 否 | [number] | |||
| top_p | 默认值为 1,取值范围为[0,1]之间,作为温度采样的替代方法,称为核采样,该方法中模型考虑具有 top_p 概率质量的词元结果 | 否 | [number] | |||
| extra_body | 额外参数 | 否 | [object] | |||
| extra_body>>top_k | 作用:随机候选数(不建议修改) 取值:大于0的值越大,输出的多元性越大。 取值范围:(0,10000] | 否 | [int] | |||
| extra_body>>repetition_penalty | 作用:生成重复惩罚 取值范围:(0,2] | 否 | [double] | |||
| extra_body>>frequency_penalty | 基于它们在生成文本中的频率。值>0鼓励模型使用新令牌,而值 流式响应结果-成功 (200) | |||||
| > Json | ||||||
| > Object |
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| data | 表⽰流式返回的数据块,包含⽣成的⽂本内容,[DONE]表⽰⽣成过程已完成 | 是 | [object] | |||
| data>>id | 聊天补全的唯一标识符(uuid4)。 | 是 | [string] | |||
| data>>choices | 聊天补全选项的列表。 | 否 | [array] | |||
| data>>choices>>finish_reason | string/null,模型停止生成标记的原因。原因可能是stop模型到达自然停止点或提供的停止序列、 length达到请求中指定的最大标记数。 | 否 | [string] | |||
| data>>choices>>index | 选择列表中的索引 | 否 | [int] | |||
| data>>choices>>delta | 模型响应流生成的聊天补全增量。 | 否 | [object] | |||
| data>>choices>>delta>>content | string/null,块消息的内容。 | 否 | [string] | |||
| data>>choices>>delta>>role | 此消息作者的角色。【第一块携带、其他块 不携带此参数】 | 否 | [string] | |||
| data>>choices>>delta>>refusal | string/null,模型生成的拒绝消息【第一块携带、其他块不携带此参数】 | 否 | [string] | |||
| data>>choices>>delta>>tool_calls | 工具列表 | 否 | [array] | |||
| data>>choices>>delta>>tool_calls>>index | 选择列表中的索引 | 否 | [int] | |||
| data>>choices>>delta>>tool_calls>>id | 工具调用的 ID | 否 | [string] | |||
| data>>choices>>delta>>tool_calls>>type | 工具的类型。目前仅支持 function | 否 | [string] | |||
| data>>choices>>delta>>tool_calls>>function | 模型调用的函数。 | 否 | [object] | |||
| data>>choices>>delta>>tool_calls>>function>>name | 要调用的函数的名称 | 否 | [string] | |||
| data>>choices>>delta>>tool_calls>>function>>arguments | 用于调用函数的参数,由模型以 JSON 格式生成。请注意,该模型并不总是生成有效的 JSON,并且可能会产生函数架构未定义的参数。在调用函数之前验证代码中的参数 | 否 | [string] | |||
| data>>choices>>logprobs | object/null,输出标记的对数概率。 | 否 | [object] | |||
| data>>created | 时间戳【秒级】 | 是 | [int] | |||
| data>>model | 用于生成补全的模型。 | 是 | [string] | |||
| data>>object | 对象类型,始终为 chat.completion.chunk。 | 是 | [string] | |||
| data>>usage | object/null,token统计【当stream_options生效时,最后一个块携带usage信息、其他块携带的是null,其他情况默认不携带】 | 否 | [object] | |||
| data>>usage>>completion_tokens | 生成tokens | 否 | [int] | |||
| data>>usage>>prompt_tokens | prompt的tokens | 否 | [int] | |||
| data>>usage>>total_tokens | 总tokens | 否 | [int] | |||
| data>>usage>>completion_tokens_details | 生成 tokens详细统计 | 否 | [object] | |||
| data>>usage>>completion_tokens_details>>reasoning_tokens | 思考 tokens,当前都为0 | 否 | [int] | |||
| data>>system_fingerprint | 代表模型运行时后端配置的指纹。【当前默认null】 | 是 | [string] |
> 非流式响应结果-成功 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 聊天补全的唯一标识符(uuid4)。 | 是 | [string] | |||
| choices | 聊天补全选项的列表。 | 是 | [array] | |||
| choices>>finish_reason | 模型停止生成标记的原因。原因可能是stop模型到达自然停止点或提供的停止序列、 length达到请求中指定的最大标记数。 如果模型调用了工具,tool_calls。 | 是 | [string] | |||
| choices>>index | 选择列表中的索引 | 是 | [int] | |||
| choices>>message | 模型生成的聊天补全消息。 | 是 | [object] | |||
| choices>>message>>content | 消息的内容 | 是 | [string] | |||
| choices>>message>>refusal | 模型生成的拒绝消息。 | 是 | [string] | |||
| 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 格式生成。请注意,该模型并不总是生成有效的 JSON,并且可能会产生函数架构未定义的参数。在调用函数之前验证代码中的参数。 | 是 | [string] | |||
| choices>>message>>role | 此消息作者的角色。 | 是 | [string] | |||
| choices>>logprobs | object/null,输出标记的对数概率。 | 是 | [object] | |||
| created | 时间戳【秒级】 | 是 | [int] | |||
| model | 用于聊天补全的模型。 | 是 | [string] | |||
| object | 对象类型,始终为 chat.completion。 | 是 | [string] | chat.completion.chunk | ||
| usage | token统计 | 是 | [object] | |||
| usage>>completion_tokens | 生成tokens | 是 | [int] | |||
| usage>>prompt_tokens | prompt的tokens | 是 | [int] | |||
| usage>>total_tokens | 总tokens | 是 | [int] | |||
| usage>>completion_tokens_details | 生成tokens详细统计 | 是 | [object] | |||
| usage>>completion_tokens_details>>reasoning_tokens | 思考tokens,当前都为0 | 是 | [int] | |||
| system_fingerprint | 代表模型运行时后端配置的指纹。【当前默认null】 | 是 | [string] |
详细说明 :
TeleChat对话35B版本。
| 日期 | 版本 | 修订内容 |
|---|---|---|
| 2025-10-09 | v1.3.1 | message规则全部关闭;入参新增tool_calls子字段,删除knowledgeBase字段;修改部分字段描述;增加状态码与健康检查接口描述 |
| 2025-02-17 | v1.6.5 | 初始化api文档 |
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 接口签名认证。
通用状态码请参考【状态码】中的【网关认证】
| 字段 | 类型 | 说明 |
|---|---|---|
| code | string | 状态响应码。01110001: 请求体参数不符合类型;01110002: 请求参数不符合规则;01110003: 模型连接错误;01110004: 内部错误 |
| message | string | 错误消息提示 |
流式请求示例
{
"model": "telechat-35b",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": true
}
流式响应示例
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "",
"role": "assistant",
"refusal": null
},
"logprobs": null
}],
"created": 1729666765,
"system_fingerprint": null,
"model": "aichat",
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "u4f60u597d"
},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
........中间省略消息块
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "uff1f"
},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": "stop",
"index": 0,
"delta": {},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "c86aff51e90442ed8c7e1ab5296189a8",
"choices": [],
"created": 1729666822,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk",
"usage": {
"completion_tokens": 40,
"prompt_tokens": 23,
"total_tokens": 63,
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
}
此消息块在stream_option生效时产生
data: [DONE]
非流式请求示例
{
"model": "telechat-35b",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": false
}
非流式响应示例
{
"id": "aacd0a837f244378812fa898d5094fe2",
"choices": [{
"finish_reason": "stop",
"index": 0,
"message": {
"refusal": null,
"role": "assistant",
"content": " 你好,我很乐意为你解答问题。请问有什么我可以帮助你的吗?"
},
"logprobs": null
}],
"created": 1729666692,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion",
"usage": {
"completion_tokens": 41,
"prompt_tokens": 23,
"total_tokens": 64,
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
}
| 参数 | 数据类型 | 说明 | 备注 |
|---|---|---|---|
| code | int | 状态码 | 无 |
| data | obj | 返回消息体 | 无 |
| data.error_code | string | 返回服务状态码 | 无 |
| data.error_message | string | 返回模型状态信息 | 无 |
| data.algo_types | array | 算法类型 | 无 |
响应示例:
{
"code": 10000,
"data": {
"error_code": "APP_ERR_OK",
"error_message": "正常状态
",
"algo_types": ["0000"]
}
}
tips:模型健康检测接口 http_code 返回非 200,即可认为模型异常。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 系统消息的内容 例:“content”:”你好”“content”:[{“type”:”text”,”text”:”你好”}] |
| role | 是 | string | 消息作者的角色,在本例中为 system |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者,最大长度为 30 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| role | 是 | string | 消息作者的角色,在本例中为 user |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者,最大长度为 30 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| refusal | 否 | string | 助理的拒绝消息。 |
| role | 是 | string | 消息作者的角色,在本例中assistant |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者,最大长度为 30 |
| tool_calls | 否 | array | 模型生成的工具调用,详见请求字段 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| role | 是 | string | 消息作者的角色,在本例中为tool |
| content | 是 | string/array | 工具消息的内容。 |
| tool_call_id | 否 | string | 此消息正在响应的工具调用,最大长度为 64 |
本次全部关闭。
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/** 主类,用于发起HTTP请求并处理响应 */
public class Example {
public static void main(String[] args) {
example();
}
/**
* 方法中使用到的 JSONUtil、HttpRequest、HttpResponse均来自Hutool工具类。
* 具体maven依赖为:
*
* cn.hutool
* hutool-all
* 5.8.29
*
*/
public static void example() {
try {
String url = "算法调用地址";
// 设置请求头
Map headers = new HashMap();
//调用鉴权
headers.put("Content-Type", "application/json");
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
// 创建请求对象
Map request = new HashMap();
request.put("model", "telechat-35b");
Map messages = new HashMap();
messages.put("role", "user");
messages.put("content", "你是什么模型,能处理什么问题");
request.put("messages", Arrays.asList(messages));
request.put("max_completion_tokens", 150);
request.put("stream", true);
// 将请求对象转换为JsonNode
String requestString = JSONUtil.toJsonStr(request);
// 发起HTTP请求
HttpResponse response =
HttpRequest.post(url)
.headerMap(headers, true)
.body(requestString)
.execute();
// 输出响应结果
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import json
import hashlib
import hmac
import time
import re
import urllib.parse
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# URL 和请求数据
url = "算法调用地址" # 请求的URL
request_data = {
"model": "telechat-35b",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": True
}
# 构建请求头
headers = {
"Content-Type": "application/json",
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")