# openai.BadRequestError: logprobs is not supported when using response_format parameter

- **ID:** `llm/logprobs-request-fails-on-structured-output`
- **Domain:** llm
- **Category:** api_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

OpenAI API does not allow requesting logprobs when structured output (response_format) is enabled, as the constrained decoding mechanism cannot produce token-level probabilities.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| openai-python>=1.30.0 | active | — | — |
| gpt-4o-2024-08-06 | active | — | — |
| gpt-4o-mini-2024-07-18 | active | — | — |

## Workarounds

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`.** (95% success)
   ```
   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.** (80% success)
   ```
   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).** (60% success)
   ```
   Switch to a model or provider that supports both features simultaneously (e.g., some open-source models with guided decoding).
   ```

## Dead Ends

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