HKUDS/DeepTutor · error · LLMAPIError
Cohere API error: {error_text}
Error message
Cohere API error: {error_text} What it means
_cohere_complete POSTs to the Cohere endpoint and on any non-200 status reads the body and raises LLMAPIError with the server's error message, status code, and provider='cohere'. As with the other backends, the embedded text is the provider's own error body, which usually states the reason (invalid token, model not found, rate limit).
Source
Thrown at deeptutor/services/llm/cloud_provider.py:855
max_tokens_value = max_tokens if max_tokens is not None else 4096
temperature_value = temperature if temperature is not None else 0.7
data: dict[str, object] = {
"model": model,
"message": f"{system_prompt}\n\n{prompt}",
"max_tokens": max_tokens_value,
"temperature": temperature_value,
}
timeout = aiohttp.ClientTimeout(total=120)
connector = _get_aiohttp_connector()
async with aiohttp.ClientSession(
timeout=timeout, connector=connector, trust_env=True
) as session:
async with session.post(url, headers=headers, json=data) as response:
if response.status != 200:
error_text = await response.text()
raise LLMAPIError(
f"Cohere API error: {error_text}",
status_code=response.status,
provider="cohere",
)
result = cast(dict[str, object], await response.json())
text = result.get("text")
if isinstance(text, str):
return text
raise LLMAPIError(
"Cohere API error: unexpected response payload",
status_code=response.status,
provider="cohere",
)
async def fetch_models(
base_url: str,View on GitHub (pinned to 3e82f13042)
Solutions
- Read e.status_code and the embedded error_text for the server's reason.
- Fix auth (401), model slug (404), or back off (429).
- Confirm base_url matches the Cohere API version the code targets.
- Upgrade model names to current Cohere slugs if deprecated.
Example fix
// before out = await complete(prompt=p, binding="cohere", model="command", api_key=k) # after out = await complete(prompt=p, binding="cohere", model="command-r-plus", api_key=k)
Defensive patterns
Strategy: try-catch
Try / catch
try:
out = await complete(prompt=p, binding="cohere", model=m, api_key=k)
except LLMAPIError as e:
if e.status_code == 429:
await asyncio.sleep(15); retry()
elif e.status_code == 404:
update_model_slug()
else:
raise Prevention
- Pin model slugs and review them when upgrading Cohere clients.
- Back off on trial-tier rate limits or upgrade the plan.
- Confirm base_url matches the API version the code expects.
When it happens
Trigger: 401/403 invalid Cohere token; 404 wrong model slug or base_url path; 429 trial-key rate limits; 400 from bad parameters on the generate payload.
Common situations: Trial keys with tight rate limits; deprecated model slugs after Cohere renames (command → command-r); custom gateways exposing Cohere under a different prefix.
Related errors
- Anthropic API error: {error_text}
- Anthropic stream error: {error_text}
- OpenAI API error: {error_text}
- OpenAI stream error: {error_text}
- Cohere API key is missing from the active LLM profile.
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/db14a4e4587d18d4.
Report an issue: GitHub.