Sample - OpenAI API
POST/responses/compact

Compact a conversation

Compacts a conversation into a smaller response representation. Provide the required model and the input or previous response context to reduce the conversation while preserving the output items needed for continued work. The response includes the compacted output and token usage details.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

8 body fields

Conversation configuration used to create a compacted response.

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 inputs to include in the conversation.
previous_response_idstringoptional
The unique ID of a previous response used to provide conversation state.
instructionsstringoptional
System or developer instructions inserted into the model context.
prompt_cache_keystringoptional
A key used to read from or write to the prompt cache. Maximum 64 characters.
prompt_cache_retentionstringdeprecatedoptional
How long to retain the prompt cache entry: `in_memory` or `24h`. This field is deprecated.
Allowed:in_memory24h
prompt_cache_optionsobjectoptional
Options for prompt caching, including cache time-to-live and mode settings.
service_tierstringoptional
The processing tier: `auto`, `default`, `fast`, `flex`, or `priority`.
Allowed:autodefaultfastflexpriority

3 status codes
200Returns a compacted response object containing its `id`, `response.compaction` object type, compacted `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.
429Returned when the request is rejected because the rate limit was exceeded; a `slow_down` error indicates that traffic increased too quickly.

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 because the requested model is overloaded; 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

The model field is required. A 429 is returned when the rate limit is exceeded, including traffic that increases too quickly; a 503 is returned when the requested model is temporarily overloaded. prompt_cache_key must be no more than 64 characters, and service_tier must be one of auto, default, fast, flex, or priority when provided.