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

# Codex 上下文压缩接口

> Responses API 上下文压缩端点，适用于 Codex CLI 长会话

使用 Codex 上下文压缩接口压缩长会话上下文，降低后续请求的上下文体积。该端点主要供 Codex CLI 或兼容 Responses API 的客户端使用。

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://gogogotoken.ai/v1/responses/compact \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5.2-codex",
      "input": [
        {
          "role": "user",
          "content": "Summarize the current coding session for continuation."
        }
      ]
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "resp_abc123",
    "object": "response",
    "model": "gpt-5.2-codex",
    "status": "completed",
    "output": [
      {
        "type": "message",
        "role": "assistant",
        "content": [
          {
            "type": "output_text",
            "text": "The session focused on refactoring API documentation pages..."
          }
        ]
      }
    ],
    "usage": {
      "input_tokens": 1800,
      "output_tokens": 260,
      "total_tokens": 2060
    }
  }
  ```
</ResponseExample>

## 接口说明

该接口用于把较长的 Codex 会话内容压缩成更短的延续上下文。Base URL 只填写 `https://gogogotoken.ai`，实际请求路径为 `/v1/responses/compact`。

<Info>
  普通 Codex 对话请使用 `POST /v1/responses`。只有需要压缩上下文时才调用该端点。
</Info>

## 请求头

<ParamField header="Authorization" type="string" required>
  API Key 鉴权信息，格式为 `Bearer YOUR_API_KEY`。
</ParamField>

<ParamField header="Content-Type" type="string" required>
  固定为 `application/json`。
</ParamField>

## 请求体

<ParamField body="model" type="string" required default="gpt-5.2-codex">
  Codex 模型 ID，例如 `gpt-5.2-codex`。完整列表以 `GET /v1/models` 与分组配置为准。
</ParamField>

<ParamField body="input" type="string" required default="Summarize the current coding session for continuation.">
  需要压缩的上下文内容。可传字符串，也可传 Responses API 兼容的结构化输入。
</ParamField>

<ParamField body="prompt_cache_key" type="string">
  可选的缓存键。网关可基于该字段保持同一会话上游路由稳定。
</ParamField>

## 响应体

<ResponseField name="id" type="string">
  本次压缩响应 ID。
</ResponseField>

<ResponseField name="status" type="string">
  响应状态，例如 `completed`、`failed`。
</ResponseField>

<ResponseField name="output" type="object[]">
  压缩后的上下文内容。文本结果通常位于 `output[].content[].text`。
</ResponseField>

<ResponseField name="usage" type="object">
  token 用量统计。
</ResponseField>

## 错误码

| 状态码   | 含义               | 处理建议                            |
| ----- | ---------------- | ------------------------------- |
| `401` | API Key 无效或未传    | 检查请求头与令牌状态                      |
| `403` | 无权限访问目标 Codex 模型 | 检查 API Key 分组权限                 |
| `404` | 路径配置错误           | 确认请求路径为 `/v1/responses/compact` |
| `429` | 触发限速             | 降低请求频率或调整套餐                     |
| `5xx` | 上游或网关异常          | 稍后重试，并查看控制台日志                   |
