AWS Bedrock
Use Amazon Bedrock's OpenAI-compatible inference with Anvia.
Amazon Bedrock exposes an OpenAI-compatible chat completions and responses surface at https://bedrock-runtime.{region}.amazonaws.com/openai/v1. In Anvia, configure OpenAIClient with that baseUrl, then pass Bedrock model ids to completionModel(...). Bedrock also supports native Converse and InvokeModel APIs and an Anthropic-SDK Messages endpoint.
Create the Client
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const client = new OpenAIClient({
baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1",
apiKey: process.env.AWS_BEARER_TOKEN_BEDROCK,
});
const model = client.completionModel("anthropic.claude-opus-4-7");
const agent = new AgentBuilder("support", model)
.instructions("Answer support questions clearly.")
.build();
const response = await agent.prompt("Hello!").send();
console.log(response.output);baseUrl makes Anvia use the OpenAI-compatible chat completion adapter. The model id is the Bedrock model id, not an Anvia-specific alias. The region is required because Bedrock endpoints are regional.
Get the Model List
When the OpenAI-compatible surface is enabled for your account, listModels() calls Bedrock's configured /models endpoint and returns the model ids available in the configured region.
const models = await client.listModels();
console.table(
models.data.map((model) => ({
id: model.id,
name: model.name,
contextLength: model.contextLength,
})),
);Use the id field directly with completionModel(...).
Available Models
Bedrock hosts models from Amazon, Anthropic, DeepSeek, Moonshot AI, MiniMax, and OpenAI under stable, namespaced model ids. Sample ids include:
| Model | Provider |
|---|---|
anthropic.claude-opus-4-7 | Anthropic |
anthropic.claude-sonnet-4-6 | Anthropic |
amazon.nova-* | Amazon |
openai.gpt-5.5 | OpenAI (Responses API) |
openai.gpt-5.4 | OpenAI (Responses API) |
openai.gpt-oss-120b | OpenAI (Chat Completions) |
deepseek.* | DeepSeek |
moonshot.kimi-k2-* | Moonshot AI |
minimax.* | MiniMax |
OpenAI-hosted models on Bedrock are exposed through the Responses API rather than chat completions. Switch baseUrl to the Responses-compatible surface or use a chat-compatible model id for completionModel(...).
AWS SigV4 Auth (Optional)
The default OpenAI client uses a bearer token. To use AWS Signature Version 4 with boto3-resolved credentials instead, sign the request in your HTTP layer and forward the resulting Authorization header.
import { SignatureV4 } from "@aws-sdk/signature-v4";
import { Sha256 } from "@aws-crypto/sha256-js";
import { HttpRequest } from "@aws-sdk/protocol-http";
const signer = new SignatureV4({
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? "",
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "",
},
region: "us-east-1",
service: "bedrock",
sha256: Sha256,
});
const request = await signer.sign(
new HttpRequest({
method: "POST",
protocol: "https:",
hostname: "bedrock-runtime.us-east-1.amazonaws.com",
path: "/openai/v1/chat/completions",
headers: { "content-type": "application/json", host: "bedrock-runtime.us-east-1.amazonaws.com" },
body: JSON.stringify({ model: "anthropic.claude-opus-4-7", messages: [] }),
}),
);
const client = new OpenAIClient({
baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1",
apiKey: "unused",
defaultHeaders: {
Authorization: request.headers.authorization,
"x-amz-date": request.headers["x-amz-date"],
"x-amz-security-token": request.headers["x-amz-security-token"] ?? "",
},
});The apiKey value is not used in this mode, but Anvia still expects the field. Pass a placeholder. Use AWS_BEARER_TOKEN_BEDROCK for the simpler bearer-token path with an API key generated in the Bedrock console.
Notes
- Bedrock endpoints are regional. Pick a region that hosts the model you want. Cross-region inference profiles let you reference models across regions.
- Model ids follow a
<provider>.<model>shape, unlike OpenAI's flat namespace. Use the exact id shown in your account's model catalog. - Some models are gated behind AWS form approvals, including Claude Mythos Preview. Check that your account has access before integrating.
- Bedrock also exposes native Converse and InvokeModel APIs through
boto3, plus an Anthropic-SDK-compatible Messages endpoint. Use those when you need model-specific parameters that are not part of the OpenAI surface. - Cost allocation by IAM user and role is available in AWS Cost and Usage Report 2.0 for tagging inference cost to teams and workflows.
For current Bedrock details, see the Amazon Bedrock user guide and the Bedrock supported models.
