{"record":{"id":"d622fb18ffa3a86f","repo":"BerriAI/litellm","slug":"vertex-ai-project-id-is-required-please-set-vert","errorCode":null,"errorMessage":"Vertex AI project ID is required. Please set 'VERTEXAI_PROJECT', 'litellm.vertex_project', or pass 'vertex_project' parameter","messagePattern":"Vertex AI project ID is required\\. Please set 'VERTEXAI_PROJECT', 'litellm\\.vertex_project', or pass 'vertex_project' parameter","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/rerank/transformation.py","lineNumber":65,"sourceCode":"        params: Final = optional_params or {}\n\n        # Get credentials to extract project ID if needed\n        vertex_credentials: Final = self.safe_get_vertex_ai_credentials(params.copy())\n        vertex_project = self.safe_get_vertex_ai_project(params.copy())\n\n        # Use _ensure_access_token to extract project_id from credentials\n        # This is the same method used in vertex embeddings\n        _, vertex_project = self._ensure_access_token(\n            credentials=vertex_credentials,\n            project_id=vertex_project,\n            custom_llm_provider=\"vertex_ai\",\n        )\n\n        # Fallback to environment or litellm config\n        project_id: Final = vertex_project or get_secret_str(\"VERTEXAI_PROJECT\") or litellm.vertex_project\n\n        if not project_id:\n            raise ValueError(\n                \"Vertex AI project ID is required. Please set 'VERTEXAI_PROJECT', 'litellm.vertex_project', or pass 'vertex_project' parameter\"\n            )\n\n        return f\"https://discoveryengine.googleapis.com/v1/projects/{project_id}/locations/global/rankingConfigs/default_ranking_config:rank\"\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        \"\"\"\n        Validate and set up authentication for Vertex AI Discovery Engine API\n        \"\"\"\n        # Get credentials and project info from optional_params (which contains vertex_credentials, etc.)\n        litellm_params: Final = optional_params.copy() if optional_params else {}\n        vertex_credentials: Final = self.safe_get_vertex_ai_credentials(litellm_params)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/rerank/transformation.py#L47-L83","documentation":"ValueError raised while constructing the Vertex AI Discovery Engine rerank URL when no project ID can be resolved. The handler first extracts the project from the supplied credentials (via _ensure_access_token), then falls back to the VERTEXAI_PROJECT environment variable and finally litellm.vertex_project; if all are empty the rankingConfigs URL cannot be built.","triggerScenarios":"Calling litellm.rerank with a vertex_ai/... model when the credentials carry no project, VERTEXAI_PROJECT is unset, and litellm.vertex_project was never assigned.","commonSituations":"Using access-token-only auth with no project attached; env var missing in the deployed runtime; multi-project service accounts where the token is project-less.","solutions":["Pass vertex_project='my-project' in the rerank call / router deployment","Or export VERTEXAI_PROJECT=my-project","Or set litellm.vertex_project='my-project' globally","If using service-account credentials, use one whose JSON includes project_id so it is auto-extracted"],"exampleFix":"# before\nlitellm.rerank(model='vertex_ai/semantic-ranker', query='q', documents=docs)\n\n# after\nlitellm.rerank(\n    model='vertex_ai/semantic-ranker',\n    query='q',\n    documents=docs,\n    vertex_project='my-project',\n)","handlingStrategy":"validation","validationCode":"import os\nimport litellm\n\nproject = os.environ.get('VERTEXAI_PROJECT') or litellm.vertex_project\nassert project, 'vertex_ai rerank needs vertex_project / VERTEXAI_PROJECT / litellm.vertex_project'","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.rerank(model=model, query=q, documents=docs)\nexcept ValueError as e:\n    if 'project ID is required' in str(e):\n        raise SystemExit('Set VERTEXAI_PROJECT or pass vertex_project')\n    raise","preventionTips":["Set VERTEXAI_PROJECT or litellm.vertex_project once at app startup","Prefer service-account JSON that includes project_id so it is auto-extracted","Assert project resolution in a pre-flight check for vertex_ai routes"],"tags":["vertex-ai","rerank","configuration","gcp-project"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}