claude-bedrock-client
v1.0.0
Published
Invoke Anthropic Claude models through AWS Bedrock — simple, credential-free wrapper around @anthropic-ai/bedrock-sdk
Maintainers
Readme
claude-bedrock-client
Invoke Anthropic Claude models through AWS Bedrock with a simple, clean API. Built on top of @anthropic-ai/bedrock-sdk.
Installation
npm install claude-bedrock-clientAWS Credential Setup
This package reads credentials from environment variables or your ~/.aws/credentials file — no credentials are ever hardcoded.
Option 1 — Environment variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION=us-east-1Or in a .env file (add .env to your .gitignore):
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1Option 2 — AWS credentials file
Configure credentials with the AWS CLI:
aws configureThis writes to ~/.aws/credentials and is picked up automatically.
IAM permissions required
Your IAM user or role needs:
{
"Effect": "Allow",
"Action": ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"],
"Resource": "arn:aws:bedrock:*::foundation-model/anthropic.*"
}Make sure Claude model access is enabled in the AWS Bedrock console for your region.
Usage
Basic chat
const { invokeClaude } = require('claude-bedrock-client');
const response = await invokeClaude([
{ role: 'user', content: 'What is the capital of France?' }
]);
for (const block of response.content) {
if (block.type === 'text') console.log(block.text);
}
// → Paris is the capital of France.Multi-turn conversation
const { invokeClaude } = require('claude-bedrock-client');
const response = await invokeClaude(
[
{ role: 'user', content: 'My name is Ankit.' },
{ role: 'assistant', content: 'Hello Ankit! Nice to meet you.' },
{ role: 'user', content: "What's my name?" },
],
{
system: 'You are a helpful assistant.',
maxTokens: 256,
}
);Streaming
const { streamClaude } = require('claude-bedrock-client');
const finalMessage = await streamClaude(
[{ role: 'user', content: 'Write a haiku about the ocean.' }],
{
onChunk: (text) => process.stdout.write(text),
}
);
console.log(`\nTokens — in: ${finalMessage.usage.input_tokens}, out: ${finalMessage.usage.output_tokens}`);Custom model / region
const { invokeClaude } = require('claude-bedrock-client');
const response = await invokeClaude(
[{ role: 'user', content: 'Hello' }],
{
model: 'us.anthropic.claude-haiku-4-5',
maxTokens: 512,
region: 'us-west-2',
}
);Low-level client access
const { createClient } = require('claude-bedrock-client');
const client = createClient({ region: 'eu-central-1' });
// client is a fully configured AnthropicBedrock instance
const response = await client.messages.create({ ... });API
invokeClaude(messages, options?)
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| messages | Array<{role, content}> | required | Conversation turns |
| options.model | string | us.anthropic.claude-sonnet-4-6 | Bedrock model ID |
| options.maxTokens | number | 1024 | Max output tokens |
| options.system | string | — | System prompt |
| options.region | string | AWS_REGION env / us-east-1 | AWS region |
| options.accessKey | string | AWS_ACCESS_KEY_ID env | AWS access key |
| options.secretKey | string | AWS_SECRET_ACCESS_KEY env | AWS secret key |
Returns: Promise<BedrockResponse>
streamClaude(messages, options?)
Same options as invokeClaude, plus:
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| options.maxTokens | number | 512 | Max output tokens |
| options.onChunk | Function | — | Called with each text chunk |
Returns: Promise<FinalMessage> (includes usage stats)
createClient(options?)
Returns a raw AnthropicBedrock client for advanced usage.
Constants
const { DEFAULT_MODEL, DEFAULT_REGION } = require('claude-bedrock-client');
// DEFAULT_MODEL → 'us.anthropic.claude-sonnet-4-6'
// DEFAULT_REGION → 'us-east-1'Running the example
# Copy and fill in your credentials
cp .env.example .env # edit .env with your AWS keys
node example/index.jsLicense
MIT
