Amazon Bedrock and Foundation Models: How LLMs Work
Generative AI creates new content – text, code, images – from instructions. It is powered by foundation models (FMs): very large neural networks pre-trained on huge datasets and adaptable to many tasks. Amazon Bedrock gives you many FMs through one managed API, inside your AWS security boundary.
How an LLM works – the essentials
flowchart LR
P["Prompt text"] --> T["Tokenizer<br/>'Explain RAG' → [8, 1734, 49]"]
T --> M["Transformer model<br/>predicts the next token,<br/>again and again"]
M --> S["Sampling<br/>temperature · top-p"]
S --> O["Output tokens → text"]
| Concept | Meaning |
|---|---|
| Token | Unit of text (~4 characters / ¾ of an English word). Limits and prices are in tokens |
| Next-token prediction | The model repeatedly predicts the most likely continuation |
| Context window | Max tokens of input + output the model can consider (e.g. 128K–300K) |
| Pre-training / instruction tuning | General language knowledge, then trained to follow instructions and chat |
| Hallucination | Fluent but wrong output – mitigated with RAG, low temperature, guardrails, citations |
| Embeddings | Vectors representing meaning – used for search and RAG |
Models on Bedrock
| Provider | Examples | Strengths |
|---|---|---|
| Amazon | Nova Micro / Lite / Pro, Titan Embeddings | Low cost, multimodal (Lite/Pro), embeddings |
| Anthropic | Claude Haiku, Claude Sonnet | Reasoning, coding, tool use for agents |
| Meta | Llama 3.x | Open weights, good value |
| Mistral AI | Mistral Large | Multilingual reasoning |
| Cohere | Embed, Command | Search and RAG |
Third-party models need model access to be enabled for the account; some regions require a cross-Region inference profile ID (e.g. apac.anthropic…).
Calling a model – the Converse API
import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';
const client = new BedrockRuntimeClient({});
const res = await client.send(new ConverseCommand({
modelId: 'amazon.nova-lite-v1:0',
system: [{ text: 'You are a concise assistant.' }],
messages: [{ role: 'user', content: [{ text: 'Explain RAG in two sentences.' }] }],
inferenceConfig: { maxTokens: 300, temperature: 0.3, topP: 0.9 },
}));
console.log(res.output.message.content[0].text, res.usage); // { inputTokens, outputTokens }
- Converse – one request format for every chat model (also supports tool use and guardrails); ConverseStream streams tokens.
- InvokeModel – model-specific JSON body (needed for embeddings).
- IAM action:
bedrock:InvokeModel(also covers Converse).
Inference parameters
| Parameter | Effect | Typical value |
|---|---|---|
| temperature | Randomness of sampling | 0–0.2 extraction/classification; 0.7+ creative |
| topP | Sample only from the most likely tokens covering P probability | 0.9 |
| maxTokens | Upper limit of output – stop reason max_tokens when hit |
Enough for the task |
| stopSequences | Stop when a string appears | "###" |
Cost and choice
Cost = input tokens × input price + output tokens × output price (per 1,000 tokens). Choose the smallest model that meets quality, cap maxTokens, cache repeated work, and consider batch inference or provisioned throughput at scale.
| Need | Start with |
|---|---|
| Cheap, fast classification/extraction | Nova Micro / Lite, Claude Haiku |
| Complex reasoning, coding, agents | Claude Sonnet, Nova Pro |
| Embeddings for RAG | Titan Text Embeddings V2, Cohere Embed |
Your prompts and outputs are not used to train the providers’ models; data stays in your Region and account boundary. Access is controlled with IAM, logged in CloudTrail, and metered in tokens.
Practise it
Virtual lab · Amazon Web Services · 30 min
Call an LLM from your code: Bedrock Converse API in Lambda
Build a ticket-triage function that calls a foundation model with the Converse API, fix the IAM permission it needs, return structured JSON and log token usage – the pattern behind most GenAI features in real applications.
Virtual lab · Amazon Web Services · 30 min
Prompt engineering in the Amazon Bedrock playground
Request model access, then practise the core prompt-engineering techniques – clear instructions, system prompts, JSON output, few-shot examples, temperature and max-tokens – while watching tokens, latency and cost for each call.
Quick revision
- LLMs predict the next token; limits and prices are in tokens.
- Bedrock = many foundation models behind one API.
- Converse API for chat/tools; InvokeModel for model-specific calls and embeddings.
- temperature, topP, maxTokens, stopSequences control output.
- Pick the smallest model that is good enough.
Practise this topic
Hands-on virtual labs
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.