# OpenAI Responses API 端到端测试用例与 Mock 设计

本文档针对 `POST /responses` 接口（OpenAI Responses API），设计端到端测试用例及对应的 Mock 返回值结构。

---

## 一、测试场景总览

| 分类 | 测试用例 | 优先级 |
|------|----------|--------|
| 基础响应 | 1. 单轮纯文本响应 | P0 |
| 基础响应 | 2. 多轮对话（previous_response_id） | P0 |
| 基础响应 | 3. instructions 系统指令 | P1 |
| 基础响应 | 4. 含图片输入 | P1 |
| 基础响应 | 5. 含文件输入 | P1 |
| 参数控制 | 6. max_output_tokens 截断 | P1 |
| 参数控制 | 7. temperature + top_p | P1 |
| 参数控制 | 8. text.format 为 json_object | P1 |
| 参数控制 | 9. text.format 为 json_schema | P1 |
| 参数控制 | 10. text.verbosity 控制 | P2 |
| 推理模型 | 11. reasoning.effort 参数 | P1 |
| 推理模型 | 12. reasoning.generate_summary | P2 |
| 工具调用 | 13. function 工具调用 | P0 |
| 工具调用 | 14. 并行工具调用（parallel_tool_calls） | P1 |
| 工具调用 | 15. tool_choice 为 "required" | P2 |
| 工具调用 | 16. tool_choice 指定具体工具 | P2 |
| 工具调用 | 17. web_search 工具调用 | P1 |
| 工具调用 | 18. file_search 工具调用 | P2 |
| 工具调用 | 19. code_interpreter 工具调用 | P2 |
| 工具调用 | 20. image_generation 工具调用 | P2 |
| 工具调用 | 21. computer_use 工具调用 | P2 |
| 工具调用 | 22. mcp 工具调用 | P2 |
| 工具调用 | 23. custom 工具调用 | P2 |
| 流式响应 | 24. 流式文本响应（SSE） | P0 |
| 流式响应 | 25. 流式 + stream_options | P1 |
| 流式响应 | 26. 流式工具调用 | P1 |
| 上下文管理 | 27. truncation 为 "auto" | P2 |
| 上下文管理 | 28. context_management 配置 | P2 |
| 缓存 | 29. prompt_cache_key + prompt_cache_retention | P2 |
| 存储 | 30. store + background 模式 | P2 |
| 其他 | 31. metadata 元数据 | P2 |
| 其他 | 32. max_tool_calls 限制 | P2 |
| 其他 | 33. service_tier 选择 | P2 |
| 错误处理 | 34. 无效 model 返回错误 | P1 |
| 错误处理 | 35. 缺少 input 返回错误 | P1 |
| 错误处理 | 36. 内容安全策略拒绝 | P2 |
| Token 计数 | 37. /responses/input_tokens 端点 | P1 |

---

## 二、测试用例详情

### 用例 1：单轮纯文本响应

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好，请介绍一下你自己"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test001",
  "object": "response",
  "created_at": 1700000001,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test001",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是由 OpenAI 开发的 AI 助手 GPT-4。我可以帮你回答问题、写作、编程、数学推理、数据分析等多种任务。我的知识截止到 2025 年 1 月。请问有什么我可以帮你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 12,
    "output_tokens": 68,
    "total_tokens": 80
  },
  "metadata": {}
}
```

**验证点：**
- `status` == `"completed"`
- `output[0].type` == `"message"`
- `output[0].content[0].type` == `"output_text"`
- `usage` 字段完整

---

### 用例 2：多轮对话（previous_response_id）

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "能举个例子吗？",
  "previous_response_id": "resp_01test001"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test002",
  "object": "response",
  "created_at": 1700000002,
  "model": "gpt-4o",
  "status": "completed",
  "previous_response_id": "resp_01test001",
  "output": [
    {
      "id": "msg_01test002",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "当然。例如定义一个 `Reader` interface：\n\n```go\ntype Reader interface {\n    Read(p []byte) (n int, err error)\n}\n```\n\n`os.File` 和 `bytes.Buffer` 都实现了 `Read` 方法，所以它们都自动实现了 `Reader` interface。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 120,
    "output_tokens": 85,
    "total_tokens": 205
  },
  "metadata": {}
}
```

---

