Making requests
Claude Platform on AWS uses the same API endpoints as the first-party Claude API. The differences are the base URL, the authentication method, and a required anthropic-workspace-id header that identifies which workspace the request targets.
Before running these examples, complete the steps in Before making API calls.
# Replace us-west-2 with your AWS region in both the URL and --aws-sigv4
# Omit the x-amz-security-token header if you use long-term IAM user credentials
curl "https://aws-external-anthropic.us-west-2.api.aws/v1/messages" \
--aws-sigv4 "aws:amz:us-west-2:aws-external-anthropic" \
--user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
-H "x-amz-security-token: $AWS_SESSION_TOKEN" \
-H "content-type: application/json" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-workspace-id: $ANTHROPIC_AWS_WORKSPACE_ID" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello!"}
]
}'# Replace us-west-2 with your AWS region
# ant reads ANTHROPIC_API_KEY and sends it as x-api-key. Generate a key in the
# AWS Console (see API key authentication).
export ANTHROPIC_API_KEY="YOUR_AWS_API_KEY"
ant messages create \
--base-url https://aws-external-anthropic.us-west-2.api.aws \
--workspace-id "$ANTHROPIC_AWS_WORKSPACE_ID" \
--model claude-sonnet-5 \
--max-tokens 1024 \
--message '{role: user, content: "Hello!"}' \
--transform contentfrom anthropic import AnthropicAWS
client = AnthropicAWS()
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message)import AnthropicAws from "@anthropic-ai/aws-sdk";
const client = new AnthropicAws();
const message = await client.messages.create({
model: "claude-sonnet-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }]
});
console.log(message);using Anthropic;
using Anthropic.Aws;
var client = new AnthropicAwsClient();
var message = await client.Messages.Create(new()
{
Model = Model.ClaudeSonnet5,
MaxTokens = 1024,
Messages = [new() { Role = Role.User, Content = "Hello!" }]
});
Console.WriteLine(message);client, err := anthropicaws.NewClient(context.Background(), anthropicaws.ClientConfig{})
if err != nil {
panic(err)
}
message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
Model: anthropic.ModelClaudeSonnet5,
MaxTokens: 1024,
Messages: []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Hello!")),
},
})
if err != nil {
panic(err)
}
fmt.Println(message)import com.anthropic.aws.backends.AwsBackend;
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.models.messages.Model;
void main() {
AnthropicClient client = AnthropicOkHttpClient.builder()
.backend(AwsBackend.fromEnv())
.build();
Message message = client.messages().create(
MessageCreateParams.builder()
.model(Model.CLAUDE_SONNET_5)
.maxTokens(1024)
.addUserMessage("Hello!")
.build()
);
IO.println(message);
}use Anthropic\Aws\Client;
$client = new Client();
$message = $client->messages->create(
model: 'claude-sonnet-5',
maxTokens: 1024,
messages: [['role' => 'user', 'content' => 'Hello!']],
);
echo $message;require "anthropic"
client = Anthropic::AWSClient.new
message = client.messages.create(
model: "claude-sonnet-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }]
)
puts messageThe client reads AWS_REGION (or AWS_DEFAULT_REGION) and ANTHROPIC_AWS_WORKSPACE_ID from the environment. You can override either by passing aws_region / awsRegion or workspace_id / workspaceId to the constructor. Both region and workspace ID are required. The constructor raises an error if either cannot be resolved.
The x-amz-security-token header (cURL) is only required for temporary credentials such as IAM roles, SSO, or STS. Omit it when using long-term IAM user credentials. The SDK clients handle this automatically based on the credential source.
The --aws-sigv4 value follows the format aws:amz:<region>:<service>. The SigV4 service name is aws-external-anthropic, and the region must match the region in your endpoint URL. A mismatch in either produces a generic signature-rejection error rather than a specific diagnostic.
Context window
Context-window sizes on Claude Platform on AWS are identical to the first-party Claude API. See Context windows for per-model limits.