Anthropic Bedrock TypeScript API Library

This library provides convenient access to the Anthropic Bedrock API.
For the non-Bedrock Anthropic API at api.anthropic.com, see @anthropic-ai/sdk
.
Installation
npm install @anthropic-ai/bedrock-sdk
Usage
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
const client = new AnthropicBedrock();
async function main() {
const message = await client.messages.create({
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
messages: [
{
role: 'user',
content: 'Hello!',
},
],
max_tokens: 1024,
});
console.log(message);
}
main();
Custom Credential Provider (for non-Node environments)
For non-Node environments like Vercel Edge Runtime where the default AWS credential provider chain isn't available, you can provide a custom credential resolver:
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
const customCredentialProvider = async () => {
return {
accessKeyId: 'your-aws-access-key-id',
secretAccessKey: 'your-aws-secret-access-key',
sessionToken: 'your-aws-session-token',
};
};
const client = new AnthropicBedrock({
awsRegion: 'us-east-1',
providerChainResolver: async () => {
return customCredentialProvider;
},
});
For more details on how to use the SDK, see the README.md for the main Anthropic SDK which this library extends.
Requirements
TypeScript >= 4.5 is supported.
The following runtimes are supported:
- Node.js 18 LTS or later (non-EOL) versions.
- Deno v1.28.0 or higher, using
import { AnthropicBedrock } from "npm:@anthropic-ai/bedrock-sdk"
.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
- Jest 28 or greater with the
"node"
environment ("jsdom"
is not supported at this time).
- Nitro v2.6 or greater.
Note that React Native is not supported at this time.
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
0.25.0 (2024-07-29)
Full Changelog: sdk-v0.24.3...sdk-v0.25.0
Features
- add back compat alias for InputJsonDelta (8b08161)
- client: make request-id header more accessible (#462) (5ea6f8b)
Bug Fixes
- compat: remove ReadableStream polyfill redundant since node v16 (#478) (75f5710)
- use relative paths (#475) (a8ca93c)
Chores
- bedrock: use
chunk
for internal SSE parsing instead of completion
(#472) (0f6190a)
- ci: also run workflows for PRs targeting
next
(#464) (cc405a8)
- docs: fix incorrect client var names (#479) (a247935)
- docs: mention lack of support for web browser runtimes (#468) (968a7fb)
- docs: minor update to formatting of API link in README (#467) (50b9f2b)
- docs: rename anthropic const to client (#471) (e1a7f9f)
- docs: use client instead of package name in Node examples (#469) (8961ebf)
- internal: add constant for default timeout (#480) (dc89753)
- internal: minor changes to tests (#465) (c1fd563)
- internal: remove old reference to check-test-server (8dc9afc)
- sync spec (#470) (b493aa4)
- tests: update prism version (#473) (6f21ecf)
Refactors
- extract model out to a named type and rename partialjson (#477) (d2d4e36)