{"record":{"id":"88cb2e264514d7b5","repo":"BerriAI/litellm","slug":"cohere-api-key-is-required-please-set-cohere-api","errorCode":null,"errorMessage":"Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'","messagePattern":"Cohere API key is required\\. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm\\.cohere_key'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/cohere/rerank/transformation.py","lineNumber":89,"sourceCode":"                top_n=top_n,\n                rank_fields=rank_fields,\n                return_documents=return_documents,\n                max_chunks_per_doc=max_chunks_per_doc,\n            )\n        )\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        optional_params: dict | None = None,\n    ) -> dict:\n        if api_key is None:\n            api_key = get_secret_str(\"COHERE_API_KEY\") or get_secret_str(\"CO_API_KEY\") or litellm.cohere_key\n\n        if api_key is None:\n            raise ValueError(\n                \"Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'\"\n            )\n\n        default_headers: Final = {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"accept\": \"application/json\",\n            \"content-type\": \"application/json\",\n        }\n\n        # If 'Authorization' is provided in headers, it overrides the default.\n        if \"Authorization\" in headers:\n            default_headers[\"Authorization\"] = headers[\"Authorization\"]\n\n        # Merge other headers, overriding any default ones except Authorization\n        return {**default_headers, **headers}\n\n    def transform_rerank_request(\n        self,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/cohere/rerank/transformation.py#L71-L107","documentation":"Error \"Cohere API key is required. Please set 'COHERE_API_KEY' or 'CO_API_KEY' or 'litellm.cohere_key'\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/cohere/rerank/transformation.py:89 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set COHERE_API_KEY (or CO_API_KEY) or pass api_key."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}