Amazon Bedrock makes it possible to work with foundation models through APIs, allowing developers to integrate generative AI capabilities into their applications. This quickstart walks through the basic steps required to send your first inference request using Amazon Bedrock.
Step 1 — Prepare Your AWS Account
To get started, you need an AWS account. If you already have one, you can proceed directly to the next step.
Step 2 — Generate an API Key
Open Amazon Bedrock from the AWS Management Console and generate a short-term API key to authenticate your requests. For production applications, AWS recommends using IAM roles or temporary credentials instead.
Step 3 — Install the Required SDK
Install the SDK based on the API you plan to use:
| API | Required SDK |
| Messages API | boto3 + anthropic |
| Responses / Chat Completions API | boto3 + openai |
| Invoke / Converse API | boto3 |
Python must also be installed on your environment.
Step 4 — Configure Authentication
Set your API key as an environment variable based on the API you selected.
For example:
Message API:
AWS_BEARER_TOKEN_BEDROCK="<provide your Bedrock API key>"
ANTHROPIC_BASE_URL="https://bedrock-runtime.<your-region>.amazonaws.com/anthropic"
Responses / Chat Completions API:
OPENAI_API_KEY="<provide your Bedrock API key>"
OPENAI_BASE_URL="https://bedrock-runtime.<your-region>.amazonaws.com/openai/v1"
Invoke / Converse API:
AWS_BEARER_TOKEN_BEDROCK="<provide your Bedrock API key>"
Step 5 — Choose a Foundation Model
Next, choose the foundation model you want to use for your application. Amazon Bedrock supports 100+ foundation models, giving developers the flexibility to select a model based on their specific requirements.
Messages API:
from anthropic import Anthropic
from aws_bedrock_token_generator import provide_token
token = provide_token(region="us-east-1")
client = Anthropic(api_key=token)
response = client.messages.create(
model="global.anthropic.claude-opus-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Can you explain the features of Amazon Bedrock?"}]
)
print(response)
Responses API:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="openai.gpt-5.6-sol",
input="Can you explain the features of Amazon Bedrock?"
)
print(response)
Chat Completions API:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="openai.gpt-5.6-sol",
messages=[{"role": "user", "content": "Can you explain the features of Amazon Bedrock?"}]
)
print(response)
Converse API:
import boto3
client = boto3.client('bedrock-runtime', region_name='us-east-1')
response = client.converse(
modelId='global.anthropic.claude-opus-5',
messages=[
{
'role': 'user',
'content': [{'text': 'Can you explain the features of Amazon Bedrock?'}]
}
]
)
print(response)
Invoke API:
import json
import boto3
client = boto3.client('bedrock-runtime', region_name='us-east-1')
response = client.invoke_model(
modelId='global.anthropic.claude-opus-5',
body=json.dumps({
'anthropic_version': 'bedrock-2023-05-31',
'messages': [{ 'role': 'user', 'content': 'Can you explain the features of Amazon Bedrock?'}],
'max_tokens': 1024
})
)
print(json.loads(response['body'].read()))
Step 6 — Send Your First Inference Request
Amazon Bedrock supports several APIs for sending inference requests, including:
- Anthropic Messages API
- OpenAI Responses API
- OpenAI Chat Completions API
- Amazon Bedrock Converse API
- Amazon Bedrock Invoke API
For example, using the Converse API, you can send a request to a selected model and provide a prompt such as:
“Can you explain the features of Amazon Bedrock?”
The response generated by the model can then be displayed in your application.
Step 7 — Run Your Python Script
Save your Python code as:
bedrock-first-request.py
Then run it using:
python3 bedrock-first-request.py
If the request is successful, you should see the inference output returned by Amazon Bedrock.
Credit to: AWS Documentation