### 用例 3：instructions 系统指令

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "什么是递归？",
  "instructions": "你是一个专业的编程助手，请用简洁的语言回答问题。"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test003",
  "object": "response",
  "created_at": 1700000003,
  "model": "gpt-4o",
  "status": "completed",
  "instructions": "你是一个专业的编程助手，请用简洁的语言回答问题。",
  "output": [
    {
      "id": "msg_01test003",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "递归是一种函数调用自身来解决问题的方法。它包含两个关键部分：\n\n1. **基准情况**：直接返回结果的终止条件\n2. **递归情况**：将问题分解为更小的子问题，调用自身解决\n\n例如计算阶乘：`n! = n × (n-1)!`，基准情况是 `0! = 1`。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 45,
    "output_tokens": 72,
    "total_tokens": 117
  },
  "metadata": {}
}
```

---

### 用例 4：含图片输入

**请求：**
```json
{
  "model": "gpt-4o",
  "input": [
    {
      "type": "input_text",
      "text": "这张图片里有什么？"
    },
    {
      "type": "input_image",
      "image_url": "https://example.com/images/cat.jpg",
      "detail": "auto"
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test004",
  "object": "response",
  "created_at": 1700000004,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test004",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "图片中有一只橘色的猫，它正躺在沙发上晒太阳。猫的毛色是橘白相间的，眼睛是绿色的，看起来非常放松。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 1280,
    "output_tokens": 45,
    "total_tokens": 1325
  },
  "metadata": {}
}
```

---

### 用例 5：含文件输入

**请求：**
```json
{
  "model": "gpt-4o",
  "input": [
    {
      "type": "input_text",
      "text": "请总结这份文档的主要内容"
    },
    {
      "type": "input_file",
      "file_id": "file-abc123",
      "filename": "report.pdf"
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test005",
  "object": "response",
  "created_at": 1700000005,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test005",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "这份文档是一份关于机器学习入门的指南，主要内容包括：\n\n1. **机器学习概述**：定义、历史发展、主要应用领域\n2. **监督学习**：分类、回归、常见算法\n3. **无监督学习**：聚类、降维\n4. **深度学习基础**：神经网络结构、反向传播\n5. **实践建议**：数据预处理、模型评估、超参数调优\n\n文档适合初学者阅读，提供了清晰的理论框架和实用的学习路径建议。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 5200,
    "output_tokens": 145,
    "total_tokens": 5345
  },
  "metadata": {}
}
```

---

### 用例 6：max_output_tokens 截断

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "请详细介绍一下人工智能的发展历史",
  "max_output_tokens": 30
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test006",
  "object": "response",
  "created_at": 1700000006,
  "model": "gpt-4o",
  "status": "completed",
  "max_output_tokens": 30,
  "output": [
    {
      "id": "msg_01test006",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "人工智能起源于1950年代，图灵提出了机器能否思考的问题。1956年达特茅斯会议正式确立了AI领域。此后经历了多次起伏..."
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "incomplete_details": {
    "reason": "max_output_tokens",
    "details": null
  },
  "usage": {
    "input_tokens": 20,
    "output_tokens": 30,
    "total_tokens": 50
  },
  "metadata": {}
}
```

**验证点：**
- `incomplete_details.reason` == `"max_output_tokens"`
- `output_tokens` == 30（等于 max_output_tokens）

---

### 用例 7：temperature + top_p

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "写一首关于春天的短诗",
  "temperature": 0.9,
  "top_p": 0.95
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test007",
  "object": "response",
  "created_at": 1700000007,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test007",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "春风拂面花自开，\n柳絮飞舞满园香。\n燕归巢中呢喃语，\n万物复苏迎朝阳。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 0.9,
  "tool_choice": "auto",
  "top_p": 0.95,
  "usage": {
    "input_tokens": 18,
    "output_tokens": 32,
    "total_tokens": 50
  },
  "metadata": {}
}
```

---

### 用例 8：text.format 为 json_object

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "提取以下信息的姓名和年龄：张三，今年25岁，是一名工程师",
  "text": {
    "format": {
      "type": "json_object"
    }
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test008",
  "object": "response",
  "created_at": 1700000008,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test008",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "{\"name\": \"张三\", \"age\": 25, \"occupation\": \"工程师\"}"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "text": {
    "format": {
      "type": "json_object"
    }
  },
  "usage": {
    "input_tokens": 35,
    "output_tokens": 25,
    "total_tokens": 60
  },
  "metadata": {}
}
```

**验证点：**
- `content[0].text` 是合法的 JSON 字符串

---

### 用例 9：text.format 为 json_schema

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "创建一个用户信息记录，姓名李四，年龄30岁",
  "text": {
    "format": {
      "type": "json_schema",
      "name": "user_info",
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"},
          "email": {"type": "string"}
        },
        "required": ["name", "age"],
        "additionalProperties": false,
        "strict": true
      }
    }
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test009",
  "object": "response",
  "created_at": 1700000009,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test009",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "{\"name\": \"李四\", \"age\": 30}"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "text": {
    "format": {
      "type": "json_schema",
      "name": "user_info",
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"},
          "email": {"type": "string"}
        },
        "required": ["name", "age"],
        "additionalProperties": false,
        "strict": true
      }
    }
  },
  "usage": {
    "input_tokens": 120,
    "output_tokens": 18,
    "total_tokens": 138
  },
  "metadata": {}
}
```

**验证点：**
- 输出严格符合 JSON schema 定义

---

### 用例 10：text.verbosity 控制

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "解释什么是 API",
  "text": {
    "verbosity": "low"
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test010",
  "object": "response",
  "created_at": 1700000010,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test010",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "API（应用程序接口）是软件系统之间交互的接口，定义了不同程序之间通信的规则和方法。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "text": {
    "verbosity": "low"
  },
  "usage": {
    "input_tokens": 15,
    "output_tokens": 28,
    "total_tokens": 43
  },
  "metadata": {}
}
```

---

### 用例 11：reasoning.effort 参数

