{"record":{"id":"b891b3610198d5f5","repo":"JuliusBrussee/caveman","slug":"vertex-method-q-is-not-allowed-for-publisher-q","errorCode":null,"errorMessage":"vertex method %q is not allowed for publisher %q","messagePattern":"vertex method %q is not allowed for publisher %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/vertex/routing.go","lineNumber":41,"sourceCode":"// Operators override it with CAVE_VERTEX_MODEL_ALLOWLIST.\nvar defaultModelPrefixes = []string{\"gemini-\", \"claude-\"}\n\n// ResolveUpstreamURL validates the Vertex request shape (publisher + model on\n// the allowlist), enforces SSRF/host constraints against the aiplatform\n// endpoint, and resolves the upstream URL. The /vertex prefix is stripped so the\n// upstream path is the native aiplatform path\n// (/v1/projects/{p}/locations/{l}/publishers/{pub}/models/{model}:{method}). The\n// non-authentication query bytes (e.g. ?alt=sse) are preserved unchanged.\nfunc (a Adapter) ResolveUpstreamURL(ctx context.Context, req *http.Request, route providers.RouteContext) (*url.URL, error) {\n\tif _, err := providers.GoogleRequestAPIKey(req); err != nil {\n\t\treturn nil, err\n\t}\n\tpublisher, model, method := parsePredictPath(req.URL.Path)\n\tif publisher == \"\" || model == \"\" || method == \"\" {\n\t\treturn nil, fmt.Errorf(\"vertex request path %q does not name a publisher, model, and method\", req.URL.Path)\n\t}\n\tif !methodAllowed(publisher, method) {\n\t\treturn nil, fmt.Errorf(\"vertex method %q is not allowed for publisher %q\", method, publisher)\n\t}\n\tif !publisherAllowed(publisher) {\n\t\treturn nil, fmt.Errorf(\"vertex publisher %q is not on the allowlist\", publisher)\n\t}\n\tif !modelAllowed(model) && !anthropicCountTokensPath(publisher, model, method) {\n\t\treturn nil, fmt.Errorf(\"vertex model %q is not on the allowlist\", model)\n\t}\n\n\tbaseURL := a.BaseURL\n\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)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/vertex/routing.go#L23-L59","documentation":"The Vertex adapter enforces a per-publisher method allowlist in methodAllowed (routing.go:40-41,75-89). Google-publisher models accept only generateContent/streamGenerateContent; Anthropic-publisher models accept only rawPredict/streamRawPredict; countTokens is allowed for both. A method/publisher combination outside that matrix is rejected before the request is routed upstream.","triggerScenarios":"Call '/vertex/.../publishers/google/models/gemini-2.5-pro:rawPredict' (OpenAI-style method on a Google model) or '/vertex/.../publishers/anthropic/models/claude-sonnet-4-5:generateContent' (Gemini-style method on a Claude model).","commonSituations":"Pointing an Anthropic-format client at a google-publisher model or vice versa; copying a curl example for one model family and swapping only the model id; SDK defaults that assume the other publisher's method.","solutions":["Match the method to the publisher: use :generateContent/:streamGenerateContent for publisher 'google', :rawPredict/:streamRawPredict for publisher 'anthropic'.","Change the publisher segment in the path if the model actually belongs to the other family (e.g. gemini-* under publishers/google, claude-* under publishers/anthropic).","For token counting either family works: use :countTokens (google/anthropic) or the Anthropic SDK's count-tokens:rawPredict path."],"exampleFix":"// before\nPOST /vertex/v1/projects/p/locations/l/publishers/google/models/claude-sonnet-4-5:generateContent\n// after\nPOST /vertex/v1/projects/p/locations/l/publishers/anthropic/models/claude-sonnet-4-5@20250929:rawPredict","handlingStrategy":"validation","validationCode":"if !methodAllowed(publisher, method) {\n    return fmt.Errorf(\"method %s invalid for publisher %s: google→generateContent|streamGenerateContent, anthropic→rawPredict|streamRawPredict\", method, publisher)\n}","typeGuard":"func isCompatiblePair(publisher, method string) bool {\n    return methodAllowed(publisher, method)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"is not allowed for publisher\") {\n    return httpError(400, \"method/publisher mismatch — match the method to the model family\")\n}","preventionTips":["Keep a mental map: gemini-* models → publishers/google + :generateContent; claude-* → publishers/anthropic + :rawPredict.","Never swap only the model id in a copied curl example; check the publisher too.","For token counting use :countTokens, allowed for both publishers."],"tags":["go","vertex","routing","allowlist"],"backgroundTag":"unsupported-operation","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"}