Cohere API error
Cohere API 400 Bad Request (too many tokens): what it means and how to fix it
400 Bad Request (too many tokens)Retry? Not statedLast verified 3 documented fixes1 source
What it means
A 400 Bad Request whose documented example messages begin with "too many tokens", sent when the prompt or requested output exceeds the model's token limits.
Causes
- Prompt exceeds the model's token limit ("too many tokens: total number of tokens in the prompt cannot exceed 4081 - received 4292.")
- max tokens above the model's maximum output ("too many tokens: max tokens must be less than or equal to 4096, the maximum output for this model - received 8192.")
- Inputs exceed the size limit ("too many tokens: size limit exceeded by 11326 tokens.")
How to fix it
- Fix 1.
Try using a shorter prompt, or enabling prompt truncating (as stated in the documented error message).
- Fix 2.
Try using shorter or fewer inputs, or setting prompt truncation to AUTO (as stated in the documented error message).
TOMLprompt_truncation='AUTO' - Fix 3.
Lower max tokens to at most the maximum output for the model.
More Cohere API errors
HTTP 400 at other providers
Compare 400 across providers400 ValidationExceptionRetry? NoAmazon Bedrock400 ServiceQuotaExceededExceptionRetry? YesAmazon Bedrock400 IncompleteSignatureRetry? Not statedAmazon Bedrock400 InvalidActionRetry? Not statedAmazon Bedrock400 NotAuthorizedRetry? Not statedAmazon Bedrock400 RequestExpiredRetry? Not statedAmazon Bedrock400 invalid_request_errorRetry? Not statedAnthropic API400 invalid_request_error (spend limit reached)Retry? Not statedAnthropic API400 Bad RequestRetry? Not statedAzure OpenAI400 content_filterRetry? Not statedAzure OpenAI400 - Invalid FormatRetry? Not statedDeepSeek API400 invalid_requestRetry? NoGemini API
FAQ
What does the Cohere API error "400 Bad Request (too many tokens)" mean?
A 400 Bad Request whose documented example messages begin with "too many tokens", sent when the prompt or requested output exceeds the model's token limits.
How do I fix Cohere API "400 Bad Request (too many tokens)"?
There are 3 documented fixes. Start with the first: Try using a shorter prompt, or enabling prompt truncating (as stated in the documented error message).
Should I retry Cohere API "400 Bad Request (too many tokens)"?
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), 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), OpenAI API (400 invalid_request_error (Invalid service_tier argument); 400 BadRequestError), 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 1 source: Cohere API's official docs and official SDK repositories.
- docs.cohere.comhttps://docs.cohere.com/reference/errors
Newsletter
Know when the APIs change
One email per week. New model releases, API changes, what broke, and how developers are working around it.