**请求：**
```json
{
  "model": "o3",
  "input": "一个房间里有3个灯泡，房间外有3个开关，每个开关控制一个灯泡。你只能进房间一次，如何确定哪个开关控制哪个灯泡？",
  "reasoning": {
    "effort": "high"
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test011",
  "object": "response",
  "created_at": 1700000011,
  "model": "o3",
  "status": "completed",
  "reasoning": {
    "effort": "high",
    "summary": "这是一个经典的逻辑推理问题，需要利用灯泡的两种可观察状态（亮/灭）和一种物理属性（温度）来区分三个开关。"
  },
  "output": [
    {
      "id": "reason_01test011",
      "type": "reasoning",
      "content": "我需要找到一种方法，通过一次观察来区分三个开关。关键是灯泡有两种可观察的状态：亮或灭。但如果只用亮灭，我只能区分一个开关（开的那个）。我需要找到另一种可观察的属性...温度！灯泡开着会发热。"
    },
    {
      "id": "msg_01test011",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "解决方案如下：\n\n1. **打开第一个开关**，等待几分钟\n2. **关闭第一个开关**，**打开第二个开关**\n3. **立即进入房间**\n\n此时观察：\n- **亮着的灯** → 由第二个开关控制\n- **摸起来发热的灯** → 由第一个开关控制\n- **既不亮也不热的灯** → 由第三个开关控制"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 95,
    "output_tokens": 280,
    "total_tokens": 375,
    "output_tokens_details": {
      "reasoning_tokens": 180
    }
  },
  "metadata": {}
}
```

**验证点：**
- `reasoning` 配置被正确返回
- `output` 包含 `reasoning` 类型的输出项
- `reasoning_tokens` 在 usage 详情中体现

---

### 用例 12：reasoning.generate_summary

**请求：**
```json
{
  "model": "o3",
  "input": "请帮我分析这个算法问题",
  "reasoning": {
    "effort": "medium",
    "generate_summary": "concise"
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test012",
  "object": "response",
  "created_at": 1700000012,
  "model": "o3",
  "status": "completed",
  "reasoning": {
    "effort": "medium",
    "generate_summary": "concise",
    "summary": "用户没有提供具体的算法问题，需要请用户提供更多细节。"
  },
  "output": [
    {
      "id": "reason_01test012",
      "type": "reasoning",
      "content": "用户提到了一个算法问题，但没有具体说明是什么问题。我需要请用户提供更多细节。"
    },
    {
      "id": "msg_01test012",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "我很乐意帮你分析算法问题！不过你没有具体说明是什么问题。请详细描述一下：\n\n1. 问题的具体要求是什么？\n2. 输入输出的格式是怎样的？\n3. 有没有什么约束条件？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 35,
    "output_tokens": 95,
    "total_tokens": 130,
    "output_tokens_details": {
      "reasoning_tokens": 45
    }
  },
  "metadata": {}
}
```

---

### 用例 13：function 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "北京天气怎么样？",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取指定城市的天气信息",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string",
            "description": "城市名称"
          }
        },
        "required": ["city"]
      },
      "strict": true
    }
  ],
  "tool_choice": "auto"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test013",
  "object": "response",
  "created_at": 1700000013,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "fc_01test013",
      "type": "function_call",
      "call_id": "call_01test013",
      "name": "get_weather",
      "arguments": "{\"city\": \"北京\"}",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取指定城市的天气信息",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        },
        "required": ["city"]
      },
      "strict": true
    }
  ],
  "usage": {
    "input_tokens": 180,
    "output_tokens": 42,
    "total_tokens": 222
  },
  "metadata": {}
}
```

**验证点：**
- `output[0].type` == `"function_call"`
- `arguments` 是合法的 JSON 字符串

---

### 用例 14：并行工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "帮我查一下北京、上海、广州三个城市的天气",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取指定城市的天气信息",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        },
        "required": ["city"]
      }
    }
  ],
  "parallel_tool_calls": true
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test014",
  "object": "response",
  "created_at": 1700000014,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "fc_01test014a",
      "type": "function_call",
      "call_id": "call_01test014a",
      "name": "get_weather",
      "arguments": "{\"city\": \"北京\"}",
      "status": "completed"
    },
    {
      "id": "fc_01test014b",
      "type": "function_call",
      "call_id": "call_01test014b",
      "name": "get_weather",
      "arguments": "{\"city\": \"上海\"}",
      "status": "completed"
    },
    {
      "id": "fc_01test014c",
      "type": "function_call",
      "call_id": "call_01test014c",
      "name": "get_weather",
      "arguments": "{\"city\": \"广州\"}",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取指定城市的天气信息",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        },
        "required": ["city"]
      }
    }
  ],
  "usage": {
    "input_tokens": 200,
    "output_tokens": 120,
    "total_tokens": 320
  },
  "metadata": {}
}
```

**验证点：**
- `output` 包含 3 个 `function_call` 类型的项

---

### 用例 15：tool_choice 为 "required"

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "随便聊聊",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        }
      }
    }
  ],
  "tool_choice": "required"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test015",
  "object": "response",
  "created_at": 1700000015,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "fc_01test015",
      "type": "function_call",
      "call_id": "call_01test015",
      "name": "get_weather",
      "arguments": "{}",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "required",
  "top_p": 1.0,
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        }
      }
    }
  ],
  "usage": {
    "input_tokens": 150,
    "output_tokens": 35,
    "total_tokens": 185
  },
  "metadata": {}
}
```

**验证点：**
- 模型必须调用工具

---

### 用例 16：tool_choice 指定具体工具

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "查天气",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
    },
    {
      "type": "function",
      "name": "get_news",
      "description": "获取新闻",
      "parameters": {"type": "object", "properties": {"topic": {"type": "string"}}}
    }
  ],
  "tool_choice": {
    "type": "function",
    "name": "get_weather"
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test016",
  "object": "response",
  "created_at": 1700000016,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "fc_01test016",
      "type": "function_call",
      "call_id": "call_01test016",
      "name": "get_weather",
      "arguments": "{}",
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": {
    "type": "function",
    "name": "get_weather"
  },
  "top_p": 1.0,
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
    },
    {
      "type": "function",
      "name": "get_news",
      "description": "获取新闻",
      "parameters": {"type": "object", "properties": {"topic": {"type": "string"}}}
    }
  ],
  "usage": {
    "input_tokens": 200,
    "output_tokens": 35,
    "total_tokens": 235
  },
  "metadata": {}
}
```

