{"record":{"id":"3ffa1d68505104ea","repo":"HKUDS/DeepTutor","slug":"cohere-api-key-is-missing-from-the-active-llm-prof","errorCode":null,"errorMessage":"Cohere API key is missing from the active LLM profile.","messagePattern":"Cohere API key is missing from the active LLM profile\\.","errorType":"error_code","errorClass":"LLMAuthenticationError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/llm/cloud_provider.py","lineNumber":826,"sourceCode":"                            text = None\n                        if isinstance(text, str) and text:\n                            yield text\n                except json.JSONDecodeError:\n                    continue\n\n\nasync def _cohere_complete(\n    model: str,\n    prompt: str,\n    system_prompt: str,\n    api_key: str | None,\n    base_url: str | None,\n    max_tokens: int | None = None,\n    temperature: float | None = None,\n) -> str:\n    \"\"\"Cohere API completion.\"\"\"\n    if not api_key:\n        raise LLMAuthenticationError(\n            \"Cohere API key is missing from the active LLM profile.\",\n            provider=\"cohere\",\n        )\n\n    # Build URL using unified utility\n    effective_base = base_url or \"https://api.cohere.ai/v1\"\n    url = f\"{effective_base}/chat\"\n\n    # Build headers using unified utility\n    headers = build_auth_headers(api_key, binding=\"cohere\")\n\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,","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/llm/cloud_provider.py#L808-L844","documentation":"Cohere backend guard in _cohere_complete: Cohere's generate endpoint requires an Authorization bearer token, so a falsy api_key is rejected up front with LLMAuthenticationError(provider='cohere'). No request is made. Note the default base is api.cohere.ai/v1 in this code path.","triggerScenarios":"Calling complete with a cohere binding while the profile's api_key is empty; COHERE_API_KEY unset; key entry blanked during settings migration.","commonSituations":"Adding Cohere as a provider without completing key setup; env var typo (COHERE_API_KEY vs COHEREAI_API_KEY); CI lacking the secret.","solutions":["Set the Cohere API key in the active profile / COHERE_API_KEY env var.","Verify with a quick assert on the resolved key before calling.","If testing without a key, choose the local/Ollama provider instead.","Check the env var spelling against Cohere's current docs."],"exampleFix":"// before\nresp = await complete(prompt=p, binding=\"cohere\", model=\"command-r\", api_key=os.environ.get(\"COHERE_API_TOKEN\"))\n\n# after\nresp = await complete(prompt=p, binding=\"cohere\", model=\"command-r\", api_key=os.environ[\"COHERE_API_KEY\"])","handlingStrategy":"validation","validationCode":"api_key = (os.getenv(\"COHERE_API_KEY\") or \"\").strip()\nif not api_key:\n    raise RuntimeError(\"COHERE_API_KEY is required for the cohere binding\")\nresp = await complete(prompt=p, binding=\"cohere\", model=m, api_key=api_key)","typeGuard":"def has_cohere_key(api_key: str | None) -> bool:\n    return isinstance(api_key, str) and bool(api_key.strip())","tryCatchPattern":"try:\n    resp = await complete(prompt=p, binding=\"cohere\", model=m, api_key=k)\nexcept LLMAuthenticationError as e:\n    if e.provider == \"cohere\":\n        prompt_user_for_key(\"cohere\")\n    raise","preventionTips":["Double-check the env var name against current Cohere docs (COHERE_API_KEY).","Validate provider credentials at startup for every binding you may route to.","Don't ship settings templates with empty cohere key fields."],"tags":["llm","cohere","authentication","api-key","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}