High severity HTTP 400 intermediate · Fix: 2-5 min

BadRequestError

openai.BadRequestError (HTTP 400)

What this error means
OpenAI's o1 and o1-mini reasoning models do not support the logprobs parameter: passing it triggers a 400 BadRequestError because reasoning models don't expose token probability information.

Stack trace

traceback
openai.BadRequestError: Error code: 400 - {'error': {'message': "'logprobs' is not supported for this model. 'logprobs' can only be set to 'true' for 'gpt-4o', 'gpt-4o-mini', 'gpt-4.1', and 'gpt-4.1-mini'.", 'type': 'invalid_request_error', 'param': 'logprobs', 'code': 'invalid_parameter_value'}}
QUICK FIX
Remove logprobs parameter entirely from o1/o1-mini calls; if you need probabilities, use gpt-4o-mini instead or restructure to call o1 for reasoning and gpt-4o for probability analysis.

Why it happens

Reasoning models like o1 and o1-mini use an internal 'thinking' process that's opaque to users: the API doesn't expose token-level probabilities because they're generated during hidden reasoning phases, not in the final response. When you pass logprobs=True or logprobs=None to these models, the API immediately rejects the request with a 400 error. This constraint only applies to o-series reasoning models; standard models like gpt-4o and gpt-4o-mini still support logprobs.

Detection

Before calling client.chat.completions.create(), check if your model is o1 or o1-mini and conditionally remove the logprobs parameter. Log the request payload to catch this early in development.

Causes & fixes

1

Passing logprobs=True to o1 or o1-mini in a generic chat completion wrapper that works with multiple models

✓ Fix

Check the model name before building the completion params: if 'o1' in model: completion_params.pop('logprobs', None) else: completion_params['logprobs'] = True

2

Using a reusable completion function that doesn't distinguish between reasoning and standard models

✓ Fix

Create a separate code path for reasoning models: use one param set for o1/o1-mini (no logprobs, no temperature) and another for gpt-4o variants (logprobs allowed)

3

Migrating code from gpt-4o to o1 without removing logprobs configuration

✓ Fix

Strip all unsupported params (logprobs, temperature, top_p, frequency_penalty, presence_penalty) when switching to reasoning models

4

Middleware or instrumentation layer automatically adds logprobs to all completions

✓ Fix

Add a filter in the middleware: if model in ['o1', 'o1-mini']: skip logprobs injection and other unsupported params

Code: broken vs fixed

Broken - triggers the error
python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))

# This breaks for o1 models because logprobs is not supported
response = client.chat.completions.create(
    model='o1',
    messages=[{'role': 'user', 'content': 'Solve x^2 + 2x + 1 = 0'}],
    logprobs=True,  # ❌ NOT SUPPORTED FOR o1 — causes 400 BadRequestError
    top_logprobs=2
)

print(response.choices[0].message.content)
Fixed - works correctly
python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))

# Fixed: check model type and conditionally set logprobs
model = 'o1'
messages = [{'role': 'user', 'content': 'Solve x^2 + 2x + 1 = 0'}]

completion_params = {
    'model': model,
    'messages': messages,
}

# ✅ Only add logprobs for models that support it
if model not in ['o1', 'o1-mini']:
    completion_params['logprobs'] = True
    completion_params['top_logprobs'] = 2

response = client.chat.completions.create(**completion_params)

print(response.choices[0].message.content)
Added conditional logic to check if the model is o1 or o1-mini before adding logprobs — reasoning models reject this parameter, so we remove it for that class of models while preserving it for standard models.

Workaround

If you have a generic completion wrapper that's difficult to refactor, catch the BadRequestError and retry without logprobs: wrap the call in try/except, catch BadRequestError, check if 'logprobs' in str(error), and re-run with logprobs removed from params.

Prevention

Build model-aware parameter builders: create a function that takes (model, base_params) and returns filtered params based on model class. Reasoning models (o1, o1-mini) exclude logprobs/temperature/top_p/frequency_penalty/presence_penalty; standard models (gpt-4o, gpt-4o-mini, gpt-4.1) include all. Use this builder for all completion calls to enforce consistency.

Python 3.9+ · openai >=1.0.0 · tested on 1.40+
Verified 2026-04 · o1, o1-mini, gpt-4o, gpt-4o-mini
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.