{"record":{"id":"6ec175094a1b2c12","repo":"BerriAI/litellm","slug":"api-base-is-required-6ec175","errorCode":null,"errorMessage":"api_base is required","messagePattern":"api_base is required","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/files/transformation.py","lineNumber":82,"sourceCode":"        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        OPTIONAL\n\n        Get the complete url for the request\n\n        Some providers need `model` in `api_base`\n        \"\"\"\n        endpoint: Final = \"upload/v1beta/files\"\n        api_base = self.get_api_base(api_base)\n        if not api_base:\n            raise ValueError(\"api_base is required\")\n\n        # Get API key from multiple sources\n        final_api_key: Final = api_key or litellm_params.get(\"api_key\") or self.get_api_key()\n        if not final_api_key:\n            raise ValueError(\"api_key is required\")\n\n        url: Final = f\"{api_base}/{endpoint}\"\n        return url\n\n    def get_supported_openai_params(self, model: str) -> list[OpenAICreateFileRequestOptionalParams]:\n        return []\n\n    def map_openai_params(\n        self,\n        non_default_params: dict,\n        optional_params: dict,\n        model: str,\n        drop_params: bool,","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gemini/files/transformation.py#L64-L100","documentation":"GeminiFilesConfig.get_complete_url() builds the resumable-upload URL {api_base}/upload/v1beta/files. It resolves api_base via self.get_api_base() (explicit argument, then GEMINI_API_BASE env); if the result is falsy it raises 'api_base is required' before constructing the URL.","triggerScenarios":"File operations invoked with api_base=None/'' and no GEMINI_API_BASE environment variable set (e.g. an environment where the default base was cleared or a custom integration forgot to pass it).","commonSituations":"Custom orchestration code that forwards api_base=None explicitly; GEMINI_API_BASE set to an empty string in .env; a test harness that strips env vars and calls the transformation directly.","solutions":["Export GEMINI_API_BASE=https://generativelanguage.googleapis.com (the standard AI Studio base).","Or pass api_base explicitly when invoking the file operation.","Audit code that forwards api_base for accidental empty-string values, which also fail the check."],"exampleFix":"# before\nos.environ.pop(\"GEMINI_API_BASE\", None)\nlitellm.create_file(model=\"gemini/\", file=f)  # api_base unresolvable\n\n# after\nos.environ[\"GEMINI_API_BASE\"] = \"https://generativelanguage.googleapis.com\"\nlitellm.create_file(model=\"gemini/\", file=f)","handlingStrategy":"validation","validationCode":"import os\n\ndef gemini_files_base() -> str:\n    base = os.getenv(\"GEMINI_API_BASE\") or \"https://generativelanguage.googleapis.com\"\n    if not base:\n        raise RuntimeError(\"GEMINI_API_BASE must be a non-empty URL\")\n    return base","typeGuard":"def is_valid_api_base(base: object) -> bool:\n    return isinstance(base, str) and base.strip() != \"\"","tryCatchPattern":"try:\n    litellm.create_file(model=\"gemini/\", file=f, purpose=\"user_data\")\nexcept ValueError as e:\n    if \"api_base is required\" in str(e):\n        os.environ[\"GEMINI_API_BASE\"] = \"https://generativelanguage.googleapis.com\"\n        litellm.create_file(model=\"gemini/\", file=f, purpose=\"user_data\")\n    else:\n        raise","preventionTips":["Default GEMINI_API_BASE explicitly in your config layer rather than relying on library defaults.","Validate forwarded api_base values (non-empty, https) in the call-construction layer.","Never pass api_base='' — normalize empty strings to None/absent before calling litellm."],"tags":["gemini","files","configuration","api-base"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}