-
-
Notifications
You must be signed in to change notification settings - Fork 352
feat(ai-bedrock): add Amazon Bedrock adapter (Converse default + OpenAI-compatible chat/responses) #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(ai-bedrock): add Amazon Bedrock adapter (Converse default + OpenAI-compatible chat/responses) #665
Changes from 44 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
885b05b
chore(ai-bedrock): scaffold package
AlemTuzlak 19ff7b0
chore(ai-bedrock): make aws-sigv4-fetch an optional peer dep; revert β¦
AlemTuzlak 12797e9
chore(ai-bedrock): drop aws-sigv4-fetch from manifest (user-installedβ¦
AlemTuzlak 3805d52
feat(ai-bedrock): client config + auth resolution (apikey + SigV4 casβ¦
AlemTuzlak 3fa84ba
fix(ai-bedrock): close apikey-mode fall-through; robust env test restβ¦
AlemTuzlak 8498890
feat(ai-bedrock): SigV4 signing fetch behind /sigv4 subpath
AlemTuzlak 00b4ae6
feat(ai-bedrock): message metadata + chat/responses provider options
AlemTuzlak 0f09fe9
feat(ai-bedrock): seed model catalog (broad chat + responses subset)
AlemTuzlak fbdf6ef
fix(ai-bedrock): compile-time parity guard for model catalog arrays
AlemTuzlak aa8ac3d
feat(ai-bedrock): chat adapter with cast-free reasoning extraction
AlemTuzlak 6944266
test(ai-bedrock): cover empty-string + non-array-choices reasoning guβ¦
AlemTuzlak a42d7ee
feat(ai-bedrock): responses adapter (mantle-only) on OpenAI Responsesβ¦
AlemTuzlak d11eb3f
feat(ai-bedrock): branching bedrockText factory (api: chat | responses)
AlemTuzlak cdc5f51
fix(ai-bedrock): export ResolvedBedrockAuth; lock api:responses type+β¦
AlemTuzlak 7f5459c
chore(ai-bedrock): add maintainer model-catalog refresh script
AlemTuzlak 33778ca
test(e2e): register bedrock + bedrock-responses providers
AlemTuzlak 0c35a85
test(e2e): add feature coverage for bedrock-responses
AlemTuzlak 3ef2bbd
docs(ai-bedrock): adapter guide, nav, changeset
AlemTuzlak a0050c5
docs(ai-bedrock): register Bedrock in gap-analysis skill and providerβ¦
AlemTuzlak 13b5bb6
docs(ai-bedrock): move Bedrock to first-party adapters section
AlemTuzlak 89567f3
fix(ai-bedrock): SigV4 service for mantle; canonical versioned gpt-osβ¦
AlemTuzlak f8460d2
ci: apply automated fixes
autofix-ci[bot] 6ccd207
fix(ai-bedrock): address review β lazy auth in bedrockText, authoritaβ¦
AlemTuzlak 6ac6e40
docs(ai-bedrock): keep config.json diff to just the Bedrock nav entry
AlemTuzlak 7b3632b
chore(ai-bedrock): add @aws-sdk client, drop aws-sigv4-fetch optionalβ¦
AlemTuzlak 43d973f
feat(ai-bedrock): unified discriminated auth resolver (bearer | sigv4)
AlemTuzlak b9fabb5
refactor(ai-bedrock): sign openai-SDK path with @aws-sdk signer; remoβ¦
AlemTuzlak 63d67fe
fix(ai-bedrock): handle Request input in createSigV4Fetch; simplify bβ¦
AlemTuzlak 57e15ce
feat(ai-bedrock): generate model catalog with per-API support flags
AlemTuzlak 63b0bc9
feat(ai-bedrock): three per-API catalogs (converse default) + curatedβ¦
AlemTuzlak 8602e82
feat(ai-bedrock): Converse message converter (system, role merge, tooβ¦
AlemTuzlak f345d08
feat(ai-bedrock): Converse tool & tool-choice converter
AlemTuzlak 0357dab
feat(ai-bedrock): Converse stream -> AG-UI StreamChunk processor
AlemTuzlak 878b615
feat(ai-bedrock): Converse structured output via forced single-tool
AlemTuzlak b1a3b4b
feat(ai-bedrock): BedrockConverseTextAdapter (streaming, tools, strucβ¦
AlemTuzlak 4b628f8
feat(ai-bedrock): converse is the default bedrockText path; chat/respβ¦
AlemTuzlak 8cac582
docs(e2e): document Bedrock Converse coverage gap (aimock lacks AWS eβ¦
AlemTuzlak bc75c30
docs: restore nav entries dropped by stale config.json rewrite; keep β¦
AlemTuzlak f0bd676
docs(ai-bedrock): document Converse-as-default + opt-in chat/responses
AlemTuzlak 9bb6011
chore(ai-bedrock): satisfy PR quality gate (lint, knip, format); dropβ¦
AlemTuzlak b5a15e7
fix(ai-bedrock): give Converse document blocks unique names
AlemTuzlak 6a4e71e
fix(ai-bedrock): keep AWS SDK out of the browser bundle via non-literβ¦
AlemTuzlak ee3173c
fix(e2e): pin bedrock matrix entry to api: 'chat' (Converse is now thβ¦
AlemTuzlak 5665872
Merge remote-tracking branch 'origin/main' into feat/ai-bedrock-adapter
AlemTuzlak 6b8a81d
fix(bedrock): align openai dep and adapt to post-merge API changes
AlemTuzlak 16a73d6
fix(bedrock): address review feedback (tool choice none, client retryβ¦
AlemTuzlak 4bb126a
fix(bedrock): address maintainer review (structured output, model guaβ¦
AlemTuzlak 2078a77
fix(bedrock): surface in-band Converse errors, honest provider optionβ¦
tombeckenham 35db8fa
ci: apply automated fixes
autofix-ci[bot] 12ba505
fix(bedrock): prefer bearer auth scheme so the Bedrock API key is honβ¦
tombeckenham 8a607a7
chore(examples): add Bedrock provider to ts-react-chat
tombeckenham a4cac44
chore(examples): add SigV4 auth toggle for Bedrock in ts-react-chat
tombeckenham 21d7db0
Merge remote-tracking branch 'origin/main' into feat/ai-bedrock-adapter
tombeckenham 69dfbd5
fix(bedrock): order type import after value imports (import/order)
tombeckenham 2074006
Merge branch 'main' into feat/ai-bedrock-adapter
AlemTuzlak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/ai-bedrock': minor | ||
| --- | ||
|
|
||
| Add `@tanstack/ai-bedrock`: an Amazon Bedrock adapter. The default `bedrockText` path uses Bedrock's **Converse** API (`@aws-sdk/client-bedrock-runtime`), reaching the broad chat catalog including Anthropic Claude, Amazon Nova, and Meta Llama, with streaming, tools, reasoning, and structured output. Opt into Bedrock's OpenAI-compatible endpoints with `api: 'chat'` (Chat Completions) or `api: 'responses'` (gpt-oss Responses). Authentication supports Bedrock API keys or SigV4 via the AWS credential chain. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| --- | ||
| title: Amazon Bedrock | ||
| id: bedrock-adapter | ||
| order: 7 | ||
| description: "Use Amazon Bedrock with TanStack AI β the Converse API is the default, reaching Claude, Nova, Llama, Mistral, DeepSeek, and more. Opt into OpenAI-compatible Chat Completions or Responses for open-weight and gpt-oss models. Supports streaming, tools, reasoning, and API-key or SigV4 auth." | ||
| keywords: | ||
| - tanstack ai | ||
| - amazon bedrock | ||
| - aws | ||
| - bedrock | ||
| - converse api | ||
| - openai compatible | ||
| - chat completions | ||
| - responses api | ||
| - sigv4 | ||
| - claude | ||
| - nova | ||
| - llama | ||
| - adapter | ||
| --- | ||
|
|
||
| The Bedrock adapter connects TanStack AI to [Amazon Bedrock](https://aws.amazon.com/bedrock/) with three API paths: | ||
|
|
||
| - **Converse** (default) β Bedrock's model-agnostic API built on `@aws-sdk/client-bedrock-runtime`. Reaches the broad chat catalog including Anthropic Claude, Amazon Nova, Meta Llama, Mistral, DeepSeek, Cohere, AI21, and OpenAI gpt-oss models. | ||
| - **Chat Completions** (`api: 'chat'`) β Bedrock's OpenAI-compatible Chat Completions endpoint. Reaches open-weight models only (gpt-oss, DeepSeek V3.x, Gemma, Qwen, Mistral open models, GLM, etc.). Does NOT reach Claude, Nova, or Llama. | ||
| - **Responses** (`api: 'responses'`) β Bedrock's OpenAI-compatible Responses API, mantle-only. Currently the OpenAI gpt-oss family. | ||
|
|
||
| All paths support streaming, client-side tool calling, and reasoning. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @tanstack/ai-bedrock | ||
| ``` | ||
|
|
||
| No additional packages are required. SigV4 authentication is handled by `@aws-sdk/client-bedrock-runtime`, which is a direct dependency. | ||
|
|
||
| ## Quick Start (Converse β default) | ||
|
|
||
| The default `bedrockText` call uses the Converse API and reaches the broad model catalog: | ||
|
|
||
| ```typescript | ||
| import { bedrockText } from '@tanstack/ai-bedrock' | ||
| import { chat } from '@tanstack/ai' | ||
|
|
||
| const adapter = bedrockText('us.anthropic.claude-haiku-4-5-20251001-v1:0', { | ||
| region: 'us-east-1', | ||
| }) | ||
|
|
||
| for await (const chunk of chat({ | ||
| adapter, | ||
| messages: [{ role: 'user', content: 'What is the capital of France?' }], | ||
| })) { | ||
| if (chunk.type === 'content') process.stdout.write(chunk.delta) | ||
| } | ||
| ``` | ||
|
|
||
| Equivalent to passing `{ api: 'converse' }` explicitly. Returns a `bedrock-converse` adapter. | ||
|
|
||
| ## Authentication | ||
|
|
||
| Bedrock supports two authentication modes. | ||
|
|
||
| ### API Key | ||
|
|
||
| Bedrock issues API keys from the AWS Console. See the [Bedrock API keys guide](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html) for instructions. | ||
|
|
||
| Set one of the following environment variables and the adapter picks it up automatically: | ||
|
|
||
| ```bash | ||
| BEDROCK_API_KEY=your-bedrock-api-key | ||
| # or the legacy name: | ||
| AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key | ||
| ``` | ||
|
|
||
| ### SigV4 (AWS credential chain) | ||
|
|
||
| For workloads using IAM roles, instance profiles, or `~/.aws/credentials`, set `auth: 'sigv4'` (or leave it as `'auto'` with no API key in the environment). SigV4 works out of the box via `@aws-sdk/client-bedrock-runtime` β no additional packages required. | ||
|
|
||
| ```bash | ||
| AWS_ACCESS_KEY_ID=... | ||
| AWS_SECRET_ACCESS_KEY=... | ||
| AWS_SESSION_TOKEN=... # optional, for temporary credentials | ||
| ``` | ||
|
|
||
| ### Auth resolution order (`auth: 'auto'`, the default) | ||
|
|
||
| 1. Explicit `apiKey` passed to the factory | ||
| 2. `BEDROCK_API_KEY` environment variable | ||
| 3. `AWS_BEARER_TOKEN_BEDROCK` environment variable | ||
| 4. SigV4 via the standard AWS credential chain | ||
|
|
||
| ## Configuration | ||
|
|
||
| `BedrockClientConfig` accepts the following options: | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `api` | `'converse' \| 'chat' \| 'responses'` | `'converse'` | Bedrock API to use | | ||
| | `region` | `string` | `'us-east-1'` | AWS region string (e.g. `'us-west-2'`) | | ||
| | `auth` | `'apikey' \| 'sigv4' \| 'auto'` | `'auto'` | Authentication mode | | ||
| | `apiKey` | `string` | β | Explicit API key (overrides env vars) | | ||
| | `baseURL` | `string` | β | Override the computed base URL entirely | | ||
| | `endpoint` | `'runtime' \| 'mantle'` | `'runtime'` | Bedrock endpoint to target (Chat Completions path only) | | ||
|
|
||
| The `endpoint` option only applies when `api: 'chat'`. The `runtime` endpoint (`bedrock-runtime`) hosts the broad open-weight catalog; `mantle` is an alternative. The Responses API always targets mantle. | ||
|
|
||
| ## Converse API (default) | ||
|
|
||
| `bedrockText(model)` or `bedrockText(model, { api: 'converse' })` returns a `bedrock-converse` adapter backed by `@aws-sdk/client-bedrock-runtime`. This is Bedrock's model-agnostic conversational API and is the recommended path for most use cases. | ||
|
|
||
| **Model scope:** Anthropic Claude, Amazon Nova, Meta Llama, Mistral, DeepSeek, Cohere, AI21, OpenAI gpt-oss, and other models accessible in your account. See [Model availability](#model-availability) below. | ||
|
|
||
| ```typescript | ||
| import { bedrockText } from '@tanstack/ai-bedrock' | ||
| import { chat } from '@tanstack/ai' | ||
|
|
||
| // Claude via Converse | ||
| const claudeAdapter = bedrockText('us.anthropic.claude-haiku-4-5-20251001-v1:0', { | ||
| region: 'us-east-1', | ||
| }) | ||
|
|
||
| // Amazon Nova via Converse | ||
| const novaAdapter = bedrockText('us.amazon.nova-pro-v1:0', { | ||
| region: 'us-east-1', | ||
| }) | ||
|
|
||
| // Meta Llama via Converse | ||
| const llamaAdapter = bedrockText('us.meta.llama3-3-70b-instruct-v1:0', { | ||
| region: 'us-east-1', | ||
| }) | ||
| ``` | ||
|
|
||
| ### Explicit API key (Converse) | ||
|
|
||
| ```typescript | ||
| import { createBedrockText } from '@tanstack/ai-bedrock' | ||
|
|
||
| const adapter = createBedrockText( | ||
| 'us.anthropic.claude-haiku-4-5-20251001-v1:0', | ||
| 'your-bedrock-api-key', | ||
| { region: 'us-west-2' }, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Chat Completions API (`api: 'chat'`) | ||
|
|
||
| Set `api: 'chat'` to use Bedrock's OpenAI-compatible Chat Completions endpoint. Returns a `bedrock` adapter. | ||
|
|
||
| **Model scope:** Open-weight models only β gpt-oss, DeepSeek V3.x, Gemma, Qwen, Mistral open models, GLM, and similar. Claude, Nova, and Llama are NOT available on this endpoint. See the [AWS API compatibility matrix](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html) for the current list. | ||
|
|
||
| ```typescript | ||
| import { bedrockText } from '@tanstack/ai-bedrock' | ||
| import { chat } from '@tanstack/ai' | ||
|
|
||
| const adapter = bedrockText('openai.gpt-oss-mini-1:0', { | ||
| region: 'us-east-1', | ||
| api: 'chat', | ||
| }) | ||
|
|
||
| for await (const chunk of chat({ | ||
| adapter, | ||
| messages: [{ role: 'user', content: 'What is the capital of France?' }], | ||
| })) { | ||
| if (chunk.type === 'content') process.stdout.write(chunk.delta) | ||
| } | ||
| ``` | ||
|
|
||
| ## Responses API (`api: 'responses'`) | ||
|
|
||
| Set `api: 'responses'` to use Bedrock's OpenAI-compatible Responses API. Returns a `bedrock-responses` adapter. This API is mantle-only. | ||
|
|
||
| **Model scope:** Currently the OpenAI gpt-oss family. The Responses API is stateful β pass `previous_response_id` and `store` through `modelOptions` to continue a conversation server-side. | ||
|
|
||
| ```typescript | ||
| import { bedrockText } from '@tanstack/ai-bedrock' | ||
| import { chat } from '@tanstack/ai' | ||
|
|
||
| const adapter = bedrockText('openai.gpt-oss-120b-1:0', { | ||
| region: 'us-east-1', | ||
| api: 'responses', | ||
| }) | ||
|
|
||
| for await (const chunk of chat({ | ||
| adapter, | ||
| messages: [{ role: 'user', content: 'Summarize the Bedrock pricing page.' }], | ||
| })) { | ||
| if (chunk.type === 'content') process.stdout.write(chunk.delta) | ||
| } | ||
| ``` | ||
|
|
||
| ## Model Availability | ||
|
|
||
| The adapter ships with a hand-seeded snapshot catalog (`src/model-catalog.generated.ts`) of confirmed model IDs. This catalog can be refreshed by the maintainer script `scripts/fetch-bedrock-models.ts`, which calls `ListFoundationModels` with AWS credentials. | ||
|
|
||
| **Actual model availability depends on your AWS account's model access configuration and the region you are targeting.** Enable model access in the [Amazon Bedrock console](https://console.aws.amazon.com/bedrock/home#/modelaccess) before use. | ||
|
|
||
| For the full list of models and which API endpoints they support, see the [AWS API compatibility matrix](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html). | ||
|
|
||
| ## Supported Capabilities | ||
|
|
||
| - Streaming chat completions | ||
| - Client-side tool calling | ||
| - Reasoning (extended thinking) | ||
| - Multimodal input (text, images, documents β model-dependent) | ||
| - JSON schema / structured output | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### `bedrockText(model, config?)` | ||
|
|
||
| Creates a Bedrock adapter using environment-variable auth. | ||
|
|
||
| - `model` β Model ID (e.g. `'us.anthropic.claude-haiku-4-5-20251001-v1:0'`) | ||
| - `config.api` β `'converse'` (default), `'chat'`, or `'responses'` | ||
| - `config.region` β AWS region string (default `'us-east-1'`) | ||
| - `config.auth` β `'auto'` (default), `'apikey'`, or `'sigv4'` | ||
| - `config.apiKey` β Explicit API key (overrides env vars) | ||
| - `config.baseURL` β Override base URL | ||
| - `config.endpoint` β `'runtime'` (default) or `'mantle'` (Chat Completions path only) | ||
|
|
||
| Returns a chat adapter for use with `chat()` or `generate()`. | ||
|
|
||
| | `api` value | Adapter name | Underlying SDK | | ||
| |---|---|---| | ||
| | `'converse'` (default) | `bedrock-converse` | `@aws-sdk/client-bedrock-runtime` | | ||
| | `'chat'` | `bedrock` | `openai` (OpenAI-compatible) | | ||
| | `'responses'` | `bedrock-responses` | `openai` (OpenAI-compatible) | | ||
|
|
||
| ### `createBedrockText(model, apiKey, config?)` | ||
|
|
||
| Creates a Bedrock adapter with an explicit API key, bypassing the environment-variable lookup. | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - [Amazon Bedrock API keys](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html) β Create and manage API keys | ||
| - [Amazon Bedrock model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) β Enable models in your account | ||
| - [AWS API compatibility matrix](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html) β Which models work with which APIs | ||
| - [Converse API reference](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) β Native Converse API docs | ||
| - [Streaming Guide](../chat/streaming) β Learn about streaming responses | ||
| - [Tools Guide](../tools/tools) β Learn about tool calling | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.