Amazon Bedrock & Generative AI
Amazon Bedrock gives you access to powerful foundation models, the large models behind chatbots and generative AI, through one managed API. You can use models from several providers, including Anthropic's Claude models, Amazon's own Nova models, and models from Meta, Mistral AI, Cohere and others, without managing any servers or GPUs.
What Bedrock offers
- Many models, one API: switch models by changing a model ID, keeping the same code.
- Serverless: you pay per use, typically per input and output token, with no infrastructure to run. Provisioned throughput and batch options exist for heavier use.
- Your data stays yours: according to AWS, prompts and outputs are not used to train the base models and are not shared with model providers.
- Building blocks: Knowledge Bases (for retrieval-augmented generation), Agents (models that call your APIs), Guardrails (content filters and PII redaction), and model evaluation.
If you are new to how these models work, read How Large Language Models Work and Prompt Engineering first.
Getting access to models
Bedrock is available in many, but not all, Regions, and each model is offered only in certain Regions. Access is controlled per account and Region:
- Open Amazon Bedrock in the console, in a Region where the model you want is offered (for example US East (N. Virginia) or Europe (Frankfurt)). It may not be available in every Region, including Cape Town, so check the model's Region list.
- Browse the model catalogue. Depending on your account and the model, you may need to request or enable access first; some providers, including Anthropic, ask first-time users to submit a short use-case form. AWS has simplified this process over time, so follow what the console shows.
- Make sure your IAM identity is allowed to call Bedrock, for example the
bedrock:InvokeModelaction, which also covers the Converse API. - Copy the exact model ID from the catalogue. Newer models are often called through an inference profile, whose ID starts with a geography prefix (such as
us.oreu.) and can route requests across several Regions.
Model IDs change as new versions are released and old ones are retired. Do not copy a model ID from a blog post or an old tutorial; always copy it from the Bedrock console's model catalogue for your Region.
The Converse API
The Converse API gives one consistent request and response format across Bedrock's chat models. Here is a study assistant for secondary school students:
import boto3
client = boto3.client("bedrock-runtime", region_name="us-east-1")
MODEL_ID = "PASTE-THE-MODEL-ID-FROM-THE-BEDROCK-CONSOLE"
response = client.converse(
modelId=MODEL_ID,
system=[{"text": "You are a friendly tutor for Kenyan secondary school students. "
"Answer in under 80 words, using simple English."}],
messages=[
{"role": "user", "content": [{"text": "What is photosynthesis?"}]},
],
inferenceConfig={"maxTokens": 300, "temperature": 0.3},
)
print(response["output"]["message"]["content"][0]["text"])
print(response["stopReason"])
print(response["usage"]["inputTokens"], response["usage"]["outputTokens"])
This output is only an example: the wording and token counts will differ with each model and each run.
systemsets the model's role and rules.messagesis the conversation so far, alternatinguserandassistantturns.inferenceConfigcontrols length (maxTokens) and randomness (temperature).stopReasontells you why the model stopped, for exampleend_turn(finished) ormax_tokens(cut off).usagereports tokens, which is what you are billed for.
To continue a conversation, append the model's reply and the next user message, then call converse again. The model has no memory between calls; you send the history each time:
messages = [
{"role": "user", "content": [{"text": "What is photosynthesis?"}]},
response["output"]["message"],
{"role": "user", "content": [{"text": "Give me one exam-style question on it."}]},
]
follow_up = client.converse(modelId=MODEL_ID, messages=messages,
inferenceConfig={"maxTokens": 300})
For chat apps where text should appear as it is generated, use converse_stream.
RAG on AWS with Knowledge Bases
A foundation model does not know your school's fee policy or your shop's return rules. Retrieval-augmented generation (RAG) solves this by finding relevant passages from your documents and giving them to the model with the question (see Retrieval-Augmented Generation). Bedrock Knowledge Bases manages the whole pipeline.
After creating a knowledge base in the console (choosing an S3 data source, an embeddings model and a vector store) and syncing it, one call retrieves and answers. The IDs are placeholders; copy yours from the console:
import boto3
agent_runtime = boto3.client("bedrock-agent-runtime", region_name="us-east-1")
response = agent_runtime.retrieve_and_generate(
input={"text": "What happens if school fees are paid late?"},
retrieveAndGenerateConfiguration={
"type": "KNOWLEDGE_BASE",
"knowledgeBaseConfiguration": {
"knowledgeBaseId": "KB12345678",
"modelArn": "PASTE-THE-MODEL-OR-INFERENCE-PROFILE-ARN-FROM-THE-CONSOLE",
},
},
)
print(response["output"]["text"])
for citation in response.get("citations", []):
for ref in citation["retrievedReferences"]:
print("Source:", ref["location"]["s3Location"]["uri"])
Costs and safety
- Tokens cost money: long system prompts, long chat histories and large retrieved chunks are all billed on every call. Set
maxTokens, trim history and check the Bedrock pricing page for each model. - Knowledge base vector stores can have their own ongoing charges even when no one is asking questions. Delete practice knowledge bases and their vector stores.
- Guardrails: use Bedrock Guardrails to block harmful topics and redact personal data, and never let a model's output trigger important actions without validation.
- Hallucinations: models can state wrong facts confidently. RAG with citations helps, and human review matters for anything important.
Key points
- Bedrock provides managed, serverless access to foundation models from several providers, including Anthropic's Claude.
- Check model availability per Region, enable access as the console requires, and copy exact model IDs from the console.
- The Converse API uses one format for all chat models: system, messages and inferenceConfig in; output, stopReason and usage out.
- Knowledge Bases implement RAG over your documents in S3.
- You pay per token; control prompt length and clean up vector stores.
Tip: use the ← and → keys to move between pages.
