Skip to content
Kuza Ndoto Academy

Amazon Bedrock & Generative AI

Beginner → IntermediateChapter 6 · Page 23 of 305 min readUpdated 15 Nov 2026

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:

  1. 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.
  2. 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.
  3. Make sure your IAM identity is allowed to call Bedrock, for example the bedrock:InvokeModel action, which also covers the Converse API.
  4. 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. or eu.) and can route requests across several Regions.
Warning

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"])
Photosynthesis is how green plants make their own food. Their leaves take in sunlight, carbon dioxide from the air and water from the soil. Using the green pigment chlorophyll, they turn these into glucose (a sugar) for energy and growth, and release oxygen into the air. That oxygen is what we breathe! end_turn 41 68

This output is only an example: the wording and token counts will differ with each model and each run.

  • system sets the model's role and rules.
  • messages is the conversation so far, alternating user and assistant turns.
  • inferenceConfig controls length (maxTokens) and randomness (temperature).
  • stopReason tells you why the model stopped, for example end_turn (finished) or max_tokens (cut off).
  • usage reports 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.

1 Ingest (ahead of time) Documentsin S3 Knowledge Basechunk + embed Vector store 2 Query (each question) User Your app similarity search top chunks question + chunks Foundation modele.g. Claude, via Bedrock answer with citations
Figure 1. Ingestion happens once (and again when documents change). For each question, the most similar chunks are retrieved and passed to the model, so answers are grounded in your own documents and can cite them.

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.
Up next · New chapter: Operations & CostMonitoring with CloudWatchMetrics, logs, alarms and dashboards.
→

Tip: use the ← and → keys to move between pages.