**验证点：**
- 强制使用了 `get_weather` 而非 `get_news`

---

### 用例 17：web_search 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "今天有什么重要的科技新闻？",
  "tools": [
    {
      "type": "web_search",
      "search_context_size": "medium",
      "user_location": {
        "type": "approximate",
        "country": "CN"
      }
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test017",
  "object": "response",
  "created_at": 1700000017,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "ws_01test017",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search",
        "query": "今天 重要 科技新闻",
        "sources": [
          {
            "url": "https://example.com/tech-news-1",
            "title": "OpenAI 发布 GPT-5 更新",
            "summary": "新的 GPT-5 版本在多个基准测试中表现优异..."
          }
        ]
      }
    },
    {
      "id": "msg_01test017",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "根据最新的搜索结果，今天有以下重要科技新闻：\n\n1. **AI 领域**：OpenAI 发布了 GPT-5 的更新版本，在代码生成和数学推理能力上有显著提升...\n\n2. **智能手机**：Apple 宣布了新一代 iPhone 的发布日期...\n\n3. **电动汽车**：Tesla 公布了最新的自动驾驶技术进展..."
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "web_search",
      "search_context_size": "medium",
      "user_location": {
        "type": "approximate",
        "country": "CN"
      }
    }
  ],
  "usage": {
    "input_tokens": 180,
    "output_tokens": 150,
    "total_tokens": 330
  },
  "metadata": {}
}
```

---

### 用例 18：file_search 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "在我的文档中搜索关于机器学习的内容",
  "tools": [
    {
      "type": "file_search",
      "vector_store_ids": ["vs_abc123"],
      "max_num_results": 10,
      "ranking_options": {
        "ranker": "auto",
        "score_threshold": 0.5
      }
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test018",
  "object": "response",
  "created_at": 1700000018,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "fs_01test018",
      "type": "file_search_call",
      "status": "completed",
      "queries": ["机器学习"],
      "results": [
        {
          "file_id": "file-xyz789",
          "filename": "ml_intro.pdf",
          "score": 0.92,
          "attributes": {},
          "text": "机器学习是人工智能的一个分支，它使计算机能够从数据中学习..."
        }
      ]
    },
    {
      "id": "msg_01test018",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "我在你的文档中找到了关于机器学习的内容：\n\n**机器学习**是人工智能的一个分支，它使计算机能够从数据中学习模式和规律，而无需显式编程。主要类型包括监督学习、无监督学习和强化学习。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "file_search",
      "vector_store_ids": ["vs_abc123"],
      "max_num_results": 10,
      "ranking_options": {
        "ranker": "auto",
        "score_threshold": 0.5
      }
    }
  ],
  "usage": {
    "input_tokens": 250,
    "output_tokens": 85,
    "total_tokens": 335
  },
  "metadata": {}
}
```

---

### 用例 19：code_interpreter 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "帮我计算斐波那契数列的前10项",
  "tools": [
    {
      "type": "code_interpreter",
      "container": "auto"
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test019",
  "object": "response",
  "created_at": 1700000019,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "ci_01test019",
      "type": "code_interpreter_call",
      "status": "completed",
      "code": "fib = [0, 1]\nfor i in range(2, 10):\n    fib.append(fib[i-1] + fib[i-2])\nprint(fib)",
      "container_id": "container_abc123",
      "outputs": [
        {
          "type": "logs",
          "logs": "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]"
        }
      ]
    },
    {
      "id": "msg_01test019",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "斐波那契数列的前10项是：\n\n**0, 1, 1, 2, 3, 5, 8, 13, 21, 34**\n\n这个数列的规律是：每一项等于前两项之和。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "code_interpreter",
      "container": "auto"
    }
  ],
  "usage": {
    "input_tokens": 120,
    "output_tokens": 95,
    "total_tokens": 215
  },
  "metadata": {}
}
```

---

### 用例 20：image_generation 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "生成一张日出的图片",
  "tools": [
    {
      "type": "image_generation",
      "action": "generate",
      "size": "1024x1024",
      "quality": "high",
      "output_format": "png"
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test020",
  "object": "response",
  "created_at": 1700000020,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "ig_01test020",
      "type": "image_generation_call",
      "status": "completed",
      "result": {
        "type": "image",
        "image": {
          "file_id": "file-img001",
          "url": "https://example.com/generated/sunrise.png"
        }
      }
    },
    {
      "id": "msg_01test020",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "我已经为你生成了一张日出的图片！画面中金色的阳光洒满天际，云彩被染成了橙红色，远处的山峦在晨光中若隐若现。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "image_generation",
      "action": "generate",
      "size": "1024x1024",
      "quality": "high",
      "output_format": "png"
    }
  ],
  "usage": {
    "input_tokens": 85,
    "output_tokens": 75,
    "total_tokens": 160
  },
  "metadata": {}
}
```

---

