Text
Compact Response
Compacts a long conversation into a shorter one for the next Responses request.
Overview
Compacts the input of a long conversation and returns a response.compaction object. Its output array holds the items to send as input of your next Create Response request. Send the returned items unchanged, and keep using the same model: the compaction item is encrypted, and another model may not accept it.
- The
modelmust listopenai_responsesinaccepted_request_formats. Otherwise the request returns400. streamis not supported on this endpoint.stream: truereturns400.- The request is billed by token usage like any other Responses request.
Codex CLI uses this endpoint for remote compaction.
Request
curl -X POST "https://api.tokenlab.sh/v1/responses/compact" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-terra",
"input": [
{"type": "message", "role": "user", "content": "Plan a three-day trip to Kyoto."},
{"type": "message", "role": "assistant", "content": "Day 1: Fushimi Inari and Gion. Day 2: Arashiyama. Day 3: Kinkaku-ji and Nishiki Market."},
{"type": "message", "role": "user", "content": "Add a tea ceremony on day 2."}
]
}'Response
{
"id": "resp_abc123",
"object": "response.compaction",
"created_at": 1706000000,
"output": [
{
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "Plan a three-day trip to Kyoto."}]
},
{
"id": "cmp_abc123",
"type": "compaction",
"encrypted_content": "gAAAAAB..."
}
],
"usage": {
"input_tokens": 120,
"output_tokens": 30,
"total_tokens": 150
}
}Important fields
response.compaction.input of the next request without changes.Errors
Errors use the OpenAI-style error object: 400 for an invalid field or a model without the Responses format, 401 for an invalid key, 402 for insufficient balance, and 503 when the model cannot serve the request now. See Handle API errors.
Authorization
BearerAuth API Key authentication. Create or manage API keys in Dashboard > API > API Keys.
In: header
Headers
Per-request Delivery policy. Overrides the API key and Workspace defaults. Auto tries TokenLab Verified first and may switch once to Official only before output, request acceptance, or persistent resource creation.
Value in
- "auto"
- "verified"
- "official"
Request Body
application/json
Response
application/json
application/json
application/json
application/json