> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Compact response

> Referência da API para POST /v1/responses/compact. Resuma itens mais antigos da conversa em um único item de compactação.

> [!NOTE]
>
> **Guia relacionado**: compactação de contexto. Consulte [Compactação de contexto](/docs/pt-BR/ai-gateway/features/context-compaction.md) para limites, compactação automática e o item a partir do qual continuar.


## OpenAPI

````yaml post /v1/responses/compact
openapi: 3.1.0
info:
  title: Toqan Router API
  version: '2.0'
  description: Toqan Router API documentation
servers:
  - url: https://router.toqan.ai/eu
    description: Frankfurt (Europe)
  - url: https://router.toqan.ai/br
    description: São Paulo (Brazil)
security:
  - ApiKey: []
tags:
  - description: >-
      API keys authenticate programmatic access to the workspace. They expose
      opaque tokens, per-domain access grants, and budget and rate-limit
      constraints.
    name: API keys
  - name: Logs
    description: >-
      OpenTelemetry log query API. Search, filter, aggregate, and facet log
      records ingested via OTLP.
  - name: Reporting
    description: >-
      GenAI reporting API over canonical analytics rollups. Accepts a metric
      name, time range, grain, group-by, and filters; returns a typed time
      series and optional totals.
  - name: Telemetry
    description: >-
      Unified query envelope for traces, metrics, and logs. One request shape,
      one filter dialect, and one response shape per source, validated by a
      per-source registry.
  - name: Traces
    description: >-
      Query and inspect ingested trace data: search trace summaries, aggregate
      metrics, and read individual traces and their spans.
  - name: Views
    description: Saved filters and columns for workspace observability pages.
  - description: List models available through the AI Router.
    name: Models
  - name: Alerts
    description: >-
      Alerts evaluate a telemetry metric on a fixed interval and fire
      notifications through notifiers when the value breaches a threshold. Each
      breach opens a trigger that tracks the incident until the value recovers.
  - name: Annotation Queues
    description: Annotation queues collect spans for human review.
  - name: Budgets
    description: >-
      Budgets govern spend, token usage, and request rate across six scopes:
      workspace, project, identity, API key, provider, and model. Every
      applicable budget is enforced, and the most restrictive limit applies per
      dimension.
  - name: Files
    description: File upload and retrieval operations.
  - name: Guardrail Rules
    description: >-
      Guardrail Rules conditionally enforce evaluators and plugins for AI
      Gateway traffic. Rules may be scoped to a project or the whole workspace.
  - name: Identities
    description: >-
      Identities represent end users from your system for usage and engagement
      tracking.
  - name: Management keys
    description: >-
      Management keys are workspace-scoped credentials that authenticate
      programmatic access to workspace administration surfaces (API keys,
      budgets). Unlike project-scoped API keys, a management key always operates
      at the workspace level.
  - name: MCP Gateway
    description: >-
      Register upstream MCP servers, discover and sync their tools, and assemble
      gateways that expose a curated tool surface to MCP clients.
  - name: Model Catalog
    description: >-
      Browse the Toqan Router model catalog: every model Toqan Router offers,
      across every provider, with pricing, capabilities and benchmark data. List
      endpoints only return models that are not deprecated. This API is public,
      requires no authentication, and is rate limited to 120 requests per minute
      per IP. Responses carry a 5-minute cache-control max-age.
  - name: Monitors
    description: >-
      Monitors are custom observability dashboards for traces, runtime metrics,
      and logs. Each monitor holds widgets that chart one telemetry query. List
      the metrics, operations, and dimensions available to your workspace with
      `GET /v3/telemetry/capabilities`, or start from a preset with `GET
      /v2/monitors/presets`.
  - name: Notifiers
    description: Notifier destinations used to send delivery and workflow notifications.
  - name: Routing Rules
    description: >-
      Routing Rules conditionally select models and enforce request plugins for
      AI Gateway traffic. Rules are evaluated by ascending priority and may be
      scoped to a project or the whole workspace.
  - name: Threads
    description: Threads group related trace invocations and their aggregate usage
  - name: Smart Routers
    description: >-
      Create and manage workspace Smart Routers. A Smart Router selects a model
      from an eligible pool for each request according to a quality, balanced,
      or cost profile.
  - name: Responses
  - name: Embeddings
  - description: Beta. Run typed classification questions against a classify model.
    name: Classify
  - description: Beta. Run classification decisions with the classify contract.
    name: Decisions
  - description: >-
      Run large offline workloads as JSONL batches and download
      OpenAI-compatible result files.
    name: Batches
