AWS Bedrock

Portkey provides a robust and secure gateway to facilitate the integration of various Large Language Models (LLMs) into your applications, including models hosted on AWS Bedrock.

With Portkey, you can take advantage of features like fast AI gateway access, observability, prompt management, and more, all while ensuring the secure management of your LLM API keys through a virtual key system.

Portkey SDK Integration with AWS Bedrock

Portkey provides a consistent API to interact with models from various providers. To integrate Bedrock with Portkey:

1. Install the Portkey SDK

Add the Portkey SDK to your application to interact with Anthropic's API through Portkey's gateway.

npm install --save portkey-ai

2. Initialize Portkey with the Virtual Key

Set up Portkey with your virtual key as part of the initialization configuration. You can create a virtual key for AWS Bedrock in the UI.

You can navigate to the Virtual Keys tab of your Portkey account and create a Key for AWS Bedrock that'll make it easier to make calls. You'll need the AWS Secret Access Key and AWS Access Key Id to create the virtual key.

import Portkey from 'portkey-ai'
 
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
    virtualKey: "VIRTUAL_KEY" // Your Bedrock Virtual Key
})

Using Virtual Key with AWS STS

If you're using AWS Security Token Service, you can pass your aws_session_token along with the Virtual key:

import Portkey from 'portkey-ai'
 
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
    virtualKey: "VIRTUAL_KEY" // Your Bedrock Virtual Key,
    aws_session_token: "<aws_session_token>"
})

Not using Virtual Keys?

Check out this example on how you can directly use your AWS details to make a Bedrock request through Portkey.

3. Invoke Chat Completions with AWS bedrock

Use the Portkey instance to send requests to Anthropic. You can also override the virtual key directly in the API call if needed.

const chatCompletion = await portkey.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'anthropic.claude-v2:1',
    max_tokens: 250 // Required field for Anthropic
});

console.log(chatCompletion.choices);

Using Vision Models

Portkey's multimodal Gateway fully supports Bedrock's vision models anthropic.claude-3-sonnet, anthropic.claude-3-haiku, and anthropic.claude-3-opus

For more info, check out this guide:

pageVision

Managing AWS Bedrock Prompts

You can manage all prompts to AWS bedrock in the Prompt Library. All the current models of Anthropic are supported and you can easily start testing different prompts.

Once you're ready with your prompt, you can use the portkey.prompts.completions.create interface to use the prompt in your application.

Making Requests without Virtual Keys

If you do not want to add your AWS details to Portkey vault, you can also directly pass them while instantiating the Portkey client.

Mapping the Azure Details

Node SDKPython SDKREST Headers

awsAccessKeyId

aws_access_key_id

x-portkey-aws-session-token

awsSecretAccessKey

aws_secret_access_key

x-portkey-aws-secret-access-key

awsRegion

aws_region

x-portkey-aws-region

awsSessionToken

aws_session_token

x-portkey-aws-session-token

Example

import Portkey from 'portkey-ai'
 
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",
    provider: "bedrock",
    awsAccessKeyId: "AWS_ACCESS_KEY_ID",
    awsSecretAccessKey: "AWS_SECRET_ACCESS_KEY",
    awsRegion: "us-east-1",
    awsSessionToken: "AWS_SESSION_TOKEN"
})

Supported Models

Model NameModel String to Use in API calls

Amazon Titan Text Express

amazon.titan-text-express-v1

Amazon Titan Lite

amazon.titan-text-lite-v1

Amazon Titan Embeddings

amazon.titan-embed-text-v1

Anthropic Claude 1

anthropic.claude-v1

Anthropic Claude 2

anthropic.claude-v2

Anthropic Claude 2.1

anthropic.claude-v2:1

Anthropic Claude Instant 1

anthropic.claude-instant-v1

Anthropic Claude 3 Sonnet

anthropic.claude-3-sonnet-20240229-v1:0

AI21 J2 Mid

ai21.j2-mid-v1

AI21 J2 Ultra

ai21.j2-ultra-v1

Cohere Command

cohere.command-text-v14

Cohere Command Light

cohere.command-light-text-v14

Cohere Embeddings (English)

cohere.embed-english-v3

Cohere Embeddings (multilingual)

cohere.embed-multilingual-v3

Meta Llama2 13B Chat

meta.llama2-13b-chat-v1

Meta Llama2 70B Chat

meta.llama2-70b-chat-v1

Stability Image Generation models

All

Next Steps

The complete list of features supported in the SDK are available on the link below.

pagePortkey SDK Client

You'll find more information in the relevant sections:

Last updated