Skip to main content
Watch: I Built an AI App Without Leaving Databricks

OpenAI API error

OpenAI API 400 BadRequestError: what it means and how to fix it

Error message
400 BadRequestError

Retry? Not statedLast verified 2 documented fixes2 sources

What it means

Python library error for 400 responses (formerly InvalidRequestError): the request was malformed or missing required parameters, such as a token or an input.

Causes

  • A typo, a formatting error, or a logic error in your code
  • Invalid encoding, format, or size of request data

How to fix it

  1. Fix 1.

    Read the error message, which should say which parameter was invalid or missing and what was expected.

  2. Fix 2.

    Check the API reference for the method you are calling and send valid, complete parameters; check encoding (UTF-8), JSON format, and size.

More OpenAI API errors

All 23 OpenAI API errors

HTTP 400 at other providers

Compare 400 across providers

FAQ

What does the OpenAI API error "400 BadRequestError" mean?

Python library error for 400 responses (formerly InvalidRequestError): the request was malformed or missing required parameters, such as a token or an input.

How do I fix OpenAI API "400 BadRequestError"?

There are 2 documented fixes. Start with the first: Read the error message, which should say which parameter was invalid or missing and what was expected.

Should I retry OpenAI API "400 BadRequestError"?

Not stated. The official docs do not say whether this error is retryable.

Which other AI APIs return HTTP 400?

Per their official error docs: Amazon Bedrock (400 ValidationException; 400 ServiceQuotaExceededException; 400 IncompleteSignature; 400 InvalidAction; 400 NotAuthorized; 400 RequestExpired), Anthropic API (400 invalid_request_error; 400 invalid_request_error (spend limit reached)), Azure OpenAI (400 Bad Request; 400 content_filter), Cohere API (400 Bad Request; 400 Bad Request (too many tokens)), DeepSeek API (400 - Invalid Format), Gemini API (400 invalid_request; 400 failed_precondition; 400 parameter_unknown; 400 INVALID_ARGUMENT; 400 FAILED_PRECONDITION), Groq API (400 Bad Request), Mistral API (400 Bad request), OpenRouter (400 invalid_request; 400 invalid_prompt; 400 context_length_exceeded; 400 max_tokens_exceeded; 400 token_limit_exceeded; 400 string_too_long; 400 invalid_image; 400 image_too_large; 400 image_too_small; 400 unsupported_image_format; 400 image_download_failed), Vertex AI (400 INVALID_ARGUMENT / FAILED_PRECONDITION), xAI API (400 Bad Request).

Sources

Last verified against 2 sources: OpenAI API's official docs and official SDK repositories.

Newsletter

Know when the APIs change

One email per week. New model releases, API changes, what broke, and how developers are working around it.