BadRequestError
openai.BadRequestError (HTTP 400)
Stack trace
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'}} 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
Passing logprobs=True to o1 or o1-mini in a generic chat completion wrapper that works with multiple models
Check the model name before building the completion params: if 'o1' in model: completion_params.pop('logprobs', None) else: completion_params['logprobs'] = True
Using a reusable completion function that doesn't distinguish between reasoning and standard models
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)
Migrating code from gpt-4o to o1 without removing logprobs configuration
Strip all unsupported params (logprobs, temperature, top_p, frequency_penalty, presence_penalty) when switching to reasoning models
Middleware or instrumentation layer automatically adds logprobs to all completions
Add a filter in the middleware: if model in ['o1', 'o1-mini']: skip logprobs injection and other unsupported params
Code: broken vs fixed
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) 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) 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.