{"record":{"id":"761c2a1857a82309","repo":"JuliusBrussee/caveman","slug":"vertex-endpoint-host-q-is-not-an-aiplatform-host","errorCode":null,"errorMessage":"vertex endpoint host %q is not an aiplatform host","messagePattern":"vertex endpoint host %q is not an aiplatform host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/vertex/routing.go","lineNumber":69,"sourceCode":"\tif route.BaseURL != \"\" {\n\t\tbaseURL = route.BaseURL\n\t}\n\tbase, err := url.Parse(baseURL)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"vertex base url invalid: %w\", err)\n\t}\n\tbase.Path = strings.TrimRight(base.Path, \"/\") + strings.TrimPrefix(req.URL.Path, \"/vertex\")\n\tbase.RawQuery = providers.WithoutGoogleAPIKeyQuery(req.URL.RawQuery)\n\n\t// SSRF/host validation on the resolved endpoint. Active in managed (prod)\n\t// mode; local/self-hosted (stub) endpoints are permitted so the dry-run and\n\t// examples can target the provider-stub.\n\tif env.IsProduction() {\n\t\tif err := providers.ValidateUpstreamEndpoint(ctx, base, ssrf.ManagedConfig()); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif host := base.Hostname(); !isVertexHost(host) {\n\t\t\treturn nil, fmt.Errorf(\"vertex endpoint host %q is not an aiplatform host\", host)\n\t\t}\n\t}\n\treturn base, nil\n}\n\nfunc methodAllowed(publisher, method string) bool {\n\t// countTokens is publisher-agnostic on aiplatform: the discovery document\n\t// defines projects.locations.publishers.models.countTokens for any publisher.\n\tif method == \"countTokens\" {\n\t\treturn publisher == \"google\" || publisher == \"anthropic\"\n\t}\n\tswitch publisher {\n\tcase \"google\":\n\t\treturn method == \"generateContent\" || method == \"streamGenerateContent\"\n\tcase \"anthropic\":\n\t\treturn method == \"rawPredict\" || method == \"streamRawPredict\"\n\tdefault:\n\t\treturn false","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/vertex/routing.go#L51-L87","documentation":"In production mode, after SSRF validation, ResolveUpstreamURL additionally requires the resolved hostname to be a Vertex AI aiplatform host (routing.go:64-70, isVertexHost at 211-222): 'aiplatform.googleapis.com', any '{location}-aiplatform.googleapis.com' (including global-), or 'aiplatform.{us,eu}.rep.googleapis.com'. This is defense-in-depth against the endpoint being repointed at a non-Vertex host in managed deployments.","triggerScenarios":"Run with CAVE_ENV indicating production while the adapter/route BaseURL points at a non-aiplatform host — e.g. 'https://generativelanguage.googleapis.com', 'https://us-central1-notebook.googleapis.com', or a loopback stub base URL.","commonSituations":"Copying a Gemini-API (generativelanguage) base URL into the Vertex adapter; pointing at a local mock in a prod-flagged environment; a route.BaseURL override intended only for development leaking into a managed deployment; using the wrong regional domain spelling.","solutions":["Set the base URL to a regional Vertex endpoint like 'https://{location}-aiplatform.googleapis.com' (e.g. us-central1-aiplatform.googleapis.com) or the global 'https://aiplatform.googleapis.com'.","Remove any development/stub BaseURL override (route.BaseURL) from the production configuration.","If you actually want the Gemini API rather than Vertex AI, use the gemini adapter instead of the vertex adapter.","For local testing, run in a non-production environment (env.IsProduction() false) where stub endpoints are permitted."],"exampleFix":"// before\nBaseURL: \"https://generativelanguage.googleapis.com\"\n// after\nBaseURL: \"https://us-central1-aiplatform.googleapis.com\"","handlingStrategy":"validation","validationCode":"host := u.Hostname()\nvertexHost := host == \"aiplatform.googleapis.com\" ||\n    strings.HasSuffix(host, \"-aiplatform.googleapis.com\") ||\n    (strings.HasPrefix(host, \"aiplatform.\") && strings.HasSuffix(host, \".rep.googleapis.com\"))\nif env.IsProduction() && !vertexHost {\n    return fmt.Errorf(\"host %q is not a Vertex aiplatform endpoint\", host)\n}","typeGuard":"func isVertexHost(host string) bool {\n    return host == \"aiplatform.googleapis.com\" ||\n        strings.HasSuffix(host, \"-aiplatform.googleapis.com\") ||\n        (strings.HasPrefix(host, \"aiplatform.\") && strings.HasSuffix(host, \".rep.googleapis.com\"))\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"not an aiplatform host\") {\n    return httpError(500, \"use https://{location}-aiplatform.googleapis.com as the Vertex base URL in production\")\n}","preventionTips":["Use regional aiplatform.googleapis.com hosts for Vertex; generativelanguage.googleapis.com belongs to the Gemini adapter.","Keep stub/local base URLs out of production-flagged environments.","Prefer the regional hostname pattern {location}-aiplatform.googleapis.com (e.g. us-central1-aiplatform.googleapis.com).","Test prod-mode config with a dry-run before rolling out route BaseURL overrides."],"tags":["go","vertex","ssrf","host-validation","production"],"backgroundTag":"invalid-url-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}