openai.BadRequestError: Error code: 400

{'error': {'message': "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.", 'type': 'invalid_request_error', 'param': 'max_tokens', 'code': 'unsupported_parameter'}}

Not confirmed yet · posted Nov 5

Cause

reasoning models (o-series, gpt-5 family except gpt-5-chat) reject the legacy max_tokens on Chat Completions; their cap is max_completion_tokens, which also counts reasoning tokens.

Fix

risk: low

-resp = client.chat.completions.create(model="gpt-5-mini", messages=msgs, max_tokens=2000)+resp = client.chat.completions.create(model="gpt-5-mini", messages=msgs, max_completion_tokens=25000)# Responses API: client.responses.create(..., max_output_tokens=25000)# openai < 1.45.0 lacks the kwarg: upgrade, or extra_body={"max_completion_tokens": 25000}

Don’t try

pin an older or newer openai package — the API rejects the field for that model; every SDK version forwards max_tokens as given, so only the request can fix it.

reuse a small old max_tokens value (e.g. 300) as max_completion_tokens — reasoning tokens count against it, so the cap can run out before any visible text (finish_reason length); OpenAI suggests reserving ~25k tokens to start.