# openai.BadRequestError: 使用 response_format 参数时不支持 logprobs

- **ID:** `llm/logprobs-request-fails-on-structured-output`
- **领域:** llm
- **类别:** api_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

OpenAI API 不允许在启用结构化输出（response_format）时请求 logprobs，因为约束解码机制无法生成 token 级别的概率。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| openai-python>=1.30.0 | active | — | — |
| gpt-4o-2024-08-06 | active | — | — |
| gpt-4o-mini-2024-07-18 | active | — | — |

## 解决方案

1. ```
   Remove logprobs from the request entirely when using response_format. Example: `response = client.chat.completions.create(model="gpt-4o", messages=messages, response_format={ "type": "json_object" })` without `logprobs`.
   ```
2. ```
   If logprobs are needed, use a separate API call without response_format and parse JSON manually with error handling.
   ```
3. ```
   Switch to a model or provider that supports both features simultaneously (e.g., some open-source models with guided decoding).
   ```

## 无效尝试

- **** — The error occurs when logprobs is present at all, even if set to false; the API still validates the field presence. (70% 失败率)
- **** — Older API versions may not support structured output at all, or have different bugs; the restriction is intentional and consistent across versions. (90% 失败率)
- **** — This works functionally but defeats the purpose of using structured output for guaranteed JSON. (50% 失败率)
