Last updated 2026-05-17
Vertex AI Model Garden — Anthropic
The vertexanthropic provider talks to
Claude models hosted on Google Vertex AI Model
Garden. The transport layer is Vertex-shaped (regional
:streamRawPredict endpoint, OAuth2 access token from
Google ADC), but the request body and the SSE event stream are
native Anthropic. There is one Vertex-specific quirk — covered
below — and one model-id format change.
Picking the right Anthropic surface:
-
providers/anthropic— directapi.anthropic.com. -
providers/bedrock— Claude via AWS Bedrock (Converse API). -
providers/azureanthropic— Claude via Azure AI Foundry. -
providers/vertexanthropic(this page) — Claude via Vertex Model Garden.
Import path
import ( "github.com/elloloop/llmrouter" "github.com/elloloop/llmrouter/providers/vertexanthropic")Endpoint shape
Vertex serves Anthropic models from a regional, project-scoped endpoint:
POST https://<region>-aiplatform.googleapis.com/v1/projects/<project>/locations/<region>/publishers/anthropic/models/<model>:streamRawPredict
The provider composes this URL from WithProject,
WithRegion, and the model id on the request. You can
override the host with llmrouter.WithBaseURL if you
front Vertex behind a custom hostname.
Vertex-specific quirks
- The Vertex version goes in the body. Anthropic on
Vertex requires a top-level
"anthropic_version": "vertex-2023-10-16"field in the request body — not in a header. The provider injects this automatically; you do not need to set it onChatRequest. - Model id uses
@-versioning. Vertex addresses Claude variants asclaude-3-5-sonnet-v2@20241022, not the dash-separated form direct Anthropic uses. Pass the Vertex form verbatim inChatRequest.Model— the provider interpolates it straight into the URL. (The router can translate vendor-neutral ids likeclaude-3-5-sonnetto the@-versioned form for you viarouter.ApplyModelTranslation.) - Pure HTTP, no
google.golang.org/genaidependency. Unlikeproviders/vertex(which uses the genai SDK for Gemini), this package is intentionally a pure-HTTP provider — it does not import the GCP SDK. Bring your own token source.
Authentication
Vertex uses Google ADC (Application Default Credentials), surfaced
here as an OAuth2 access token sent in the
Authorization: Bearer header. Two ways to provide
one — pick exactly one:
-
WithTokenSource(src TokenSource)— preferred. Your callback is invoked once perCompletionStreamcall. Implement caching and refresh inside the callback (the standard pattern wraps anoauth2.TokenSourcefromgolang.org/x/oauth2/google). -
WithAccessToken(token string)— static. Convenient for CI runs where the token is minted out-of-band and lives long enough for the request to complete. Not appropriate for long-lived servers (tokens expire every hour).
llmrouter.WithAPIKey is rejected at
New(). Vertex does not accept API keys for
Model Garden endpoints, and accepting one silently would
misconfigure auth.
Construction
The canonical pattern wraps a Google ADC token source:
import ( "context"
"github.com/elloloop/llmrouter" "github.com/elloloop/llmrouter/providers/vertexanthropic" "golang.org/x/oauth2/google")
func newProvider(ctx context.Context) (*vertexanthropic.Provider, error) { creds, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/cloud-platform") if err != nil { return nil, err }
return vertexanthropic.New( vertexanthropic.WithProject("my-gcp-project"), vertexanthropic.WithRegion("us-east5"), vertexanthropic.WithTokenSource(func(ctx context.Context) (string, error) { tok, err := creds.TokenSource.Token() if err != nil { return "", err } return tok.AccessToken, nil }), )}
The token source closes over the cached oauth2.TokenSource,
so refreshes happen transparently inside the callback.
Capabilities
Because the body and SSE event stream are native Anthropic, every feature of the Anthropic provider works without code changes — typed tool use, extended thinking deltas, prompt caching, multipart content, mid-stream errors, structured outputs via forced tool-use, tool-result messages.
Full example
package main
import ( "context" "fmt" "log"
"github.com/elloloop/llmrouter" "github.com/elloloop/llmrouter/providers/vertexanthropic" "golang.org/x/oauth2/google")
func main() { ctx := context.Background()
creds, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/cloud-platform") if err != nil { log.Fatal(err) }
p, err := vertexanthropic.New( vertexanthropic.WithProject("my-gcp-project"), vertexanthropic.WithRegion("us-east5"), vertexanthropic.WithTokenSource(func(ctx context.Context) (string, error) { tok, err := creds.TokenSource.Token() if err != nil { return "", err } return tok.AccessToken, nil }), ) if err != nil { log.Fatal(err) }
stream, err := p.CompletionStream(ctx, llmrouter.ChatRequest{ // Vertex addresses Claude with an @-versioned model id. Model: "claude-3-5-sonnet-v2@20241022", MaxTokens: 1024, Messages: []llmrouter.Message{ llmrouter.TextMessage("user", "In one sentence, what is Vertex Model Garden?"), }, }) if err != nil { log.Fatal(err) }
for chunk := range stream.Chunks() { for _, c := range chunk.Choices { fmt.Print(c.Delta.Content) } } if err := stream.Err(); err != nil { log.Fatal(err) } fmt.Println()}Supported regions
Vertex serves Anthropic models from a subset of regions. Check the
current list at
cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude.
At time of writing, us-east5 and
europe-west1 are the most widely available regions
for the current Claude 3.5 generation.
Error handling
Non-2xx responses surface as
*llmrouter.ErrUpstream
with Provider == "vertexanthropic". Common cases:
401— access token expired or wrong scopes (needcloud-platform).403— IAM permission missing on the project; the caller needsaiplatform.endpoints.predictor the broaderroles/aiplatform.user.404— model id not available in this region (check the supported-regions matrix).400— body shape mismatch; the most common cause is sending a model id without the@-version suffix.
When to use this vs other Anthropic surfaces
- Use
vertexanthropicwhen you're on GCP and want IAM + project + region as the auth and billing boundary, or your data-residency requirements pin you to a GCP region. - Use direct Anthropic when you want the latest variants on day one. Vertex Model Garden lags direct Anthropic by days to weeks for new releases.
- Use Bedrock when you're on AWS — same shape, different cloud.
- Use azureanthropic when you're on Azure.
See also
- Anthropic provider — direct API; same body and SSE shape.
- Vertex AI provider — Gemini on Vertex (uses the genai SDK).
- The Router — automatic platform resolution with model-id translation.
router.ApplyModelTranslation— translate vendor-neutral Claude ids to the Vertex@-versioned form.