OpenAI API 400 (invalid_request_error / context_length_exceeded)
Is there an outage right now?
OpenAI API official status is operational. If this error persists, it is likely an implementation or environment issue on your side.
View OpenAI API status →What this error means
400 means the request is invalid. A very common case is context_length_exceeded—your messages plus max_tokens exceed the model's context window. Other causes are malformed JSON, a missing or invalid parameter, or an unsupported model.
Common causes
- •context_length_exceeded: input plus max_tokens exceed the model context window
- •Malformed JSON or wrong Content-Type
- •Missing or invalid required parameter (model, messages)
- •Unsupported model name, or a parameter not supported by that model
- •Invalid value (e.g. temperature out of range, bad tool schema)
How to fix
- 1.Shorten the input or lower max_tokens to fit the context window
- 2.Switch to a larger-context model if you genuinely need more tokens
- 3.Read the error message—it names the parameter and the limit
- 4.Validate JSON and required fields; set Content-Type: application/json
- 5.Check the parameter is supported by the chosen model
When waiting helps (and when it won't)
Request-side error—waiting will not help. Trim tokens or fix the parameter named in the error.
Alternatives when OpenAI API is down
Related errors
FAQ
What is 400 invalid_request_error?
400 means the request is invalid. A very common case is context_length_exceeded—your messages plus max_tokens exceed the model's context window. Other causes are malformed JSON, a missing or invalid parameter, or an unsupported model.
How do I fix 400 invalid_request_error?
Shorten the input or lower max_tokens to fit the context window / Switch to a larger-context model if you genuinely need more tokens / Read the error message—it names the parameter and the limit / Validate JSON and required fields; set Content-Type: application/json / Check the parameter is supported by the chosen model