← Back to daily report
+40 lines added
-2 lines removed
# Claude on Vertex AI¶
¶
Anthropic's Claude models are now generally available through [Vertex AI](https://cloud.google.com/vertex-ai).¶
¶
---¶
¶
The Vertex API for accessing Claude is nearly-identical to the [Messages API](/docs/en/api/messages) and supports all of the same options, with two key differences:¶
¶
* In Vertex, `model` is not passed in the request body. Instead, it is specified in the Google Cloud endpoint URL.¶
* In Vertex, `anthropic_version` is passed in the request body (rather than as a header), and must be set to the value `vertex-2023-10-16`.¶
¶
Vertex is also supported by Anthropic's official [client SDKs](/docs/en/api/client-sdks). This guide walks you through the process of making a request to Claude on Vertex AI in either Python or TypeScript.¶
¶
Note that this guide assumes you already have a GCP project that is able to use Vertex AI. See [using the Claude 3 models from Anthropic](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude) for more information on the setup required, as well as a full walkthrough.¶
¶
## Install an SDK for accessing Vertex AI¶
¶
First, install Anthropic's [client SDK](/docs/en/api/client-sdks) for your language of choice.¶
¶
<Tabs>¶
<Tab title="Python">¶
```bash¶
pip install -U google-cloud-aiplatform "anthropic[vertex]"¶
```¶
</Tab>¶
¶
<Tab title="TypeScript">¶
```bash¶
npm install @anthropic-ai/vertex-sdk¶
```¶
</Tab>¶
¶
<Tab title="Go">¶
```bash¶
go get github.com/anthropics/anthropic-sdk-go¶
```¶
</Tab>¶
¶
<Tab title="Java">¶
<CodeGroup>¶
```groovy Gradle¶
implementation("com.anthropic:anthropic-java-vertex:2.+")¶
```¶
¶
```xml Maven¶
<dependency>¶
<groupId>com.anthropic</groupId>¶
<artifactId>anthropic-java-vertex</artifactId>¶
<version>2.13.0</version>¶
</dependency>¶
```¶
</CodeGroup>¶
</Tab>¶
¶
<Tab title="Go">¶
```bash¶
go get github.com/anthropics/anthropic-sdk-go¶
```¶
</Tab>¶
¶
<Tab title="Ruby">¶
```bash¶
# Gemfile¶
gem "anthropic"¶
gem "googleauth"¶
```¶
</Tab>¶
</Tabs>¶
¶
<Note>¶
The PHP SDK does not currently support Google Vertex AI. For available SDK platform integrations, see [Client SDKs](/docs/en/api/client-sdks).¶
</Note>¶
¶
## Accessing Vertex AI¶
¶
### Model availability¶
¶
Note that Anthropic model availability varies by region. Search for "Claude" in the [Vertex AI Model Garden](https://cloud.google.com/model-garden) or go to [Use Claude 3](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude) for the latest information.¶
¶
#### API model IDs¶
¶
| Model | Vertex AI API model ID |¶
| ------------------------------ | ------------------------ |¶
| Claude Opus 4.6 | claude-opus-4-6 |¶
| Claude Sonnet 4.6 | claude-sonnet-4-6 |¶
| Claude Sonnet 4.5 | claude-sonnet-4-5@20250929 |¶
| Claude Sonnet 4 | claude-sonnet-4@20250514 |¶
| Claude Sonnet 3.7 <Tooltip tooltipContent="Retired as of February 19, 2026.">⚠️</Tooltip> | claude-3-7-sonnet@20250219 |¶
| Claude Opus 4.5 | claude-opus-4-5@20251101 |¶
| Claude Opus 4.1 | claude-opus-4-1@20250805 |¶
| Claude Opus 4 | claude-opus-4@20250514 |¶
| Claude Haiku 4.5 | claude-haiku-4-5@20251001 |¶
| Claude Haiku 3.5 <Tooltip tooltipContent="Retired as of February 19, 2026.">⚠️</Tooltip> | claude-3-5-haiku@20241022 |¶
| Claude Haiku 3 <Tooltip tooltipContent="Deprecated as of February 19, 2026. Retiring April 19, 2026.">⚠️</Tooltip> | claude-3-haiku@20240307 |¶
¶
### Making requests¶
¶
Before running requests you may need to run `gcloud auth application-default login` to authenticate with GCP.¶
¶
The following examples show how to generate text from Claude on Vertex AI:¶
<CodeGroup>¶
¶
```bash Shell¶
MODEL_ID=claude-opus-4-6¶
LOCATION=global¶
PROJECT_ID=MY_PROJECT_ID¶
¶
curl \¶
-X POST \¶
-H "Authorization: Bearer $(gcloud auth print-access-token)" \¶
-H "Content-Type: application/json" \¶
https://$LOCATION-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/anthropic/models/${MODEL_ID}:streamRawPredict -d \¶
'{¶
"anthropic_version": "vertex-2023-10-16",¶
"messages": [{¶
"role": "user",¶
"content": "Hey Claude!"¶
}],¶
"max_tokens": 100,¶
}'¶
```¶
¶
```python Python¶
from anthropic import AnthropicVertex¶
¶
project_id = "MY_PROJECT_ID"¶
region = "global"¶
¶
client = AnthropicVertex(project_id=project_id, region=region)¶
¶
message = client.messages.create(¶
model="claude-opus-4-6",¶
max_tokens=100,¶
messages=[¶
{¶
"role": "user",¶
"content": "Hey Claude!",¶
}¶
],¶
)¶
print(message)¶
```¶
¶
¶
```typescript TypeScript nocheck hidelines={1..2}¶
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";¶
¶
const projectId = "MY_PROJECT_ID";¶
const region = "global";¶
¶
// Goes through the standard `google-auth-library` flow.¶
const client = new AnthropicVertex({¶
projectId,¶
region¶
});¶
¶
async function main() {¶
const result = await client.messages.create({¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
messages: [¶
{¶
role: "user",¶
content: "Hey Claude!"¶
}¶
]¶
});¶
console.log(JSON.stringify(result, null, 2));¶
}¶
¶
main();¶
```¶
¶
```java Java¶
import com.anthropic.client.AnthropicClient;¶
import com.anthropic.client.okhttp.AnthropicOkHttpClient;¶
import com.anthropic.models.messages.Message;¶
import com.a¶
```csharp C# nocheck¶
using Anthropic;¶
using Anthropic.mModels.messages.MessageCreateParams;¶
import com.anthropic.vertex.backends.VertexBackend;¶
¶
public class VertexExample {¶
¶
public static void main(String[] args) {¶
// Uses default Google Cloud credentials¶
AnthropicClientMessages;¶
using Anthropic.Vertex;¶
¶
var projectId = "MY_PROJECT_ID";¶
var region = "global";¶
¶
var client = new AnthropicOkHttpClient.builder()Client¶
{¶
.bBackend( = new VertexBackend.fromEnv())¶
.build()(projectId, region)¶
};¶
¶
Message message = client¶
.messages()¶
.create(¶
var parameters = new MessageCreateParams.builder()¶
{¶
.mModel = Model("c.Claude-oOpus-4-6")4_6,¶
.mMaxTokens( = 100),¶
.addUserMessage("Hey Claude!")¶
.build()¶
);¶
¶
System.out.println(message);¶
}¶
}Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]¶
};¶
¶
var message = await client.Messages.Create(parameters);¶
Console.WriteLine(message);¶
```¶
¶
```go Go¶
package main¶
¶
import (¶
"context"¶
"fmt"¶
¶
"github.com/anthropics/anthropic-sdk-go"¶
"github.com/anthropics/anthropic-sdk-go/vertex"¶
)¶
¶
func main() {¶
// Uses default Google Cloud credentials¶
client := anthropic.NewClient(¶
vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),¶
)¶
¶
message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{¶
Model: "claude-opus-4-6",¶
MaxTokens: 100,¶
Messages: []anthropic.MessageParam{¶
anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),¶
},¶
})¶
if err != nil {¶
panic(err)¶
}¶
fmt.Printf("%+v\n", message)¶
}¶
```¶
¶
```ruby Ruby¶
require "anthropic"¶
¶
client = Anthropic::VertexClient.new(¶
region: "global",¶
project_id: "MY_PROJECT_ID"¶
)¶
¶
message = client.messages.create(¶
java Java¶
import com.anthropic.client.AnthropicClient;¶
import com.anthropic.client.okhttp.AnthropicOkHttpClient;¶
import com.anthropic.models.messages.Message;¶
import com.anthropic.models.messages.MessageCreateParams;¶
import com.anthropic.vertex.backends.VertexBackend;¶
¶
public class VertexExample {¶
¶
public static void main(String[] args) {¶
// Uses default Google Cloud credentials¶
AnthropicClient client = AnthropicOkHttpClient.builder()¶
.backend(VertexBackend.fromEnv())¶
.build();¶
¶
Message message = client¶
.messages()¶
.create(¶
MessageCreateParams.builder()¶
.model: ("claude-opus-4-6",)¶
.max_tTokens: (100,)¶
messages: [{role: "user", content: .addUserMessage("Hey Claude!"}])¶
)¶
¶
puts message.content.first.text¶
```¶
¶
```bash Shell¶
MODEL_ID=claude-opus-4-6¶
LOCATION=global¶
PROJECT_ID=MY_PROJECT_ID¶
¶
curl \¶
-X POST \¶
-H "Authorization: Bearer $(gcloud auth print-access-token)" \¶
-H "Content-Type: application/json" \¶
https://$LOCATION-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/anthropic/models/${MODEL_ID}:streamRawPredict -d \¶
'{¶
"anthropic_version": "vertex-2023-10-16" .build()¶
);¶
¶
System.out.println(message);¶
}¶
}¶
```¶
¶
```ruby Ruby¶
require "anthropic"¶
¶
client = Anthropic::VertexClient.new(¶
region: "global",¶
project_id: "MY_PROJECT_ID"¶
)¶
¶
message = client.messages.create(¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
"messages": [{¶
"role": "user",¶
" content": "Hey Claude!"}]¶
}],¶
"max_tokens": 100,¶
}')¶
¶
puts message.content.first.text¶
```¶
¶
</CodeGroup>¶
¶
See the [client SDKs](/docs/en/api/client-sdks) and the official [Vertex AI docs](https://cloud.google.com/vertex-ai/docs) for more details.¶
¶
Claude is also available through [Amazon Bedrock](/docs/en/build-with-claude/claude-on-amazon-bedrock) and [Microsoft Foundry](/docs/en/build-with-claude/claude-in-microsoft-foundry).¶
¶
## Activity logging¶
¶
Vertex provides a [request-response logging service](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/request-response-logging) that allows customers to log the prompts and completions associated with your usage.¶
¶
Anthropic recommends that you log your activity on at least a 30-day rolling basis in order to understand your activity and investigate any potential misuse.¶
¶
<Note>¶
Turning on this service does not give Google or Anthropic any access to your content.¶
</Note>¶
¶
## Feature support¶
For all currently supported features on Vertex AI, see [API features overview](/docs/en/api/overview).¶
¶
## Global vs regional endpoints¶
¶
Starting with **Claude Sonnet 4.5 and all future models**, Google Vertex AI offers two endpoint types:¶
¶
- **Global endpoints:** Dynamic routing for maximum availability¶
- **Regional endpoints:** Guaranteed data routing through specific geographic regions¶
¶
Regional endpoints include a 10% pricing premium over global endpoints.¶
¶
<Note>¶
This applies to Claude Sonnet 4.5 and future models only. Older models (Claude Sonnet 4, Opus 4, and earlier) maintain their existing pricing structures.¶
</Note>¶
¶
### When to use each option¶
¶
**Global endpoints (recommended):**¶
- Provide maximum availability and uptime¶
- Dynamically route requests to regions with available capacity¶
- No pricing premium¶
- Best for applications where data residency is flexible¶
- Only supports pay-as-you-go traffic (provisioned throughput requires regional endpoints)¶
¶
**Regional endpoints:**¶
- Route traffic through specific geographic regions¶
- Required for data residency and compliance requirements¶
- Support both pay-as-you-go and provisioned throughput¶
- 10% pricing premium reflects infrastructure costs for dedicated regional capacity¶
¶
### Implementation¶
¶
**Using global endpoints (recommended):**¶
¶
Set the `region` parameter to `"global"` when initializing the client:¶
¶
<CodeGroup>¶
¶
```python Python¶
from anthropic import AnthropicVertex¶
¶
project_id = "MY_PROJECT_ID"¶
region = "global"¶
¶
client = AnthropicVertex(project_id=project_id, region=region)¶
¶
message = client.messages.create(¶
model="claude-opus-4-6",¶
max_tokens=100,¶
messages=[¶
{¶
"role": "user",¶
"content": "Hey Claude!",¶
}¶
],¶
)¶
print(message)¶
```¶
¶
```typescript TypeScript nocheck hidelines={1..2}¶
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";¶
¶
const projectId = "MY_PROJECT_ID";¶
const region = "global";¶
¶
const client = new AnthropicVertex({¶
projectId,¶
region¶
});¶
¶
const result = await client.messages.create({¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
messages: [¶
{¶
role: "user",¶
content: "Hey Claude!"¶
}¶
]¶
});¶
```¶
¶
```java Java¶
import com.anthropic.client.AnthropicClient;¶
import com.anthropic.client.okhttp.AnthropicOkHttpClient;¶
import com.acsharp C# nocheck¶
using Anthropic;¶
using Anthropic.mModels.messages.MessageCreateParams;¶
import com.aMessages;¶
using Anthropic.vVertex.backends.VertexBackend;¶
¶
// Uses default Google Cloud credentials¶
AnthropicClient;¶
¶
var projectId = "MY_PROJECT_ID";¶
var region = "global";¶
¶
var client = new AnthropicOkHttpClient.builder()¶
.bClient¶
{¶
Backend( = VertexBackend.fFromEnv())¶
.build();¶
¶
var message = client¶
.messages()¶
.create(¶
ironment(projectId, region)¶
};¶
¶
var parameters = new MessageCreateParams.builder()¶
.m¶
{¶
Model = Model("c.Claude-oOpus-4-6")4_6,¶
.mMaxTokens( = 100),¶
.addUserMessage("Hey Claude!")¶
.build()¶
Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]¶
};¶
¶
var message = await client.Messages.Create(parameters);¶
Console.WriteLine(message);¶
```¶
¶
```go Go¶
package main¶
¶
import (¶
"context"¶
¶
"github.com/anthropics/anthropic-sdk-go"¶
"github.com/anthropics/anthropic-sdk-go/vertex"¶
)¶
¶
func main() {¶
// Uses default Google Cloud credentials¶
client := anthropic.NewClient(¶
vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),¶
)¶
¶
message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{¶
Model: "claude-opus-4-6",¶
MaxTokens: 100,¶
Messages: []anthropic.MessageParam{¶
anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),¶
},¶
})¶
_ = message¶
}¶
```¶
¶
```java Java¶
import com.anthropic.client.AnthropicClient;¶
import com.anthropic.client.okhttp.AnthropicOkHttpClient;¶
import com.anthropic.models.messages.MessageCreateParams;¶
import com.anthropic.vertex.backends.VertexBackend;¶
¶
// Uses default Google Cloud credentials¶
AnthropicClient client = AnthropicOkHttpClient.builder()¶
.backend(VertexBackend.fromEnv())¶
.build();¶
¶
var message = client¶
.messages()¶
.create(¶
MessageCreateParams.builder()¶
.model("claude-opus-4-6")¶
.maxTokens(100)¶
.addUserMessage("Hey Claude!")¶
.build()¶
);¶
```¶
¶
```ruby Ruby¶
require "anthropic"¶
¶
client = Anthropic::VertexClient.new(¶
region: "global",¶
project_id: "MY_PROJECT_ID"¶
)¶
¶
message = client.messages.create(¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
messages: [{role: "user", content: "Hey Claude!"}]¶
)¶
¶
puts message.content.first.text¶
```¶
¶
</CodeGroup>¶
¶
**Using regional endpoints:**¶
¶
Specify a specific region like `"us-east1"` or `"europe-west1"`:¶
¶
<CodeGroup>¶
¶
```python Python¶
from anthropic import AnthropicVertex¶
¶
project_id = "MY_PROJECT_ID"¶
region = "us-east1" # Specify a specific region¶
¶
client = AnthropicVertex(project_id=project_id, region=region)¶
¶
message = client.messages.create(¶
model="claude-opus-4-6",¶
max_tokens=100,¶
messages=[¶
{¶
"role": "user",¶
"content": "Hey Claude!",¶
}¶
],¶
)¶
print(message)¶
```¶
¶
```typescript TypeScript nocheck hidelines={1..2}¶
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";¶
¶
const projectId = "MY_PROJECT_ID";¶
const region = "us-east1"; // Specify a specific region¶
¶
const client = new AnthropicVertex({¶
projectId,¶
region¶
});¶
¶
const result = await client.messages.create({¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
messages: [¶
{¶
role: "user",¶
content: "Hey Claude!"¶
}¶
]¶
});¶
```¶
¶
```csharp C# nocheck¶
using Anthropic;¶
using Anthropic.Models.Messages;¶
¶
var projectId = "MY_PROJECT_ID";¶
var region = "us-east1";¶
¶
AnthropicClient client = new()¶
{¶
Backend = new VertexBackend¶
{¶
ProjectId = projectId,¶
Region = region¶
}¶
};¶
¶
var parameters = new MessageCreateParams¶
{¶
Model = Model.ClaudeOpus4_6,¶
MaxTokens = 100,¶
Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]¶
};¶
¶
var message = await client.Messages.Create(parameters);¶
Console.WriteLine(message);¶
```¶
¶
```go Go¶
package main¶
¶
import (¶
"context"¶
¶
"github.com/anthropics/anthropic-sdk-go"¶
"github.com/anthropics/anthropic-sdk-go/vertex"¶
)¶
¶
func main() {¶
// Specify a specific region¶
client := anthropic.NewClient(¶
vertex.WithGoogleAuth(context.Background(), "us-east1", "MY_PROJECT_ID"),¶
)¶
¶
message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{¶
Model: "claude-opus-4-6",¶
MaxTokens: 100,¶
Messages: []anthropic.MessageParam{¶
anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),¶
},¶
})¶
_ = message¶
}¶
```¶
¶
```java Java¶
import com.anthropic.client.AnthropicClient;¶
import com.anthropic.client.okhttp.AnthropicOkHttpClient;¶
import com.anthropic.models.messages.MessageCreateParams;¶
import com.anthropic.vertex.backends.VertexBackend;¶
¶
// Uses default Google Cloud credentials with specific region¶
AnthropicClient client = AnthropicOkHttpClient.builder()¶
.backend(¶
VertexBackend.builder()¶
.region("us-east1") // Specify a specific region¶
.project("MY_PROJECT_ID")¶
.build()¶
)¶
.build();¶
¶
var message = client¶
.messages()¶
.create(¶
MessageCreateParams.builder()¶
.model("claude-opus-4-6")¶
.maxTokens(100)¶
.addUserMessage("Hey Claude!")¶
.build()¶
);¶
```¶
¶
```go Go¶
package main¶
¶
import (¶
"context"¶
¶
"github.com/anthropics/anthropic-sdk-go"¶
"github.com/anthropics/anthropic-sdk-go/vertex"¶
)¶
¶
func main() {¶
// Specify a specific region¶
client := anthropic.NewClient(¶
vertex.WithGoogleAuth(context.Background(), "us-east1", "MY_PROJECT_ID"),¶
)¶
¶
message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{¶
Model: "claude-opus-4-6",¶
MaxTokens: 100,¶
Messages: []anthropic.MessageParam{¶
anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),¶
},¶
})¶
_ = message¶
}¶
```¶
¶
```ruby Ruby¶
require "anthropic"¶
¶
client = Anthropic::VertexClient.new(¶
region: "us-east1", # Specify a specific region¶
project_id: "MY_PROJECT_ID"¶
)¶
¶
message = client.messages.create(¶
model: "claude-opus-4-6",¶
max_tokens: 100,¶
messages: [{role: "user", content: "Hey Claude!"}]¶
)¶
¶
puts message.content.first.text¶
```¶
¶
</CodeGroup>¶
¶
### Additional resources¶
¶
- **Google Vertex AI pricing:** [cloud.google.com/vertex-ai/generative-ai/pricing](https://cloud.google.com/vertex-ai/generative-ai/pricing)¶
- **Claude models documentation:** [Claude on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude)¶
- **Google blog post:** [Global endpoint for Claude models](https://cloud.google.com/blog/products/ai-machine-learning/global-endpoint-for-claude-models-generally-available-on-vertex-ai)¶
- **Anthropic pricing details:** [Pricing documentation](/docs/en/about-claude/pricing#third-party-platform-pricing)
Unified Diff
--- a/build-with-claude/claude-on-vertex-ai.md
+++ b/build-with-claude/claude-on-vertex-ai.md
@@ -27,6 +27,12 @@
<Tab title="TypeScript">
```bash
npm install @anthropic-ai/vertex-sdk
+```
+</Tab>
+
+<Tab title="Go">
+```bash
+go get github.com/anthropics/anthropic-sdk-go
```
</Tab>
@@ -44,12 +50,6 @@
</dependency>
```
</CodeGroup>
-</Tab>
-
-<Tab title="Go">
-```bash
-go get github.com/anthropics/anthropic-sdk-go
-```
</Tab>
<Tab title="Ruby">
@@ -93,134 +93,6 @@
The following examples show how to generate text from Claude on Vertex AI:
<CodeGroup>
-
- ```python Python
- from anthropic import AnthropicVertex
-
- project_id = "MY_PROJECT_ID"
- region = "global"
-
- client = AnthropicVertex(project_id=project_id, region=region)
-
- message = client.messages.create(
- model="claude-opus-4-6",
- max_tokens=100,
- messages=[
- {
- "role": "user",
- "content": "Hey Claude!",
- }
- ],
- )
- print(message)
- ```
-
- ```typescript TypeScript
- import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
-
- const projectId = "MY_PROJECT_ID";
- const region = "global";
-
- // Goes through the standard `google-auth-library` flow.
- const client = new AnthropicVertex({
- projectId,
- region
- });
-
- async function main() {
- const result = await client.messages.create({
- model: "claude-opus-4-6",
- max_tokens: 100,
- messages: [
- {
- role: "user",
- content: "Hey Claude!"
- }
- ]
- });
- console.log(JSON.stringify(result, null, 2));
- }
-
- main();
- ```
-
- ```java Java
- import com.anthropic.client.AnthropicClient;
- import com.anthropic.client.okhttp.AnthropicOkHttpClient;
- import com.anthropic.models.messages.Message;
- import com.anthropic.models.messages.MessageCreateParams;
- import com.anthropic.vertex.backends.VertexBackend;
-
- public class VertexExample {
-
- public static void main(String[] args) {
- // Uses default Google Cloud credentials
- AnthropicClient client = AnthropicOkHttpClient.builder()
- .backend(VertexBackend.fromEnv())
- .build();
-
- Message message = client
- .messages()
- .create(
- MessageCreateParams.builder()
- .model("claude-opus-4-6")
- .maxTokens(100)
- .addUserMessage("Hey Claude!")
- .build()
- );
-
- System.out.println(message);
- }
- }
- ```
-
- ```go Go
- package main
-
- import (
- "context"
- "fmt"
-
- "github.com/anthropics/anthropic-sdk-go"
- "github.com/anthropics/anthropic-sdk-go/vertex"
- )
-
- func main() {
- // Uses default Google Cloud credentials
- client := anthropic.NewClient(
- vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
- )
-
- message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
- Model: "claude-opus-4-6",
- MaxTokens: 100,
- Messages: []anthropic.MessageParam{
- anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
- },
- })
- if err != nil {
- panic(err)
- }
- fmt.Printf("%+v\n", message)
- }
- ```
-
- ```ruby Ruby
- require "anthropic"
-
- client = Anthropic::VertexClient.new(
- region: "global",
- project_id: "MY_PROJECT_ID"
- )
-
- message = client.messages.create(
- model: "claude-opus-4-6",
- max_tokens: 100,
- messages: [{role: "user", content: "Hey Claude!"}]
- )
-
- puts message.content.first.text
- ```
```bash Shell
MODEL_ID=claude-opus-4-6
@@ -241,6 +113,161 @@
"max_tokens": 100,
}'
```
+
+ ```python Python
+ from anthropic import AnthropicVertex
+
+ project_id = "MY_PROJECT_ID"
+ region = "global"
+
+ client = AnthropicVertex(project_id=project_id, region=region)
+
+ message = client.messages.create(
+ model="claude-opus-4-6",
+ max_tokens=100,
+ messages=[
+ {
+ "role": "user",
+ "content": "Hey Claude!",
+ }
+ ],
+ )
+ print(message)
+ ```
+
+
+ ```typescript TypeScript nocheck hidelines={1..2}
+ import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
+
+ const projectId = "MY_PROJECT_ID";
+ const region = "global";
+
+ // Goes through the standard `google-auth-library` flow.
+ const client = new AnthropicVertex({
+ projectId,
+ region
+ });
+
+ async function main() {
+ const result = await client.messages.create({
+ model: "claude-opus-4-6",
+ max_tokens: 100,
+ messages: [
+ {
+ role: "user",
+ content: "Hey Claude!"
+ }
+ ]
+ });
+ console.log(JSON.stringify(result, null, 2));
+ }
+
+ main();
+ ```
+
+
+ ```csharp C# nocheck
+ using Anthropic;
+ using Anthropic.Models.Messages;
+ using Anthropic.Vertex;
+
+ var projectId = "MY_PROJECT_ID";
+ var region = "global";
+
+ var client = new AnthropicClient
+ {
+ Backend = new VertexBackend(projectId, region)
+ };
+
+ var parameters = new MessageCreateParams
+ {
+ Model = Model.ClaudeOpus4_6,
+ MaxTokens = 100,
+ Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
+ };
+
+ var message = await client.Messages.Create(parameters);
+ Console.WriteLine(message);
+ ```
+
+ ```go Go
+ package main
+
+ import (
+ "context"
+ "fmt"
+
+ "github.com/anthropics/anthropic-sdk-go"
+ "github.com/anthropics/anthropic-sdk-go/vertex"
+ )
+
+ func main() {
+ // Uses default Google Cloud credentials
+ client := anthropic.NewClient(
+ vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
+ )
+
+ message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
+ Model: "claude-opus-4-6",
+ MaxTokens: 100,
+ Messages: []anthropic.MessageParam{
+ anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
+ },
+ })
+ if err != nil {
+ panic(err)
+ }
+ fmt.Printf("%+v\n", message)
+ }
+ ```
+
+ ```java Java
+ import com.anthropic.client.AnthropicClient;
+ import com.anthropic.client.okhttp.AnthropicOkHttpClient;
+ import com.anthropic.models.messages.Message;
+ import com.anthropic.models.messages.MessageCreateParams;
+ import com.anthropic.vertex.backends.VertexBackend;
+
+ public class VertexExample {
+
+ public static void main(String[] args) {
+ // Uses default Google Cloud credentials
+ AnthropicClient client = AnthropicOkHttpClient.builder()
+ .backend(VertexBackend.fromEnv())
+ .build();
+
+ Message message = client
+ .messages()
+ .create(
+ MessageCreateParams.builder()
+ .model("claude-opus-4-6")
+ .maxTokens(100)
+ .addUserMessage("Hey Claude!")
+ .build()
+ );
+
+ System.out.println(message);
+ }
+ }
+ ```
+
+ ```ruby Ruby
+ require "anthropic"
+
+ client = Anthropic::VertexClient.new(
+ region: "global",
+ project_id: "MY_PROJECT_ID"
+ )
+
+ message = client.messages.create(
+ model: "claude-opus-4-6",
+ max_tokens: 100,
+ messages: [{role: "user", content: "Hey Claude!"}]
+ )
+
+ puts message.content.first.text
+ ```
+
</CodeGroup>
See the [client SDKs](/docs/en/api/client-sdks) and the official [Vertex AI docs](https://cloud.google.com/vertex-ai/docs) for more details.
@@ -295,6 +322,7 @@
Set the `region` parameter to `"global"` when initializing the client:
<CodeGroup>
+
```python Python
from anthropic import AnthropicVertex
@@ -316,7 +344,7 @@
print(message)
```
-```typescript TypeScript
+```typescript TypeScript nocheck hidelines={1..2}
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
const projectId = "MY_PROJECT_ID";
@@ -339,6 +367,57 @@
});
```
+```csharp C# nocheck
+using Anthropic;
+using Anthropic.Models.Messages;
+using Anthropic.Vertex;
+
+var projectId = "MY_PROJECT_ID";
+var region = "global";
+
+var client = new AnthropicClient
+{
+ Backend = VertexBackend.FromEnvironment(projectId, region)
+};
+
+var parameters = new MessageCreateParams
+{
+ Model = Model.ClaudeOpus4_6,
+ MaxTokens = 100,
+ Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
+};
+
+var message = await client.Messages.Create(parameters);
+Console.WriteLine(message);
+```
+
+```go Go
+package main
+
+import (
+ "context"
+
+ "github.com/anthropics/anthropic-sdk-go"
+ "github.com/anthropics/anthropic-sdk-go/vertex"
+)
+
+func main() {
+ // Uses default Google Cloud credentials
+ client := anthropic.NewClient(
+ vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
+ )
+
+ message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{
+ Model: "claude-opus-4-6",
+ MaxTokens: 100,
+ Messages: []anthropic.MessageParam{
+ anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
+ },
+ })
+ _ = message
+}
+```
+
```java Java
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
@@ -361,33 +440,6 @@
);
```
-```go Go
-package main
-
-import (
- "context"
-
- "github.com/anthropics/anthropic-sdk-go"
- "github.com/anthropics/anthropic-sdk-go/vertex"
-)
-
-func main() {
- // Uses default Google Cloud credentials
- client := anthropic.NewClient(
- vertex.WithGoogleAuth(context.Background(), "global", "MY_PROJECT_ID"),
- )
-
- message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{
- Model: "claude-opus-4-6",
- MaxTokens: 100,
- Messages: []anthropic.MessageParam{
- anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
- },
- })
- _ = message
-}
-```
-
```ruby Ruby
require "anthropic"
@@ -404,6 +456,7 @@
puts message.content.first.text
```
+
</CodeGroup>
**Using regional endpoints:**
@@ -411,6 +464,7 @@
Specify a specific region like `"us-east1"` or `"europe-west1"`:
<CodeGroup>
+
```python Python
from anthropic import AnthropicVertex
@@ -432,7 +486,7 @@
print(message)
```
-```typescript TypeScript
+```typescript TypeScript nocheck hidelines={1..2}
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
const projectId = "MY_PROJECT_ID";
@@ -455,6 +509,60 @@
});
```
+```csharp C# nocheck
+using Anthropic;
+using Anthropic.Models.Messages;
+
+var projectId = "MY_PROJECT_ID";
+var region = "us-east1";
+
+AnthropicClient client = new()
+{
+ Backend = new VertexBackend
+ {
+ ProjectId = projectId,
+ Region = region
+ }
+};
+
+var parameters = new MessageCreateParams
+{
+ Model = Model.ClaudeOpus4_6,
+ MaxTokens = 100,
+ Messages = [new() { Role = Role.User, Content = "Hey Claude!" }]
+};
+
+var message = await client.Messages.Create(parameters);
+Console.WriteLine(message);
+```
+
+```go Go
+package main
+
+import (
+ "context"
+
+ "github.com/anthropics/anthropic-sdk-go"
+ "github.com/anthropics/anthropic-sdk-go/vertex"
+)
+
+func main() {
+ // Specify a specific region
+ client := anthropic.NewClient(
+ vertex.WithGoogleAuth(context.Background(), "us-east1", "MY_PROJECT_ID"),
+ )
+
+ message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{
+ Model: "claude-opus-4-6",
+ MaxTokens: 100,
+ Messages: []anthropic.MessageParam{
+ anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
+ },
+ })
+ _ = message
+}
+```
+
```java Java
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
@@ -482,33 +590,6 @@
);
```
-```go Go
-package main
-
-import (
- "context"
-
- "github.com/anthropics/anthropic-sdk-go"
- "github.com/anthropics/anthropic-sdk-go/vertex"
-)
-
-func main() {
- // Specify a specific region
- client := anthropic.NewClient(
- vertex.WithGoogleAuth(context.Background(), "us-east1", "MY_PROJECT_ID"),
- )
-
- message, _ := client.Messages.New(context.Background(), anthropic.MessageNewParams{
- Model: "claude-opus-4-6",
- MaxTokens: 100,
- Messages: []anthropic.MessageParam{
- anthropic.NewUserMessage(anthropic.NewTextBlock("Hey Claude!")),
- },
- })
- _ = message
-}
-```
-
```ruby Ruby
require "anthropic"
@@ -525,6 +606,7 @@
puts message.content.first.text
```
+
</CodeGroup>
### Additional resources