On this page
article
上下文缓存对话创建
1.概述
创建上下文缓存,通过本接口获得缓存id字段后,在上下文缓存对话生成接口中通过携带context_id
使用。
模型列表:
Doubao-1.5-pro-32k
Doubao-1.5-lite-32k
Doubao-pro-32k
2.请求说明
- 请求方法:
POST
- 请求地址
https://gateway.theturbo.ai/v1/context/create
3.请求参数
3.1 Head参数
参数名称 | 类型 | 必填 | 说明 | 示例值 |
---|---|---|---|---|
Content-Type |
string | 是 | 设置请求头类型,必须为application/json |
application/json |
Accept |
string | 是 | 设置响应类型,建议统一为application/json |
application/json |
Authorization |
string | 是 | 身份验证所需的 API_KEY,格式Bearer $YOUR_API_KEY |
Bearer $YOUR_API_KEY |
3.2 Body 参数 (application/json)
参数名称 | 类型 | 必填 | 说明 | 示例 |
---|---|---|---|---|
model | string | 是 | 要使用的模型 ID。详见概述列出的可用版本,如 Doubao-1.5-pro-32k 。 |
Doubao-1.5-pro-32k |
messages | array | 是 | 聊天消息列表。数组中的每个对象包含role (角色) 与 content (内容)。 |
[{"role": "user","content": "你好"}] |
role | string | 否 | 消息角色,可选值: system 、user 、assistant 。 |
user |
mode | string | 否 | 上下文缓存的类型,详细见官方文档上下文缓存(Context API)概述。支持session缓存session 和前缀缓存common_prefix 。 |
session |
ttl | number | 否 | 过期时长,单位为秒。信息在创建后即开始计时,每次使用则重置为0。计时超过ttl,信息会被从缓存中删除。每次调用chat均根据ttl更新过期时间。过期时间可以设置的范围在1小时到7天,即[3600, 604800]。 | 86400 |
4.请求示例
4.1聊天对话
5.响应示例
{
"id": "ctx-20241211104333-12345",
"ttl": 3600,
"truncation_strategy": {
"type": "rolling_tokens",
"rolling_tokens": true
},
"usage": {
"prompt_tokens": 8,
"completion_tokens": 0,
"total_tokens": 8,
"prompt_tokens_details": {
"cached_tokens": 0
}
},
"mode": "session"
}