
Day 1 - Your First LLM API Call with Amazon Bedrock
Set up Amazon Bedrock with Python and send your first prompt to a foundation model using the Converse API. Learn the essentials of model invocation, authentication, AWS permissions, and token usage through a small hands-on project
Series: 30 Days of AI Engineering on AWS (17 articles)
- 2Day 1 - Your First LLM API Call with Amazon Bedrock This article
Day 1: Your First LLM API Call with Amazon Bedrock
Welcome to Day 1 of 30 Days of AI Engineering on AWS!
Before building AI agents, RAG applications, or complex AI-powered systems, we need to understand one fundamental operation: How does an application communicate with a foundation model?
Today, we'll build our first small application using Amazon Bedrock and Python. We'll send a prompt to a foundation model, receive its response, and inspect the token usage.
No frameworks. No agents. Just our first real model invocation.
1. What are we building?
We'll create a simple Python application that:
- Connects to Amazon Bedrock.
- Sends a text prompt to a foundation model.
- Receives and displays the generated response.
- Displays input and output token usage.
For this exercise, we'll use Amazon Nova Lite through Amazon Bedrock's Converse API.
2. Understanding Amazon Bedrock
Amazon Bedrock is a managed AWS service that provides access to foundation models from Amazon and other model providers through a common set of APIs.
Instead of managing the underlying model infrastructure yourself, you can invoke supported models through Bedrock's runtime APIs.
For new applications, AWS recommends using the
bedrock-runtime endpoint. We'll use its Converse API, which provides a consistent request and response structure across supported models and simplifies multi-turn conversations.3. Prerequisites
Before starting, make sure you have:
- An AWS account.
- Python installed.
- Basic Python knowledge.
- An AWS identity with permission to invoke Amazon Bedrock models.
- An active model available in your selected AWS Region.
For this reproducible example, we'll use:
Configuration | Value |
|---|---|
AWS service | Amazon Bedrock |
SDK | Boto3 |
Model | Amazon Nova Lite |
Model ID | amazon.nova-lite-v1:0 |
Region | us-east-1 |
API | Converse |
The model is currently listed as active, and the model card confirms its in-Region availability in
us-east-1 .4. Set up authentication
For local experimentation, we'll use an Amazon Bedrock short-term API key.
- Open the Amazon Bedrock console.
- Switch to the
us-east-1Region.
- Navigate to API keys.
- Open the Short-term API keys tab.
- Generate a short-term API key.
The key inherits permissions from the IAM identity that generated it and expires with the console session, up to a maximum of 12 hours.
Your identity must have the required model invocation permissions. In particular, the
bedrock:InvokeModel permission authorizes the Converse API operation.Important: Never hardcode API keys in your Python files or commit them to GitHub.
Set the key as an environment variable.
Windows PowerShell:
$env:AWS_BEARER_TOKEN_BEDROCK="YOUR_SHORT_TERM_API_KEY"Linux/macOS:
export AWS_BEARER_TOKEN_BEDROCK="YOUR_SHORT_TERM_API_KEY"5. Install Boto3
Boto3 is the AWS SDK for Python. We'll use it to communicate with Amazon Bedrock.
pip install --upgrade boto3For Bedrock API-key authentication through the
AWS_BEARER_TOKEN_BEDROCK environment variable, AWS documents Boto3 version 1.39.0 or later.6. Make your first model invocation
Create a Python file named:
first_bedrock_call.py Add the following code:
import boto3from botocore.exceptions import BotoCoreError, ClientError
# AWS configurationREGION = "us-east-1"MODEL_ID = "amazon.nova-lite-v1:0"
# Create a Bedrock Runtime clientclient = boto3.client( service_name="bedrock-runtime", region_name=REGION)
# Define the user messagemessages = [ { "role": "user", "content": [ { "text": """ You are a friendly AI engineering tutor.
Explain Generative AI to a first-year computer science student.
Include: 1. What Generative AI means. 2. One real-world example. 3. How a prompt influences the response.
Keep the explanation beginner-friendly. """ } ] }]
try: # Send the request to Amazon Bedrock response = client.converse( modelId=MODEL_ID, messages=messages, inferenceConfig={ "maxTokens": 300, "temperature": 0.3 } )
# Extract the generated response content = response["output"]["message"]["content"]
answer = "\n".join( block["text"] for block in content if "text" in block )
print("\n===== MODEL RESPONSE =====\n") print(answer)
# Display token usage usage = response.get("usage", {})
print("\n===== TOKEN USAGE =====") print("Input tokens:", usage.get("inputTokens", "N/A")) print("Output tokens:", usage.get("outputTokens", "N/A")) print("Total tokens:", usage.get("totalTokens", "N/A"))
except ClientError as error: details = error.response.get("Error", {}) print("AWS Error:", details.get("Code")) print("Message:", details.get("Message"))
except BotoCoreError as error: print("SDK Error:", error)Run the application:
python first_bedrock_call.pyYou should receive a generated explanation in your terminal, followed by token usage information.
Congratulations! You've made your first foundation model invocation using Amazon Bedrock.
7. Understand what happened
Let's break down the important parts of the code.
boto3.client("bedrock-runtime") Creates a client for communicating with the Amazon Bedrock Runtime service.
modelId Identifies the foundation model that will process your request.
messages Contains the conversation input. We use the
user role to send our prompt.client.converse() Sends the request to the selected model and returns its response.
inferenceConfig Controls generation parameters such as the maximum output tokens and temperature.
response["usage"] Provides token usage information, including input, output, and total tokens.
One important distinction: this application is currently a direct model-invocation application, not an AI agent. It sends a prompt and receives a response; it does not independently plan tasks or invoke tools.
8. Your Day 1 challenge
Don't stop after running the example once.
Try these small experiments:
- Change the prompt and ask the model to explain RAG, AI agents, or MCP.
- Change
maxTokensand observe how the output length changes.
- Experiment with different temperature values and compare responses.
- Record the input and output token counts for different prompts.
Observe how changing the request parameters affects the model's response.
9. Important things to remember
- Amazon Bedrock model availability varies by AWS Region.
- Model access and activation requirements can differ by provider.
- Model invocation requires appropriate IAM permissions.
- Amazon Bedrock pricing depends on the model, service tier, and usage. Check the pricing page before experimenting extensively.
- AWS Budget alerts are useful for monitoring costs, but they are not real-time spending limits.
Regional note: This example deliberately uses
us-east-1 , where Nova Lite supports in-Region inference. In ap-south-1 (Mumbai), Nova Lite supports APAC geographic cross-Region inference rather than in-Region inference. Its APAC inference profile can route requests to multiple supported APAC Regions. Check the model's regional availability before switching Regions, especially when data residency matters.Day 1 Complete!
Today, we learned how to connect a Python application to Amazon Bedrock, invoke a foundation model, handle its response, and inspect token usage.
This is the foundation for everything we'll build in the coming days.
Next, we'll move beyond a single prompt and explore how to design better prompts and make model outputs more useful for real applications.
30 Days. 30 Tasks. Real AI Building.
See you on Day 2!
Official References
Series: 30 Days of AI Engineering on AWS (17 articles)
- 2Day 1 - Your First LLM API Call with Amazon Bedrock This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article