POST/responses/compact

Compact a conversation

Compacts conversation input and returns a compacted response object with output items and token usage. Provide the required model and any input or conversation context to compact. Do not combine previous_response_id with conversation.

  • IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.

8 body fields

Conversation compaction request. The model field is required; the other fields are optional.

modelstringrequired
Model ID used to generate the response, like `gpt-6-astra`. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the [model guide](https://developers.openai.com/api/docs/models) to browse and compare available models.
inputstring | arrayoptional
Text, image, or file input to include in the conversation context.
previous_response_idstringoptional
The unique ID of a previous response to use as conversation context. Do not use together with `conversation`.
instructionsstringoptional
A system or developer message to include in the model's context.
prompt_cache_keystringoptional
A key to use when reading from or writing to the prompt cache. Maximum 64 characters.
prompt_cache_retentionstringdeprecatedoptional
How long to retain a prompt cache entry: `in_memory` or `24h`.
Allowed:in_memory24h
prompt_cache_optionsobjectoptional
Options for prompt caching.
service_tierstringoptional
Processing tier: `auto`, `default`, `fast`, `flex`, or `priority`.
Allowed:autodefaultfastflexpriority

4 status codes
200Returns the compacted response object with its identifier, output items, creation timestamp, and token usage details.
idstringrequired
The unique identifier for the compacted response.
objectstringrequired
The object type. Always `response.compaction`.
Allowed:response.compactionDefault:response.compaction
outputarray<Message>required
The compacted list of output items.
created_atintegerrequired
Unix timestamp (in seconds) when the compacted conversation was created.
usageobjectrequired
Represents token usage details including input tokens, output tokens, a breakdown of output tokens, and the total tokens used.
400Returned when the compaction request is invalid or contains incompatible input parameters.
errorobjectrequired
429Returned when the request exceeds a rate limit. For a `slow_down` error, reduce your request rate and increase it gradually.

One documented failure

  • slow_down

    Your request rate increased too quickly. Please reduce the request rate and gradually increase it again.

    Traffic increased too quickly

errorobjectrequired
503Returned when the service is temporarily unavailable. For a `server_is_overloaded` error, retry after a brief delay.

One documented failure

  • server_is_overloaded

    The model is temporarily overloaded. Please retry your request after a brief delay.

    The requested model is temporarily overloaded

errorobjectrequired

Error handling

A 400 is returned when the compaction request is invalid or contains incompatible input parameters, including using previous_response_id with conversation. A 429 is returned when the request exceeds a rate limit; for a slow_down error, reduce your request rate and increase it gradually. A 503 indicates temporary service unavailability; for a server_is_overloaded error, retry after a brief delay. The request body must include model.