{"record":{"id":"db14a4e4587d18d4","repo":"HKUDS/DeepTutor","slug":"cohere-api-error-error-text","errorCode":null,"errorMessage":"Cohere API error: {error_text}","messagePattern":"Cohere API error: (.+?)","errorType":"http","errorClass":"LLMAPIError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/llm/cloud_provider.py","lineNumber":855,"sourceCode":"\n    max_tokens_value = max_tokens if max_tokens is not None else 4096\n    temperature_value = temperature if temperature is not None else 0.7\n    data: dict[str, object] = {\n        \"model\": model,\n        \"message\": f\"{system_prompt}\\n\\n{prompt}\",\n        \"max_tokens\": max_tokens_value,\n        \"temperature\": temperature_value,\n    }\n\n    timeout = aiohttp.ClientTimeout(total=120)\n    connector = _get_aiohttp_connector()\n    async with aiohttp.ClientSession(\n        timeout=timeout, connector=connector, trust_env=True\n    ) as session:\n        async with session.post(url, headers=headers, json=data) as response:\n            if response.status != 200:\n                error_text = await response.text()\n                raise LLMAPIError(\n                    f\"Cohere API error: {error_text}\",\n                    status_code=response.status,\n                    provider=\"cohere\",\n                )\n\n            result = cast(dict[str, object], await response.json())\n            text = result.get(\"text\")\n            if isinstance(text, str):\n                return text\n            raise LLMAPIError(\n                \"Cohere API error: unexpected response payload\",\n                status_code=response.status,\n                provider=\"cohere\",\n            )\n\n\nasync def fetch_models(\n    base_url: str,","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/llm/cloud_provider.py#L837-L873","documentation":"_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).","triggerScenarios":"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.","commonSituations":"Trial keys with tight rate limits; deprecated model slugs after Cohere renames (command → command-r); custom gateways exposing Cohere under a different prefix.","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."],"exampleFix":"// before\nout = await complete(prompt=p, binding=\"cohere\", model=\"command\", api_key=k)\n\n# after\nout = await complete(prompt=p, binding=\"cohere\", model=\"command-r-plus\", api_key=k)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = await complete(prompt=p, binding=\"cohere\", model=m, api_key=k)\nexcept LLMAPIError as e:\n    if e.status_code == 429:\n        await asyncio.sleep(15); retry()\n    elif e.status_code == 404:\n        update_model_slug()\n    else:\n        raise","preventionTips":["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."],"tags":["llm","cohere","http-error","rate-limit"],"backgroundTag":"llm-api-http-error","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}