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

# Compact response context

> Return a complete context window for the next Responses request.

`POST /v1/responses/compact`

Send a compaction-capable `model` and complete context as `input`; `instructions` is a common optional field. This is a non-streaming request. Setting `stream: true` does not enable SSE. Confirm provider extensions separately for each channel.

The response contains `object: response.compaction`, `output`, and optional `usage`. Output includes compaction items and may retain messages or other items. Replay the complete output and do not use the ordinary Responses `status` field to detect success. Preserve encrypted content unchanged.

The gateway DTO accepts `previous_response_id`, but upstream state resolution determines support. The example supplies history explicitly and does not promise cross-channel ID continuation, general resource retrieval, or automatic compaction.

[Compaction and continuation example](/en/guides/compaction.md) · [Create a response](/en/api-reference/responses.md)

[阅读中文](/zh/api-reference/responses-compact.md)


## OpenAPI

````yaml openapi/relay.json POST /v1/responses/compact
openapi: 3.0.3
info:
  title: API — Core inference API
  version: 0.5.0
  description: >-
    面向接入的精选规范，不是全部管理或供应商接口。 / Curated integration specification, not the entire
    management or provider API.
  license:
    name: AGPL-3.0-or-later
servers:
  - url: https://gateway.example.com
    description: >-
      Example only; replace with your gateway origin and optional path prefix,
      without /v1.
security:
  - BearerAuth: []
paths:
  /v1/responses/compact:
    post:
      summary: 压缩上下文 / Compact context
      description: 需验证模型、渠道及部署支持 / Verify model, channel, and deployment support
      operationId: compactResponses
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompactionRequest'
      responses:
        '200':
          description: 成功结构仍需检查业务字段 / Check business fields even on HTTP success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompactionResult'
              example:
                id: cmp_example
                object: response.compaction
                created_at: 1700000000
                output:
                  - type: message
                    role: user
                    content:
                      - type: input_text
                        text: Plan a two-day visit.
                  - type: compaction
                    id: cmp_item
                    encrypted_content: OPAQUE_STATE_FROM_UPSTREAM
        '400':
          description: 请求参数错误 / Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: 身份校验失败 / Authentication failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: 访问被拒绝 / Access denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: 接口或资源不存在 / Endpoint or resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: 请求被限流或受配额限制 / Rate or quota restriction
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: 网关或上游错误 / Gateway or upstream error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: 服务暂不可用 / Service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        default:
          description: 其他网关或上游错误；格式可能不同 / Other gateway or upstream error; shape may vary
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CompactionRequest:
      type: object
      required:
        - model
      properties:
        model:
          type: string
          description: >-
            模型列表返回的原始 ID；需要支持当前接口 / Exact ID from the model list; must support
            this endpoint
          example: YOUR_MODEL_ID
        input:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
          description: >-
            文本或输入项数组；内容块和工具项需模型支持 / Text or input items; content blocks and tool
            items require model support
        instructions:
          type: string
          description: >-
            本次压缩指令；续聊时再次明确发送所需指令 / Instructions for this compaction; explicitly
            send needed instructions again when continuing
        previous_response_id:
          type: string
          description: >-
            DTO 接收但状态解析依赖上游；建议显式历史 / Accepted by the DTO but state resolution
            requires upstream support; prefer explicit history
    CompactionResult:
      type: object
      required:
        - object
        - output
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - response.compaction
        created_at:
          type: number
        output:
          type: array
          items:
            type: object
            additionalProperties: true
            properties:
              type:
                type: string
              encrypted_content:
                type: string
                description: >-
                  压缩项中的不透明密文；保持原样 / Opaque ciphertext in compaction items;
                  preserve unchanged
          description: >-
            下一轮完整上下文窗口，保留所有条目及顺序 / Complete next context window; retain all
            items and their order
        usage:
          type: object
          properties:
            input_tokens:
              type: integer
            output_tokens:
              type: integer
            total_tokens:
              type: integer
          nullable: true
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
              nullable: true
            code:
              nullable: true
              description: 错误标识；类型随上游变化 / Error identifier; type varies by upstream
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 模型调用 API Key，不是控制台登录凭据 / Model API key, not console login credentials

````

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