{"record":{"id":"74c1873d2cf0e673","repo":"BerriAI/litellm","slug":"api-base-is-required-74c187","errorCode":null,"errorMessage":"api_base is required","messagePattern":"api_base is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/cohere/chat/v2_transformation.py","lineNumber":285,"sourceCode":"            sync_stream=sync_stream,\n            json_mode=json_mode,\n        )\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        api_key: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict,\n        stream: bool | None = None,\n    ) -> str:\n        \"\"\"\n        Get the complete URL for Cohere v2 chat completion.\n        The api_base should already include the full path.\n        \"\"\"\n        if api_base is None:\n            raise ValueError(\"api_base is required\")\n        return api_base\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        return CohereError(status_code=status_code, message=error_message)\n\n    def _translate_citations_to_openai_annotations(self, citations: list[dict]) -> list[ChatCompletionAnnotation]:\n        \"\"\"\n        Transform Cohere citations to OpenAI annotations format.\n\n        Creates separate annotations for each source in a citation, allowing multiple\n        annotations with the same start/end index if they reference different sources.\n\n        Args:\n            citations: List of Cohere citation objects with format:\n                {\n                    \"start\": int,\n                    \"end\": int,\n                    \"text\": str,","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/cohere/chat/v2_transformation.py#L267-L303","documentation":"ValueError raised by the Cohere v2 adapter's get_complete_url: unlike most providers, this handler does not append a path and does not synthesize a default — it requires api_base to already be set, and raises if it is None. LiteLLM normally injects the default https://api.cohere.com/v2 upstream of this call, so hitting this error means the defaulting layer was bypassed or explicitly overridden with None.","triggerScenarios":"Calling a cohere_v2 model (or Cohere v2 path) with api_base=None passed explicitly through router/completion kwargs, or through an integration that forwards its own api_base value without a default.","commonSituations":"Litellm Router configs where api_base is conditionally set and forwards None; wrapper code doing completion(..., api_base=os.environ.get('COHERE_API_BASE')) when the var is unset; custom providers routing cohere_v2 through generic paths that skip default URL resolution.","solutions":["Pass api_base=\"https://api.cohere.com/v2\" (or your proxy's equivalent full path) in the completion call","If the var may be unset, fall back: api_base=os.environ.get('COHERE_API_BASE') or 'https://api.cohere.com/v2'","In Router model_list entries, ensure the cohere_v2 model has api_base set or remove the key so litellm applies its default","Upgrade litellm — default URL handling for cohere_v2 has changed across versions"],"exampleFix":"# before\nlitellm.completion(\n    model=\"cohere_v2/command-r-plus-08-2024\",\n    messages=messages,\n    api_base=os.environ.get(\"COHERE_API_BASE\"),  # None when unset\n)\n\n# after\nlitellm.completion(\n    model=\"cohere_v2/command-r-plus-08-2024\",\n    messages=messages,\n    api_base=os.environ.get(\"COHERE_API_BASE\") or \"https://api.cohere.com/v2\",\n)","handlingStrategy":"validation","validationCode":"import os\n\napi_base = os.environ.get(\"COHERE_API_BASE\") or \"https://api.cohere.com/v2\"\n\nlitellm.completion(\n    model=\"cohere_v2/command-r-plus-08-2024\",\n    messages=messages,\n    api_base=api_base,\n)","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=\"cohere_v2/command-r\", messages=messages, api_base=maybe_base)\nexcept ValueError as e:\n    if \"api_base is required\" in str(e):\n        litellm.completion(\n            model=\"cohere_v2/command-r\", messages=messages, api_base=\"https://api.cohere.com/v2\"\n        )\n    else:\n        raise","preventionTips":["Never forward os.environ.get('COHERE_API_BASE') without an 'or' default","In Router model_list, either set api_base for cohere_v2 deployments or omit the key entirely","Centralize provider URL defaults in one config module so None never reaches the adapter"],"tags":["cohere","api-base","config","url-resolution"],"backgroundTag":"missing-base-url","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}