---
title: "Compact context (OpenAI)"
method: POST
path: "/openai/v1/responses/compact"
tags: ["OpenAI Integration"]
---

# Compact context (OpenAI)

`POST /openai/v1/responses/compact`

Compresses a conversation into an opaque compaction item using the OpenAI-compatible
`/v1/responses/compact` endpoint. Drop-in compatible with the OpenAI SDK.

The response `output` contains the user messages plus a final item with
`type: "response.compaction"` and `encrypted_content`. Pass this output as `input`
to future Responses API calls to continue the conversation using the compacted context.

**Note:** This endpoint also works without the `/v1` prefix (e.g., `/openai/responses/compact`).

## Request body

- object
  - `model` string, required — Model identifier (e.g., "gpt-4o"). When routing through Bifrost's provider-prefixed path, use "provider/model" format.
  - `input` union — Conversation to compact. Required unless previous_response_id is set. Compaction items (type "response.compaction") from prior responses may be included.
    - string
    - object[]
      - `id` string
      - `type` 'message' | 'file_search_call' | 'computer_call' | 'computer_call_output' | 'web_search_call' | 'web_fetch_call' | 'function_call' | 'function_call_output' | 'code_interpreter_call' | 'local_shell_call' | 'local_shell_call_output' | 'mcp_call' | 'custom_tool_call' | 'custom_tool_call_output' | 'image_generation_call' | 'mcp_list_tools' | 'mcp_approval_request' | 'mcp_approval_responses' | 'reasoning' | 'item_reference' | 'refusal'
      - `status` 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed'
      - `role` 'assistant' | 'user' | 'system' | 'developer'
      - `content` union
        - string
        - object[]
          - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
          - `file_id` string
          - `text` string
          - `signature` string
          - `image_url` string
          - `detail` string
          - `file_data` string
          - `file_url` string
          - `filename` string
          - `file_type` string
          - `input_audio` object
            - `format` 'mp3' | 'wav', required
            - `data` string, required
          - `annotations` object[]
            - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
            - `index` integer
            - `file_id` string
            - `text` string
            - `start_index` integer
            - `end_index` integer
            - `filename` string
            - `title` string
            - `url` string
            - `container_id` string
          - `logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
            - `top_logprobs` object[]
              - …
          - `refusal` string
          - `cache_control` CacheControl — Cache control settings for content blocks
            - `type` 'ephemeral'
            - `ttl` string — Time to live (e.g., "1m", "1h")
      - `call_id` string
      - `name` string
      - `arguments` string
      - `output` union — Tool call output. A plain string for function/custom/local-shell tool outputs, an array of content blocks for structured function tool outputs, or a computer-tool screenshot object for computer_call_output.
        - string
        - object[]
          - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
          - `file_id` string
          - `text` string
          - `signature` string
          - `image_url` string
          - `detail` string
          - `file_data` string
          - `file_url` string
          - `filename` string
          - `file_type` string
          - `input_audio` object
            - `format` 'mp3' | 'wav', required
            - `data` string, required
          - `annotations` object[]
            - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
            - `index` integer
            - `file_id` string
            - `text` string
            - `start_index` integer
            - `end_index` integer
            - `filename` string
            - `title` string
            - `url` string
            - `container_id` string
          - `logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
            - `top_logprobs` object[]
              - …
          - `refusal` string
          - `cache_control` CacheControl — Cache control settings for content blocks
            - `type` 'ephemeral'
            - `ttl` string — Time to live (e.g., "1m", "1h")
        - object — Computer tool call output (computer_screenshot).
          - `type` 'computer_screenshot'
          - `file_id` string
          - `image_url` string
      - `action` object
      - `error` string
      - `queries` string[]
      - `results` object[]
      - `summary` object[]
        - `type` 'summary_text', required
        - `text` string, required
      - `encrypted_content` string
  - `instructions` string — System instructions that persist across the compacted context.
  - `previous_response_id` string — ID of a previous response to extend rather than sending full input.
  - `prompt_cache_key` string
  - `prompt_cache_retention` string
  - `service_tier` string
  - `fallbacks` string[] — Bifrost-specific — fallback model list in provider/model format.

## Response `200`

Successful compaction response

