翻篇收录说明
翻篇网页快照

Claude Platform on AWS | AI SDK

https://ai-sdk.dev/providers/ai-sdk-providers/anthropic-aws

最近抓取:2026-12-04 03:45:10(北京时间)

最近内容变化:2026-12-04 03:45:10(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Learn how to use Claude Platform on AWS with AI Gateway and the direct provider.

正文摘录

AI SDK ProvidersMenuClaude Platform on AWSCopy for LLMView MarkdownAsk AI about this pageThe Claude Platform on AWS provider for the AI SDK gives you access to the Anthropic Messages API hosted inside your AWS environment. Anthropic operates the stack, so you get the same API surface and feature set as the first-party Anthropic provider — including streaming, prompt caching, tool use, computer use, Agent Skills, and anthropic-beta headers — with AWS-native authentication and AWS Marketplace billing. Start with AI Gateway for models in its catalog (recommended), or use @ai-sdk/anthropic-aws to connect directly to Claude Platform on AWS. GatewayClaude Platform on AWSClaude Sonnet 5.5import { generateText } from 'ai'; const { text } = await generateText({ model: "anthropic/claude-sonnet-5.5", prompt: 'Write a vegetarian lasagna recipe for 4 people.', providerOptions: { gateway: { order: ['claudeaws'], }, }, }); console.log(text); Using AI Gateway The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install ai: pnpmnpmyarnbun$ pnpm add ai Set an AI Gateway API key in your environment: export AI_GATEWAY_API_KEY=your_api_key_here Vercel deployments can also use OIDC authentication. See the AI Gateway provider documentation for configuration and the model catalog for available models. The example sets providerOptions.gateway.order to ['claudeaws']. This sends the request to Claude Platform on AWS first, then falls back to other available providers of the same model if Claude Platform on AWS is unavailable or the request fails. order sets a preference; it does not restrict fallback to Claude Platform on AWS. See provider ordering. The dropdown lists models served by Claude Platform on AWS through Gateway with a corresponding direct-provider example. Provider availability depends on the model and your team's Provider Allowlist. Gateway uses the claudeaws route for Claude Platform on AWS. Enable claudeaws in your team's Gateway Provider Allowlist if it is disabled; otherwise order allows Gateway to fall back to another provider. It authenticates the upstream request using Gateway-managed credentials; your AWS workspace and AWS Marketplace billing are configured separately when using the direct provider. Using @ai-sdk/anthropic-aws For direct access to Claude Platform on AWS, install ai and @ai-sdk/anthropic-aws: pnpmnpmyarnbun$ pnpm add ai @ai-sdk/anthropic-aws Set your Claude Platform on AWS API credential in the ANTHROPIC_AWS_API_KEY environment variable: export ANTHROPIC_AWS_API_KEY=your_api_key_here export AWS_REGION=us-west-2 export ANTHROPIC_AWS_WORKSPACE_ID=your_workspace_id Use the direct provider when you need AWS-native authentication, AWS Marketplace billing, or access to your Claude Platform workspace. Gateway requests do not use your workspace configuration. The following sections document the direct @ai-sdk/anthropic-aws provider, including its model factories and settings. Gateway model and feature availability can differ. This differs from Amazon Bedrock in two important ways: Claude Platform on AWS uses Anthropic's Messages API directly (not Bedrock's Converse/InvokeModel), and new features are available the same day they launch on the first-party Claude API (no AWS integration delay). Message threads The direct provider supports Anthropic message threads through providerOptions.anthropic.thread. Create with { type: 'create' }, then continue with { type: 'continue', previousMessageId } and only new messages. The required beta header is added automatically. Keep a full local history for replay after expiry and keep fixed settings and beta headers identical between requests. When using SigV4, sign every request of a thread with credentials for the same IAM role or IAM user that created it. Prerequisites Before you can use the provider, your AWS account must be subscribed to Claude Platform on AWS through the AWS Marketplace, and outbound web identity federation must be enabled on the account (a one-time setup step): aws iam enable-outbound-web-identity-federation Without this, every request returns Outbound web identity federation is disabled for your account. This is the most common setup error. You'll also need your workspace ID. When you subscribe, AWS provisions an initial workspace for your account in the selected region. You can find the ID in the Claude Console under Workspaces (accessed from the AWS Console via the Claude Platform on AWS service page). Authentication The provider supports two authentication methods: Using AWS SigV4 (recommended for production) SigV4 integrates with your existing AWS IAM policies, roles, and auditing. Configure AWS credentials using any method supported by the AWS default credential provider chain — environment variables, shared credentials file, web identity (IRSA), ECS container credentials, or EC2 instance metadata. AWS_REGION=us-west-2 ANTHROPIC_AWS_WORKSPACE_ID=wrkspc_… AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=… # AWS_SESSION_TOKEN=… # only for temporary credentials (SSO, STS, assumed role) Then use the default provider instance: import { anthropicAws } from '@ai-sdk/anthropic-aws'; Or instantiate explicitly: import { createAnthropicAws } from '@ai-sdk/anthropic-aws'; const anthropicAws = createAnthropicAws({ region: 'us-west-2', workspaceId: 'wrkspc_…', }); For dynamic credentials (e.g., assuming a role at request time): const anthropicAws = createAnthropicAws({ region: 'us-west-2', workspaceId: 'wrkspc_…', credentialProvider: async () => fetchCredentialsFromSTS(), }); Using an API key For simpler integration paths (local development, scripts, migration from the first-party Claude API), you can authenticate with an API key instead of SigV4. Your Anthropic account representative provisions API keys for Claude Platform on AWS. ANTHROPIC_AWS_API_KEY=sk-… When apiKey is set, it takes precedence over any SigV4 credentials in the environment. import { createAnthropicAws } from '@ai-sdk/anthropic-aws'; const anthropicAws = createAnthropicAws({ region: 'us-west-2', workspaceId: 'wrkspc_…', apiKey: 'sk-…', }); A callback or promise selects API key authentication and must resolve to a non-empty string. Lookup failures do not switch to SigV4. The caller handles key caching and renewal. Provider Settings SettingDescriptionregionAWS region for the Claude Platform on AWS endpoint. Reads from AWS_REGION if omitted. Required — no fallback default.workspaceIdAnthropic workspace ID for this AWS account. Sent on every request via the anthropic-workspace-id header. Reads from ANTHROPIC_AWS_WORKSPACE_ID if omitted.apiKeyAPI key for x-api-key authentication: string, PromiseLike<string>, or a callback returning either. Callbacks resolve before each request. When provided, used instead of SigV4. Reads from ANTHROPIC_AWS_API_KEY if omitted.accessKeyIdAWS access key ID for SigV4. Reads from AWS_ACCESS_KEY_ID.secretAccessKeyAWS secret access key for SigV4. Reads from AWS_SECRET_ACCESS_KEY.sessionTokenAWS session token for SigV4 (temporary credentials only). Reads from AWS_SESSION_TOKEN.baseURLBase URL override. Defaults to https://aws-external-anthropic.{region}.api.aws/v1.headersCustom headers to include on every request.fetchCustom fetch implementation for testing or middleware.credentialProviderFunction returning dynamic AWS credentials. Overrides accessKeyId, secretAccessKey, and sessionToken. Language Models You can create models that call the Anthropic Messages API on AWS using the provider instance: import { anthropicAws } from '@ai-sdk/anthropic-aws'; const model = anthropicAws('claude-sonnet-5-5'); Model IDs are identical to the first-party Anthropic API. See the Anthropic provider docs for the full list of language model options, prompt caching, computer use, web search, code execution, and Agent Skills. All of these work identically here because Claude Platform on AWS uses Anthropic's runtime directly. Example import { anthropicAws } from '@ai-sdk/anthropic-aws'; import { generateText } from 'ai'; const { text } = await generateText({ model: anthropicAws('claude-sonnet-5-5'), prompt: 'Invent a new holiday and describe its traditions.', }); IAM permissions Your IAM principal needs permission to call the Claude Platform on AWS actions on your workspace. AWS provides three managed policies: AnthropicFullAccess — grants aws-external-anthropic:* on all resources. AnthropicInferenceAccess — grants read actions plus CreateInference, CreateBatchInference, CancelBatchInference, DeleteBatchInference, and CountTokens on all workspaces. This is the minimum for calling models. AnthropicReadOnlyAccess — grants Get*, List*, and CallWithBearerToken on all workspaces. Insufficient for inference. Model Capabilities Use anthropicAwsModelCapabilities(modelId) from @ai-sdk/anthropic-aws to look up a model's declared capabilities and provider options, grouped by endpoint. ModelImage InputObject GenerationTool UsageTool StreamingComputer UseWeb SearchTool SearchCompactionclaude-opus-5-5Conditional: Requires computer_toolset_20260801.claude-opus-5Conditional: Requires computer_20251124 or computer_toolset_20260801.claude-sonnet-5-5Conditional: Requires computer_toolset_20260801.claude-sonnet-5Conditional: Requires computer_20251124 or computer_toolset_20260801.claude-haiku-5-5Conditional: Requires computer_toolset_20260801.claude-fable-5-2Conditional: Requires computer_toolset_20260801.claude-fable-5-1Conditional: Requires computer_20251124 or computer_toolset_20260801.claude-fable-5Conditional: Requires computer_20251124 or computer_toolset_20260801.claude-opus-4-8Conditional: Requires computer_20251124 or computer_toolset_20260801.claude-opus-4-7Conditional: Requires computer_20251124.claude-opus-4-6Conditional: Requires computer_20251124.claude-sonnet-4-6Conditional: Requires computer_20251124.claude-opus-4-5Conditional: Requires computer_20250124 or computer_20251124.claude-haiku-4-5