TokenLab

Text

Compact Response

Compacts a long conversation into a shorter one for the next Responses request.

POST
/v1/responses/compact

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 model must list openai_responses in accepted_request_formats. Otherwise the request returns 400.
  • stream is not supported on this endpoint. stream: true returns 400.
  • The request is billed by token usage like any other Responses request.

Codex CLI uses this endpoint for remote compaction.

Example

Request

cURL
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 example

Response

200 OK
{
  "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

objectstring
Always response.compaction.
outputarray
The compacted items. Pass them as input of the next request without changes.
usageobject
Token usage of the compaction request.

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
AuthorizationBearer <token>

API Key authentication. Create or manage API keys in Dashboard > API > API Keys.

In: header

Headers

X-TokenLab-Delivery-Policy?string

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