{"record":{"id":"1e9cb604230f029b","repo":"BoundaryML/baml","slug":"options-project-id-is-required-when-using-api-key-auth-with","errorCode":null,"errorMessage":"options.project_id is required when using API key auth with Vertex 'location' URLs;","messagePattern":"options\\.project_id is required when using API key auth with Vertex 'location' URLs;","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs","lineNumber":265,"sourceCode":"        _expose_secrets: bool,\n    ) -> Result<reqwest::RequestBuilder> {\n        // Determine if API key auth is being used (query param 'key')\n        let has_api_key_query = self.properties.query_params.contains_key(\"key\");\n        let mut vertex_auth: Option<std::sync::Arc<super::auth::VertexAuth>> = None;\n\n        let base_url = match &self.properties.base_url_or_location {\n            BaseUrlOrLocation::BaseUrl(base_url) => base_url.to_string(),\n            BaseUrlOrLocation::Location(location) => {\n                let domain = if location == \"global\" {\n                    \"aiplatform.googleapis.com\".to_string()\n                } else {\n                    format!(\"{location}-aiplatform.googleapis.com\")\n                };\n                let project_id = match self.properties.project_id.as_ref() {\n                    Some(project_id) => project_id.to_string(),\n                    None => {\n                        if has_api_key_query {\n                            anyhow::bail!(\n                                \"options.project_id is required when using API key auth with Vertex 'location' URLs;\"\n                            );\n                        }\n                        // Fallback to GCP Application Default Credentials only when not using API key\n                        let va = match &vertex_auth {\n                            Some(va) => va,\n                            None => {\n                                vertex_auth = Some(\n                                    super::auth::VertexAuth::get_or_create(\n                                        &self.properties.auth_strategy,\n                                    )\n                                    .await?,\n                                );\n                                vertex_auth.as_ref().unwrap()\n                            }\n                        };\n                        va.project_id().await?.to_string()\n                    }","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs#L247-L283","documentation":"When building the Vertex AI request URL on a regional '<location>-aiplatform.googleapis.com' endpoint, the project ID is required. If project_id is absent from options AND an API key is being used as a query parameter, BAML bails because it cannot construct a valid regional URL (and will not fall back to Application Default Credentials when an API key is present).","triggerScenarios":"Using Vertex with API-key authentication (has_api_key_query true) while omitting options.project_id, on a location-based URL.","commonSituations":"Authenticating to Vertex with an API key (instead of service-account credentials) but forgetting to set project_id in the client options; works without project_id when using ADC but fails once an API key is switched on.","solutions":["Add project_id to the client's Vertex options (e.g. project_id \"my-gcp-project\")","Alternatively switch to Application Default Credentials / service-account auth so project_id can be inferred, though supplying it explicitly is still recommended","Double-check the project ID string matches the GCP project hosting the Vertex endpoint"],"exampleFix":"// before\noptions {\n  model gemini-1.5-pro\n  location us-central1\n  api_key $VERTEX_API_KEY\n}\n// after\noptions {\n  model gemini-1.5-pro\n  location us-central1\n  project_id my-gcp-project\n  api_key $VERTEX_API_KEY\n}","handlingStrategy":"validation","validationCode":"function assertVertexApiKeysConfig(options) {\n  if (options?.api_key && !options?.project_id) {\n    throw new Error(\"vertex options with api_key must also set project_id\");\n  }\n}\nassertVertexApiKeysConfig(clientConfig.options);","typeGuard":null,"tryCatchPattern":"try {\n  await baml_client.MyVertexFunction(prompt);\n} catch (err) {\n  if (String(err).includes('options.project_id is required')) {\n    console.error('Add options.project_id to your Vertex client config');\n  }\n  throw err;\n}","preventionTips":["Always include project_id in Vertex client options, regardless of auth method","Treat API-key auth and ADC auth as distinct config profiles with their own required fields","Validate the GCP project ID format (6-30 lowercase letters, digits, hyphens) before deployment"],"tags":["vertex-ai","gcp","configuration","api-key"],"backgroundTag":"missing-required-config-field","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}