- object
  - `id` string
  - `object` string — Always "response.compaction"
  - `model` string
  - `created_at` integer
  - `output` object[] — The compacted output — the original user messages plus a final item of type "response.compaction" whose encrypted_content holds the opaque compacted state. Pass the full output array as input to a future Responses API request.
    - `id` string
    - `type` 'message' | 'file_search_call' | 'computer_call' | 'computer_call_output' | 'web_search_call' | 'web_fetch_call' | 'function_call' | 'function_call_output' | 'code_interpreter_call' | 'local_shell_call' | 'local_shell_call_output' | 'mcp_call' | 'custom_tool_call' | 'custom_tool_call_output' | 'image_generation_call' | 'mcp_list_tools' | 'mcp_approval_request' | 'mcp_approval_responses' | 'reasoning' | 'item_reference' | 'refusal'
    - `status` 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed'
    - `role` 'assistant' | 'user' | 'system' | 'developer'
    - `content` union
      - string
      - object[]
        - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
        - `file_id` string
        - `text` string
        - `signature` string
        - `image_url` string
        - `detail` string
        - `file_data` string
        - `file_url` string
        - `filename` string
        - `file_type` string
        - `input_audio` object
          - `format` 'mp3' | 'wav', required
          - `data` string, required
        - `annotations` object[]
          - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
          - `index` integer
          - `file_id` string
          - `text` string
          - `start_index` integer
          - `end_index` integer
          - `filename` string
          - `title` string
          - `url` string
          - `container_id` string
        - `logprobs` object[]
          - `bytes` integer[]
          - `logprob` number
          - `token` string
          - `top_logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
        - `refusal` string
        - `cache_control` CacheControl — Cache control settings for content blocks
          - `type` 'ephemeral'
          - `ttl` string — Time to live (e.g., "1m", "1h")
    - `call_id` string
    - `name` string
    - `arguments` string
    - `output` union — Tool call output. A plain string for function/custom/local-shell tool outputs, an array of content blocks for structured function tool outputs, or a computer-tool screenshot object for computer_call_output.
      - string
      - object[]
        - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
        - `file_id` string
        - `text` string
        - `signature` string
        - `image_url` string
        - `detail` string
        - `file_data` string
        - `file_url` string
        - `filename` string
        - `file_type` string
        - `input_audio` object
          - `format` 'mp3' | 'wav', required
          - `data` string, required
        - `annotations` object[]
          - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
          - `index` integer
          - `file_id` string
          - `text` string
          - `start_index` integer
          - `end_index` integer
          - `filename` string
          - `title` string
          - `url` string
          - `container_id` string
        - `logprobs` object[]
          - `bytes` integer[]
          - `logprob` number
          - `token` string
          - `top_logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
        - `refusal` string
        - `cache_control` CacheControl — Cache control settings for content blocks
          - `type` 'ephemeral'
          - `ttl` string — Time to live (e.g., "1m", "1h")
      - object — Computer tool call output (computer_screenshot).
        - `type` 'computer_screenshot'
        - `file_id` string
        - `image_url` string
    - `action` object
    - `error` string
    - `queries` string[]
    - `results` object[]
    - `summary` object[]
      - `type` 'summary_text', required
      - `text` string, required
    - `encrypted_content` string
  - `usage` object
    - `input_tokens` integer
    - `input_tokens_details` object
      - `text_tokens` integer
      - `audio_tokens` integer
      - `image_tokens` integer
      - `cached_read_tokens` integer — Tokens served from the prompt cache (cache hit), billed at the reduced cache-read rate. Already included in the parent input_tokens total.
      - `cached_write_tokens` integer — Tokens written to the prompt cache on this request, billed at the cache-creation rate. Already included in the parent input_tokens total. Populated for providers that separately report cache write tokens (Anthropic, Bedrock).
    - `output_tokens` integer
    - `output_tokens_details` object
      - `text_tokens` integer
      - `accepted_prediction_tokens` integer
      - `audio_tokens` integer
      - `reasoning_tokens` integer
      - `rejected_prediction_tokens` integer
      - `citation_tokens` integer
      - `num_search_queries` integer
    - `total_tokens` integer
    - `cost` BifrostCost — Cost breakdown for the request
      - `input_tokens_cost` number
      - `output_tokens_cost` number
      - `reasoning_tokens_cost` number — Cost for reasoning/thinking tokens (reasoning models)
      - `citation_tokens_cost` number — Cost for citation tokens
      - `search_queries_cost` number — Cost for web search queries
      - `request_cost` number
      - `total_cost` number
  - `extra_fields` BifrostResponseExtraFields — Additional fields included in responses
    - `request_type` string — Type of request that was made
    - `provider` 'openai' | 'azure' | 'anthropic' | 'bedrock' | 'cohere' | 'vertex' | 'vllm' | 'mistral' | 'ollama' | 'groq' | 'sgl' | 'parasail' | 'perplexity' | 'replicate' | 'cerebras' | 'deepseek' | 'gemini' | 'openrouter' | 'elevenlabs' | 'huggingface' | 'nebius' | 'xai' | 'runway' | 'fireworks' — AI model provider identifier
    - `model_requested` string — The model that was requested
    - `model_deployment` string — The actual model deployment used
    - `latency` integer — Request latency in milliseconds
    - `chunk_index` integer — Index of the chunk for streaming responses
    - `raw_request` object — Raw request if enabled
    - `raw_response` object — Raw response if enabled
    - `cache_debug` BifrostCacheDebug
      - `cache_hit` boolean
      - `cache_id` string
      - `hit_type` string
      - `requested_provider` string
      - `requested_model` string
      - `provider_used` string
      - `model_used` string
      - `input_tokens` integer
      - `threshold` number
      - `similarity` number

## Other responses

- `400` — Bad request
- `500` — Internal server error

---

[API](https://skmtc.net/getbifrost/apis/bifrost-api.md) · [All operations](https://skmtc.net/getbifrost/apis/bifrost-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/getbifrost/bifrost-api/versions/f8cab88f64ea/schema)
