BerriAI/litellm · error · ValueError
Cohere API key is required. Please set 'COHERE_API_KEY' or '
Error message
Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'
What it means
Error "Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'" thrown in BerriAI/litellm.
Source
Thrown at litellm/llms/cohere/rerank/transformation.py:89
top_n=top_n,
rank_fields=rank_fields,
return_documents=return_documents,
max_chunks_per_doc=max_chunks_per_doc,
)
)
def validate_environment(
self,
headers: dict,
model: str,
api_key: str | None = None,
optional_params: dict | None = None,
) -> dict:
if api_key is None:
api_key = get_secret_str("COHERE_API_KEY") or get_secret_str("CO_API_KEY") or litellm.cohere_key
if api_key is None:
raise ValueError(
"Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'"
)
default_headers: Final = {
"Authorization": f"Bearer {api_key}",
"accept": "application/json",
"content-type": "application/json",
}
# If 'Authorization' is provided in headers, it overrides the default.
if "Authorization" in headers:
default_headers["Authorization"] = headers["Authorization"]
# Merge other headers, overriding any default ones except Authorization
return {**default_headers, **headers}
def transform_rerank_request(
self,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set COHERE_API_KEY (or CO_API_KEY) or pass api_key.
When it happens
Trigger: Thrown at litellm/llms/cohere/rerank/transformation.py:89 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/88cb2e264514d7b5.
Report an issue: GitHub.