paths:
  /v1/responses/compact:
    post:
      tags:
        - Responses
      summary: Compact response
      description: >-
        Compacts a conversation by summarizing older items to free up context
        window space. Returns the next context window: a compaction item
        containing the generated summary, followed by the most recent items
        verbatim.
      operationId: compact-response
      requestBody:
        content:
          application/json:
            examples:
              compact_conversation:
                summary: Compact a conversation to free context space
                value:
                  input:
                    - content: Tell me about machine learning
                      role: user
                      type: message
                    - content: Machine learning is a subset of AI...
                      role: assistant
                      type: message
                  model: openai/gpt-4o
            schema:
              additionalProperties: false
              properties:
                input:
                  anyOf:
                    - description: A simple text string.
                      title: Text
                      type: string
                    - description: An array of input items.
                      items:
                        description: >-
                          An input item. The "type" field determines the item
                          kind.
                        properties:
                          content:
                            anyOf:
                              - title: Text
                                type: string
                              - items:
                                  anyOf:
                                    - description: A text content part.
                                      properties:
                                        cache_control:
                                          properties:
                                            ttl:
                                              default: 5m
                                              description: >-
                                                The time-to-live for the cache control
                                                breakpoint. This may be one of the
                                                following values:


                                                - `5m`: 5 minutes

                                                - `1h`: 1 hour


                                                Defaults to `5m`. Only supported by
                                                Anthropic Claude models.
                                              enum:
                                                - 5m
                                                - 1h
                                              type: string
                                            type:
                                              type: string
                                              enum:
                                                - ephemeral
                                              description: >-
                                                Create a cache control breakpoint at
                                                this content block. Accepts only the
                                                value "ephemeral".
                                          required:
                                            - type
                                          title: Cache control
                                          type: object
                                        prompt_cache_breakpoint:
                                          description: >-
                                            An explicit OpenAI cache boundary for
                                            GPT-5.6 and later. Omitted ttl inherits
                                            prompt_cache_options.ttl.
                                          properties:
                                            mode:
                                              enum:
                                                - explicit
                                              type: string
                                            ttl:
                                              enum:
                                                - 30m
                                                - 12h
                                              type: string
                                          required:
                                            - mode
                                          type: object
                                        text:
                                          type: string
                                          description: The text content.
                                        type:
                                          enum:
                                            - input_text
                                          type: string
                                      required:
                                        - type
                                        - text
                                      title: Text
                                      type: object
                                    - description: An image content part.
                                      properties:
                                        cache_control:
                                          properties:
                                            ttl:
                                              default: 5m
                                              description: >-
                                                The time-to-live for the cache control
                                                breakpoint. This may be one of the
                                                following values:


                                                - `5m`: 5 minutes

                                                - `1h`: 1 hour


                                                Defaults to `5m`. Only supported by
                                                Anthropic Claude models.
                                              enum:
                                                - 5m
                                                - 1h
                                              type: string
                                            type:
                                              type: string
                                              enum:
                                                - ephemeral
                                              description: >-
                                                Create a cache control breakpoint at
                                                this content block. Accepts only the
                                                value "ephemeral".
                                          required:
                                            - type
                                          title: Cache control
                                          type: object
                                        detail:
                                          description: >-
                                            The detail level for image
                                            understanding.
                                          enum:
                                            - auto
                                            - low
                                            - high
                                          type: string
                                        file_id:
                                          description: The ID of a previously uploaded file.
                                          type: string
                                        image_url:
                                          description: The URL of the image.
                                          type: string
                                        prompt_cache_breakpoint:
                                          description: >-
                                            An explicit OpenAI cache boundary for
                                            GPT-5.6 and later. Omitted ttl inherits
                                            prompt_cache_options.ttl.
                                          properties:
                                            mode:
                                              enum:
                                                - explicit
                                              type: string
                                            ttl:
                                              enum:
                                                - 30m
                                                - 12h
                                              type: string
                                          required:
                                            - mode
                                          type: object
                                        type:
                                          enum:
                                            - input_image
                                          type: string
                                      required:
                                        - type
                                      title: Image
                                      type: object
                                    - description: >-
                                        A file content part. Provide file_id,
                                        file_data (base64), or file_url.
                                      properties:
                                        cache_control:
                                          properties:
                                            ttl:
                                              default: 5m
                                              description: >-
                                                The time-to-live for the cache control
                                                breakpoint. This may be one of the
                                                following values:


                                                - `5m`: 5 minutes

                                                - `1h`: 1 hour


                                                Defaults to `5m`. Only supported by
                                                Anthropic Claude models.
                                              enum:
                                                - 5m
                                                - 1h
                                              type: string
                                            type:
                                              type: string
                                              enum:
                                                - ephemeral
                                              description: >-
                                                Create a cache control breakpoint at
                                                this content block. Accepts only the
                                                value "ephemeral".
                                          required:
                                            - type
                                          title: Cache control
                                          type: object
                                        file_data:
                                          description: Base64-encoded file content.
                                          type: string
                                        file_id:
                                          description: The ID of a previously uploaded file.
                                          type: string
                                        file_url:
                                          description: A URL to fetch the file from.
                                          type: string
                                        filename:
                                          description: The name of the file.
                                          type: string
                                        mime_type:
                                          description: >-
                                            The MIME type of the file (e.g.,
                                            application/pdf).
                                          type: string
                                        prompt_cache_breakpoint:
                                          description: >-
                                            An explicit OpenAI cache boundary for
                                            GPT-5.6 and later. Omitted ttl inherits
                                            prompt_cache_options.ttl.
                                          properties:
                                            mode:
                                              enum:
                                                - explicit
                                              type: string
                                            ttl:
                                              enum:
                                                - 30m
                                                - 12h
                                              type: string
                                          required:
                                            - mode
                                          type: object
                                        type:
                                          enum:
                                            - input_file
                                          type: string
                                      required:
                                        - type
                                      title: File
                                      type: object
                                  description: A content part within a message.
                                title: Content parts
                                type: array
                            description: >-
                              The content of the item: a string or an array of
                              content parts.
                          id:
                            description: The ID of the item.
                            type: string
                          role:
                            description: >-
                              The role of the message sender (for message
                              items).
                            enum:
                              - user
                              - assistant
                              - system
                            type: string
                          type:
                            description: The type of item.
                            enum:
                              - message
                              - function_call
                              - function_call_output
                              - item_reference
                              - reasoning
                              - custom_tool_call
                              - custom_tool_call_output
                              - compaction
                            type: string
                        type: object
                      title: Items
                      type: array
                  description: >-
                    Input to compact: a string or an array of input items
                    (messages, files, etc.).
                instructions:
                  description: Custom instructions for the compaction summarization.
                  type: string
                model:
                  description: >-
                    The model to use for compaction in provider/model format
                    (e.g. openai/gpt-4o). Required.
                  type: string
                previous_response_id:
                  description: >-
                    The ID of a stored response whose conversation is compacted;
                    input is appended after it.
                  type: string
                prompt_cache_key:
                  description: Key for prompt caching across requests.
                  type: string
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  created_at:
                    description: Unix timestamp (seconds) when the response was created.
                    format: int64
                    type: integer
                  id:
                    description: The ID of the compaction response.
                    type: string
                  object:
                    description: Always "response.compaction".
                    enum:
                      - response.compaction
                    type: string
                  output:
                    description: >-
                      The next context window: a compaction item summarizing
                      older items, followed by the most recent items verbatim.
                      Pass it as the input of the next request, without
                      previous_response_id.
                    items: {}
                    type:
                      - array
                      - 'null'
                  usage:
                    $ref: '#/components/schemas/PublicUsage'
                    description: Token usage information for the compaction request.
                required:
                  - id
                  - object
                  - output
                  - created_at
                  - usage
                type: object
          description: Compaction completed successfully.
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                properties:
                  error:
                    $ref: '#/components/schemas/APIError'
                required:
                  - error
          description: Model is required or request is invalid.
        '401':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                properties:
                  error:
                    $ref: '#/components/schemas/APIError'
                required:
                  - error
          description: Unauthorized.
        '502':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                properties:
                  error:
                    $ref: '#/components/schemas/APIError'
                required:
                  - error
          description: Failed to compact conversation.
      security:
        - ApiKey: []
      x-code-samples: []