### 用例 21：computer_use 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "帮我打开浏览器访问 Google",
  "tools": [
    {
      "type": "computer_use_preview",
      "environment": "browser",
      "display_width": 1024,
      "display_height": 768
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test021",
  "object": "response",
  "created_at": 1700000021,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "cc_01test021",
      "type": "computer_call",
      "status": "in_progress",
      "call_id": "call_01test021",
      "pending_safety_checks": [],
      "action": {
        "type": "click",
        "x": 400,
        "y": 50,
        "button": "left"
      }
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "computer_use_preview",
      "environment": "browser",
      "display_width": 1024,
      "display_height": 768
    }
  ],
  "usage": {
    "input_tokens": 150,
    "output_tokens": 55,
    "total_tokens": 205
  },
  "metadata": {}
}
```

---

### 用例 22：mcp 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "查看我的日历安排",
  "tools": [
    {
      "type": "mcp",
      "server_label": "google_calendar",
      "connector_id": "conn_calendar_001",
      "allowed_tools": ["list_events", "create_event"]
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test022",
  "object": "response",
  "created_at": 1700000022,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "mcp_list_022",
      "type": "mcp_list_tools",
      "status": "completed",
      "tools": [
        {
          "name": "list_events",
          "description": "列出指定时间范围内的日历事件"
        },
        {
          "name": "create_event",
          "description": "创建新的日历事件"
        }
      ]
    },
    {
      "id": "mcp_call_022",
      "type": "mcp_call",
      "status": "completed",
      "call_id": "call_mcp_022",
      "name": "list_events",
      "arguments": "{\"date\": \"today\"}",
      "result": {
        "content": [
          {
            "type": "text",
            "text": "今天你有3个日程安排：\n1. 10:00 - 团队站会\n2. 14:00 - 产品评审会议\n3. 16:00 - 1:1 与经理"
          }
        ]
      }
    },
    {
      "id": "msg_01test022",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你今天有以下日程安排：\n\n1. **10:00** - 团队站会\n2. **14:00** - 产品评审会议\n3. **16:00** - 1:1 与经理"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "mcp",
      "server_label": "google_calendar",
      "connector_id": "conn_calendar_001",
      "allowed_tools": ["list_events", "create_event"]
    }
  ],
  "usage": {
    "input_tokens": 200,
    "output_tokens": 120,
    "total_tokens": 320
  },
  "metadata": {}
}
```

---

### 用例 23：custom 工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "执行自定义操作",
  "tools": [
    {
      "type": "custom",
      "name": "my_custom_tool",
      "description": "一个自定义工具",
      "format": {
        "type": "text"
      }
    }
  ]
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test023",
  "object": "response",
  "created_at": 1700000023,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "ct_01test023",
      "type": "custom_tool_call",
      "status": "completed",
      "call_id": "call_custom_023",
      "name": "my_custom_tool",
      "input": "{\"action\": \"test\"}"
    },
    {
      "id": "msg_01test023",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "自定义操作已成功执行。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "custom",
      "name": "my_custom_tool",
      "description": "一个自定义工具",
      "format": {
        "type": "text"
      }
    }
  ],
  "usage": {
    "input_tokens": 80,
    "output_tokens": 45,
    "total_tokens": 125
  },
  "metadata": {}
}
```

---

### 用例 24：流式文本响应（SSE）

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "stream": true
}
```

**期望 Mock 响应（200 OK, Content-Type: text/event-stream）：**

```
event: response.created
data: {"id":"resp_01stream001","object":"response","created_at":1700000024,"model":"gpt-4o","status":"in_progress","output":[],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","top_p":1.0,"metadata":{}}

event: response.in_progress
data: {"id":"resp_01stream001","object":"response","created_at":1700000024,"model":"gpt-4o","status":"in_progress"}

event: response.output_item.added
data: {"id":"resp_01stream001","object":"response","item":{"id":"msg_01stream001","type":"message","role":"assistant","content":[]}}

event: response.content_part.added
data: {"id":"resp_01stream001","object":"response","part":{"type":"output_text","text":""},"item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"你","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"好","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"！","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"我","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"是","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"AI","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"助手","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"，","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"很高兴","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"为你","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"服务","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_text.delta
data: {"id":"resp_01stream001","object":"response","delta":"。","item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.content_part.done
data: {"id":"resp_01stream001","object":"response","part":{"type":"output_text","text":"你好！我是AI助手，很高兴为你服务。"},"item_id":"msg_01stream001","output_index":0,"content_index":0}

event: response.output_item.done
data: {"id":"resp_01stream001","object":"response","item":{"id":"msg_01stream001","type":"message","role":"assistant","content":[{"type":"output_text","text":"你好！我是AI助手，很高兴为你服务。"}],"status":"completed"}}

event: response.completed
data: {"id":"resp_01stream001","object":"response","created_at":1700000024,"model":"gpt-4o","status":"completed","output":[{"id":"msg_01stream001","type":"message","role":"assistant","content":[{"type":"output_text","text":"你好！我是AI助手，很高兴为你服务。"}],"status":"completed"}],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","top_p":1.0,"usage":{"input_tokens":10,"output_tokens":18,"total_tokens":28},"metadata":{}}
```

**验证点：**
- 事件顺序：response.created → response.in_progress → response.output_item.added → response.content_part.added → response.output_text.delta* → response.content_part.done → response.output_item.done → response.completed
- `response.created` 包含初始 response 对象
- `response.output_text.delta` 包含增量文本
- `response.completed` 包含完整的 response 对象和 usage

---

