Context Caching for Conversation Creation

1. Overview

Create a context cache. After obtaining the cache ID field through this interface, use the context_id in Context Caching for Conversation Generation.

Available model list:

  • Doubao-1.5-pro-32k

  • Doubao-1.5-lite-32k

  • Doubao-pro-32k

2. Request Description

  • Request method: POST

  • Request address: https://gateway.theturbo.ai/v1/context/create

3. Input Parameters

3.1 Header Parameters

Parameter Name
Type
Required
Description
Example Value

Content-Type

string

Yes

Set the request header type, which must be application/json

application/json

Accept

string

Yes

Set the response type, which is recommended to be unified as application/json

application/json

Authorization

string

Yes

API_KEY required for authentication. Format: Bearer $YOUR_API_KEY

Bearer $YOUR_API_KEY

3.2 Body Parameters (application/json)

Parameter Name
Type
Required
Description
Example

model

string

Yes

Doubao-1.5-pro-32k

messages

array

Yes

Chat message list, compatible with OpenAI interface format. Each object in the array contains role and content.

[{"role": "user","content": "you are a helpful assistant"}]

role

string

No

Message role. Optional values: system, user, assistant.

system

content

string

No

The specific content of the message.

you are a helpful assistant

mode

string

No

Session cache (session) and prefix cache (common_prefix) are available.

session

ttl

number

No

The expiration time is in seconds, starting when created and resetting with each use. If it exceeds the TTL, the data is deleted. TTL can be set between 1 hour (3600 seconds) and 7 days (604800 seconds).

86400

4. Request Example

POST /v1/context/create
Content-Type: application/json
Accept: application/json
Authorization: Bearer $YOUR_API_KEY

{
	"model": "Doubao-1.5-pro-32k",
	"messages": [
		{
			"role": "system",
			"content": "Please be a helpful assistant"
		},
		{
			"role": "user",
			"content": "Hello"
		}
	],
	"mode":"session",
	"ttl": 3600
}

5. Response Example

{
	"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"
}

Last updated