components:
  schemas:
    PublicUsage:
      additionalProperties: false
      properties:
        input_cost:
          description: >-
            Cost (USD) of input tokens. Present when billing was computed for
            this response.
          format: double
          type: number
        input_tokens:
          format: int64
          type: integer
        input_tokens_details:
          $ref: '#/components/schemas/InputTokensDetails'
        output_cost:
          description: >-
            Cost (USD) of output tokens. Present when billing was computed for
            this response.
          format: double
          type: number
        output_tokens:
          format: int64
          type: integer
        output_tokens_details:
          $ref: '#/components/schemas/OutputTokensDetails'
        server_tool_use:
          $ref: '#/components/schemas/ServerToolUseDetails'
          description: >-
            Per-tool breakdown of server tool calls (provider-native and
            router-executed) made during this response.
        speed:
          description: Inference speed reported by Anthropic and used for billing.
          enum:
            - standard
            - fast
          type: string
        total_cost:
          description: >-
            Total cost (USD) of the response. Present when billing was computed
            for this response.
          format: double
          type: number
        total_tokens:
          format: int64
          type: integer
        web_search_requests:
          format: int64
          type: integer
      required:
        - input_tokens
        - output_tokens
        - total_tokens
        - input_tokens_details
        - output_tokens_details
      type: object
    APIError:
      additionalProperties: false
      properties:
        code:
          type:
            - string
            - 'null'
        failures: {}
        message:
          type: string
        param:
          type:
            - string
            - 'null'
        type:
          type: string
      required:
        - message
        - type
        - param
        - code
      type: object
    InputTokensDetails:
      additionalProperties: false
      properties:
        cache_creation_1h_tokens:
          format: int64
          type: integer
        cache_creation_5m_tokens:
          format: int64
          type: integer
        cache_creation_tokens:
          format: int64
          type: integer
        cache_write_tokens:
          format: int64
          type: integer
        cache_write_tokens_details:
          $ref: '#/components/schemas/CacheWriteTokensDetails'
        cached_tokens:
          format: int64
          type: integer
      required:
        - cached_tokens
        - cache_write_tokens
        - cache_creation_tokens
      type: object
    OutputTokensDetails:
      additionalProperties: false
      properties:
        reasoning_tokens:
          format: int64
          type: integer
      required:
        - reasoning_tokens
      type: object
    ServerToolUseDetails:
      additionalProperties: false
      properties:
        advisor_requests:
          format: int64
          type: integer
        code_interpreter_sessions:
          format: int64
          type: integer
        datetime_requests:
          format: int64
          type: integer
        fusion_requests:
          format: int64
          type: integer
        image_generation_calls:
          format: int64
          type: integer
        search_models_requests:
          format: int64
          type: integer
        shell_commands:
          format: int64
          type: integer
        subagent_requests:
          format: int64
          type: integer
        tool_search_requests:
          format: int64
          type: integer
        web_fetch_requests:
          format: int64
          type: integer
        web_search_requests:
          format: int64
          type: integer
      type: object
    CacheWriteTokensDetails:
      additionalProperties: false
      properties:
        ttl_12h_tokens:
          format: int64
          type: integer
        ttl_30m_tokens:
          format: int64
          type: integer
      required:
        - ttl_30m_tokens
        - ttl_12h_tokens
      type: object
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.