### 用例 25：流式 + stream_options

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "stream": true,
  "stream_options": {
    "include_obfuscation": true
  }
}
```

**期望 Mock 响应（200 OK, Content-Type: text/event-stream）：**

与用例 24 类似，但部分 event 数据中包含随机填充字符以混淆 payload 大小：

```
event: response.created
data: {"id":"resp_01stream002","object":"response","created_at":1700000025,"model":"gpt-4o","status":"in_progress","output":[],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","top_p":1.0,"metadata":{}}

... (正常 events) ...

event: response.output_text.delta
data: {"id":"resp_01stream002","object":"response","delta":"你","item_id":"msg_01stream002","output_index":0,"content_index":0,"_obfuscation":"xxxxxxxxxxxxxxxxxxxx"}

... (更多 events 带有 _obfuscation 字段) ...

event: response.completed
data: {"id":"resp_01stream002","object":"response","created_at":1700000025,"model":"gpt-4o","status":"completed","output":[...],"usage":{"input_tokens":10,"output_tokens":18,"total_tokens":28},"metadata":{}}
```

**验证点：**
- 部分 event 包含 `_obfuscation` 字段
- 不影响正常数据解析

---

### 用例 26：流式工具调用

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "北京天气怎么样？",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        },
        "required": ["city"]
      }
    }
  ],
  "stream": true
}
```

**期望 Mock 响应（200 OK, Content-Type: text/event-stream）：**

```
event: response.created
data: {"id":"resp_01stream003","object":"response","created_at":1700000026,"model":"gpt-4o","status":"in_progress","output":[],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","top_p":1.0,"tools":[{"type":"function","name":"get_weather","description":"获取天气","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"metadata":{}}

event: response.in_progress
data: {"id":"resp_01stream003","object":"response","created_at":1700000026,"model":"gpt-4o","status":"in_progress"}

event: response.output_item.added
data: {"id":"resp_01stream003","object":"response","item":{"id":"fc_01stream003","type":"function_call","call_id":"call_01stream003","name":"get_weather","arguments":""}}

event: response.function_call_arguments.delta
data: {"id":"resp_01stream003","object":"response","delta":"{\"","item_id":"fc_01stream003","output_index":0}

event: response.function_call_arguments.delta
data: {"id":"resp_01stream003","object":"response","delta":"city","item_id":"fc_01stream003","output_index":0}

event: response.function_call_arguments.delta
data: {"id":"resp_01stream003","object":"response","delta":"\":\"","item_id":"fc_01stream003","output_index":0}

event: response.function_call_arguments.delta
data: {"id":"resp_01stream003","object":"response","delta":"北京","item_id":"fc_01stream003","output_index":0}

event: response.function_call_arguments.delta
data: {"id":"resp_01stream003","object":"response","delta":"\"}","item_id":"fc_01stream003","output_index":0}

event: response.output_item.done
data: {"id":"resp_01stream003","object":"response","item":{"id":"fc_01stream003","type":"function_call","call_id":"call_01stream003","name":"get_weather","arguments":"{\"city\": \"北京\"}","status":"completed"}}

event: response.completed
data: {"id":"resp_01stream003","object":"response","created_at":1700000026,"model":"gpt-4o","status":"completed","output":[{"id":"fc_01stream003","type":"function_call","call_id":"call_01stream003","name":"get_weather","arguments":"{\"city\": \"北京\"}","status":"completed"}],"parallel_tool_calls":true,"temperature":1.0,"tool_choice":"auto","top_p":1.0,"usage":{"input_tokens":180,"output_tokens":42,"total_tokens":222},"metadata":{}}
```

**验证点：**
- `response.function_call_arguments.delta` 逐步拼接完整的 JSON 参数
- 最终 `response.completed` 包含完整的 function_call

---

### 用例 27：truncation 为 "auto"

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "truncation": "auto"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test027",
  "object": "response",
  "created_at": 1700000027,
  "model": "gpt-4o",
  "status": "completed",
  "truncation": "auto",
  "output": [
    {
      "id": "msg_01test027",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是由 OpenAI 开发的 AI 助手。请问有什么我可以帮你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 22,
    "total_tokens": 32
  },
  "metadata": {}
}
```

**验证点：**
- 当输入超过上下文窗口时，自动从开头截断

---

### 用例 28：context_management 配置

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "context_management": {
    "compaction": {
      "enabled": true,
      "trigger_tokens": 100000
    }
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test028",
  "object": "response",
  "created_at": 1700000028,
  "model": "gpt-4o",
  "status": "completed",
  "context_management": {
    "compaction": {
      "enabled": true,
      "trigger_tokens": 100000
    }
  },
  "output": [
    {
      "id": "msg_01test028",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是由 OpenAI 开发的 AI 助手。请问有什么我可以帮你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 22,
    "total_tokens": 32
  },
  "metadata": {}
}
```

---

### 用例 29：prompt_cache_key + prompt_cache_retention

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "instructions": "你是一个专业的编程助手。",
  "prompt_cache_key": "programming_assistant_v1",
  "prompt_cache_retention": "24h"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test029",
  "object": "response",
  "created_at": 1700000029,
  "model": "gpt-4o",
  "status": "completed",
  "prompt_cache_key": "programming_assistant_v1",
  "prompt_cache_retention": "24h",
  "output": [
    {
      "id": "msg_01test029",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是你的专业编程助手，擅长解答各种编程问题、代码审查、架构设计等。请问有什么我可以帮助你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 25,
    "output_tokens": 35,
    "total_tokens": 60,
    "input_tokens_details": {
      "cached_tokens": 15
    }
  },
  "metadata": {}
}
```

**验证点：**
- `input_tokens_details.cached_tokens` 反映缓存命中的 token 数

---

### 用例 30：store + background 模式

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "请分析这份数据",
  "store": true,
  "background": true
}
```

**期望 Mock 响应（202 Accepted）：**
```json
{
  "id": "resp_01test030",
  "object": "response",
  "created_at": 1700000030,
  "model": "gpt-4o",
  "status": "queued",
  "background": true,
  "store": true,
  "output": [],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "metadata": {}
}
```

**验证点：**
- `status` == `"queued"`
- `background` == `true`
- `store` == `true`

---

### 用例 31：metadata 元数据

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "metadata": {
    "user_id": "user_12345",
    "session_id": "session_abc",
    "request_source": "web_app"
  }
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test031",
  "object": "response",
  "created_at": 1700000031,
  "model": "gpt-4o",
  "status": "completed",
  "metadata": {
    "user_id": "user_12345",
    "session_id": "session_abc",
    "request_source": "web_app"
  },
  "output": [
    {
      "id": "msg_01test031",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是由 OpenAI 开发的 AI 助手。请问有什么我可以帮你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 22,
    "total_tokens": 32
  }
}
```

---

### 用例 32：max_tool_calls 限制

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "帮我查北京、上海、广州、深圳四个城市的天气",
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
    }
  ],
  "max_tool_calls": 2
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test032",
  "object": "response",
  "created_at": 1700000032,
  "model": "gpt-4o",
  "status": "incomplete",
  "max_tool_calls": 2,
  "output": [
    {
      "id": "fc_01test032a",
      "type": "function_call",
      "call_id": "call_01test032a",
      "name": "get_weather",
      "arguments": "{\"city\": \"北京\"}",
      "status": "completed"
    },
    {
      "id": "fc_01test032b",
      "type": "function_call",
      "call_id": "call_01test032b",
      "name": "get_weather",
      "arguments": "{\"city\": \"上海\"}",
      "status": "completed"
    }
  ],
  "incomplete_details": {
    "reason": "max_tool_calls",
    "details": null
  },
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "tools": [
    {
      "type": "function",
      "name": "get_weather",
      "description": "获取天气",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
    }
  ],
  "usage": {
    "input_tokens": 200,
    "output_tokens": 80,
    "total_tokens": 280
  },
  "metadata": {}
}
```

**验证点：**
- `status` == `"incomplete"`
- `incomplete_details.reason` == `"max_tool_calls"`
- 只调用了 2 个工具（受 max_tool_calls 限制）

---

### 用例 33：service_tier 选择

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好",
  "service_tier": "flex"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test033",
  "object": "response",
  "created_at": 1700000033,
  "model": "gpt-4o",
  "status": "completed",
  "service_tier": "flex",
  "output": [
    {
      "id": "msg_01test033",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "你好！我是由 OpenAI 开发的 AI 助手。请问有什么我可以帮你的？"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 22,
    "total_tokens": 32
  },
  "metadata": {}
}
```

---

### 用例 34：无效 model 返回错误

**请求：**
```json
{
  "model": "nonexistent-model-xyz",
  "input": "你好"
}
```

**期望 Mock 响应（400 Bad Request）：**
```json
{
  "error": {
    "code": "invalid_model",
    "message": "The model 'nonexistent-model-xyz' does not exist or you do not have access to it."
  }
}
```

---

### 用例 35：缺少 input 返回错误

**请求：**
```json
{
  "model": "gpt-4o"
}
```

**期望 Mock 响应（400 Bad Request）：**
```json
{
  "error": {
    "code": "missing_input",
    "message": "The 'input' parameter is required. Please provide text, image, or file input."
  }
}
```

---

### 用例 36：内容安全策略拒绝

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "生成违法内容..."
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "id": "resp_01test036",
  "object": "response",
  "created_at": 1700000036,
  "model": "gpt-4o",
  "status": "completed",
  "output": [
    {
      "id": "msg_01test036",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "refusal",
          "refusal": "抱歉，我无法生成此类内容。我的设计原则是提供有益、安全和负责任的帮助。如果你有其他问题或需要帮助的地方，我很乐意为你服务。"
        }
      ],
      "status": "completed"
    }
  ],
  "parallel_tool_calls": true,
  "temperature": 1.0,
  "tool_choice": "auto",
  "top_p": 1.0,
  "usage": {
    "input_tokens": 15,
    "output_tokens": 42,
    "total_tokens": 57
  },
  "metadata": {}
}
```

**验证点：**
- `content[0].type` == `"refusal"`

---

### 用例 37：/responses/input_tokens 端点

**请求：**
```json
{
  "model": "gpt-4o",
  "input": "你好，请介绍一下你自己"
}
```

**期望 Mock 响应（200 OK）：**
```json
{
  "object": "response.input_tokens",
  "input_tokens": 12
}
```

**验证点：**
- `object` == `"response.input_tokens"`
- `input_tokens` 返回正确的 token 数量
- 不生成实际响应内容

---

## 三、Mock 响应通用结构规范

### 非流式响应通用结构

```json
{
  "id": "resp_<unique_id>",
  "object": "response",
  "created_at": <unix_timestamp>,
  "model": "<model_name>",
  "status": "completed" | "failed" | "in_progress" | "cancelled" | "queued" | "incomplete",
  "output": [
    {
      "id": "<item_id>",
      "type": "message" | "function_call" | "function_call_output" | "web_search_call" | "file_search_call" | "code_interpreter_call" | "image_generation_call" | "computer_call" | "computer_call_output" | "reasoning" | "compaction" | "mcp_list_tools" | "mcp_call" | "mcp_approval_request" | "mcp_approval_response" | "custom_tool_call" | "custom_tool_call_output" | "tool_search_call" | "tool_search_output" | "shell_call" | "shell_call_output" | "local_shell_call" | "local_shell_call_output" | "apply_patch_call" | "apply_patch_call_output" | "item_reference",
      "role": "assistant" | "user",
      "content": [
        {
          "type": "output_text" | "refusal",
          "text": "<text>" | null,
          "refusal": "<refusal_text>" | null,
          "annotations": []
        }
      ],
      "status": "completed" | "in_progress" | "incomplete",
      "call_id": "<call_id>" | null,
      "name": "<tool_name>" | null,
      "arguments": "<json_string>" | null,
      "code": "<code_string>" | null,
      "container_id": "<container_id>" | null,
      "outputs": [] | null,
      "result": {} | null,
      "action": {} | null,
      "pending_safety_checks": [],
      "content_text": "<thinking_content>" | null
    }
  ],
  "parallel_tool_calls": true | false,
  "temperature": <number>,
  "tool_choice": "auto" | "none" | "required" | {},
  "tools": [],
  "top_p": <number>,
  "usage": {
    "input_tokens": <int>,
    "output_tokens": <int>,
    "total_tokens": <int>,
    "input_tokens_details": {
      "cached_tokens": <int> | null
    },
    "output_tokens_details": {
      "reasoning_tokens": <int> | null
    }
  },
  "metadata": {},
  "instructions": "<system_instructions>" | null,
  "max_output_tokens": <int> | null,
  "max_tool_calls": <int> | null,
  "previous_response_id": "<response_id>" | null,
  "reasoning": {"effort": "<effort>", "summary": "<summary>"} | null,
  "text": {"format": {}, "verbosity": "low" | "medium" | "high"} | null,
  "truncation": "auto" | "disabled" | null,
  "incomplete_details": {"reason": "max_output_tokens" | "max_tool_calls" | "content_filter", "details": null} | null,
  "service_tier": "auto" | "default" | "flex" | "scale" | "priority" | null,
  "prompt_cache_key": "<key>" | null,
  "prompt_cache_retention": "in-memory" | "24h" | null,
  "store": true | false | null,
  "background": true | false | null,
  "completed_at": <unix_timestamp> | null,
  "error": {"code": "<error_code>", "message": "<error_message>"} | null
}
```

### 流式 Event 类型

| Event Type | Key Fields |
|------------|-----------|
| `response.created` | 完整的 response 对象（空 output） |
| `response.in_progress` | response 对象，status = "in_progress" |
| `response.output_item.added` | 新增 output item |
| `response.content_part.added` | 新增 content part |
| `response.output_text.delta` | 文本增量 |
| `response.output_text.done` | 文本完成 |
| `response.function_call_arguments.delta` | 函数参数增量 |
| `response.content_part.done` | content part 完成 |
| `response.output_item.done` | output item 完成 |
| `response.completed` | 完整的 response 对象（含 usage） |

### 错误响应通用结构

```json
{
  "error": {
    "code": "invalid_model" | "missing_input" | "server_error" | "rate_limit_exceeded" | "invalid_prompt" | "invalid_image" | "vector_store_timeout" | "content_filter_violation",
    "message": "<human_readable_message>"
  }
}
```

### 请求必需参数

| 参数 | 类型 | 说明 |
|------|------|------|
| `model` | string | 模型标识符（如 `gpt-4o`、`o3`） |
| `input` | string/array | 文本、图片或文件输入 |

### 请求可选参数

| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `instructions` | string | - | 系统/开发者消息 |
| `max_output_tokens` | number | - | 最大生成 token 数 |
| `max_tool_calls` | number | - | 最大工具调用次数 |
| `temperature` | number | 1.0 | 采样温度（0-2） |
| `top_p` | number | 1.0 | 核采样阈值 |
| `tools` | array | - | 工具定义数组 |
| `tool_choice` | string/object | auto | 工具选择策略 |
| `parallel_tool_calls` | boolean | true | 允许并行工具调用 |
| `reasoning` | object | - | 推理配置（effort, summary） |
| `text` | object | - | 文本配置（format, verbosity） |
| `stream` | boolean | false | 是否流式 |
| `previous_response_id` | string | - | 上一轮响应 ID |
| `store` | boolean | false | 存储响应 |
| `background` | boolean | false | 后台执行 |
| `metadata` | object | - | 元数据（最多 16 个键值对） |
| `truncation` | string | - | 截断策略（auto/disabled） |
| `prompt_cache_key` | string | - | 提示词缓存键 |
| `prompt_cache_retention` | string | - | 缓存保留策略 |
| `service_tier` | string | - | 服务层级 |

### Status 枚举

| 值 | 含义 |
|----|------|
| `completed` | 响应已完成 |
| `in_progress` | 响应生成中 |
| `failed` | 响应生成失败 |
| `incomplete` | 响应不完整（达到限制） |
| `cancelled` | 响应已取消 |
| `queued` | 响应已入队（后台模式） |
