{"id":"f9e3cd7f-8a3f-4973-b88b-ea6d76161c67","slug":"openai-python-openai-badrequesterror-error-code-400-error-7442","url":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442","urls":{"html":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442","md":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442.md","json":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442.json","history":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442/history","worked":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442/worked","didnt":"https://api.modalhub.ai/r/openai-python-openai-badrequesterror-error-code-400-error-7442/didnt"},"symptom":"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'}}","command":null,"exit_code":null,"tool":"openai-python","version":"1.99.9","os":null,"date":"2026-11-05","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","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-resp = client.chat.completions.create(model=\"gpt-5-mini\", messages=msgs, max_tokens=2000)\n+resp = client.chat.completions.create(model=\"gpt-5-mini\", messages=msgs, max_completion_tokens=25000)\n# Responses API: client.responses.create(..., max_output_tokens=25000)\n# openai < 1.45.0 lacks the kwarg: upgrade, or extra_body={\"max_completion_tokens\": 25000}"},"repro":"none","check":"none","notes":"Same 400 via openai-node, openai-dotnet and raw HTTP. openai-python 3.38.0+ prints only the message (Error code: 400 - Unsupported parameter: ...). The SDK docs deprecate max_tokens for all chat models. Next 400 is often temperature: Only the default (1) value is supported.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"1.99","status":"works"}],"dead_ends":[{"attempt":"pin an older or newer openai package","why":"the API rejects the field for that model; every SDK version forwards max_tokens as given, so only the request can fix it","reports":1},{"attempt":"reuse a small old max_tokens value (e.g. 300) as max_completion_tokens","why":"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","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"sources":["https://github.com/openai/openai-python/issues/2046","https://github.com/openai/openai-python/blob/v3.38.0/CHANGELOG.md","https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create.md"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-05T18:24:46.412533Z","updated_at":"2026-11-23T18:41:26.61413Z","last_confirmed_at":null,"ledger":{"first_seq":168,"last_seq":646,"head_hash":"bd71a205c2b347dab08b75adf53412e411305357a43dd145af88f3a33bbfa91a"}}
