Bedrock “Input Is Too Long for Requested Model”: Count Tokens and Fit the Context Window
“Input is too long for requested model” means the request you sent has more tokens than the model’s context window can hold.
The surprise: the error often appears with prompts far shorter than the window, because a chatbot resends the entire conversation every turn. Turn 40 carries turns 1 to 39 with it.
Jake’s parts chatbot worked all morning. By mid-afternoon, long conversations with the same few customers started failing with this error, though each new question was a single line.
Jake: "Each question is one line. How is that too long?"
Ethan: "Because the bot sends every line of the conversation so far, every time. One line on top of a very long history."
What counts as input
| Part of the request | Why it grows |
|---|---|
| System prompt | Long instructions, examples, policies pasted in |
| Conversation history | Every earlier user and assistant turn is resent |
| Retrieved documents (RAG) | Many or large chunks added to the prompt |
| Tool definitions | Big JSON schemas for every tool, on every call |
| Images and documents | Each one becomes many tokens |
Tokens aren’t characters or words; for English text a token is roughly three-quarters of a word, but the exact count is model-specific, because each model family has its own tokenizer.
Step 1: count the tokens of the real request
The CountTokens API takes the same input you would send to Converse or InvokeModel and returns the token count you would be billed for. It costs nothing to call:
💻 Where to run these commands
Easiest: AWS CloudShell, nothing to install. Sign in to the AWS Management Console, choose your Region at the top right, then click the CloudShell icon (a small >_ terminal symbol) in the top bar, or type CloudShell in the search box and open it. When the $ prompt appears, paste a command and press Enter. CloudShell already has the AWS CLI, uses your console permissions and costs nothing extra.
On your own computer: install AWS CLI version 2 (installers for Windows, macOS and Linux are on the AWS CLI page), run aws configure once (or aws configure sso if your company signs in through single sign-on), and check it works with aws sts get-caller-identity. Then paste commands into Terminal on Mac or Linux, or PowerShell or Command Prompt on Windows.
Windows tip: a line ending in a backslash ( \ ) continues on the next line in CloudShell, Mac and Linux. In PowerShell use a backtick ( ` ) instead, in Command Prompt a caret ( ^ ), or simply join the lines into one. JSON inside single quotes works as shown in CloudShell; on Windows, save the JSON in a file and pass it as file://name.json.
Python examples: save the code in a file such as script.py, install the AWS SDK with pip install boto3, and run python script.py (python3 on Mac and Linux). It uses the same credentials as the AWS CLI; CloudShell has Python and boto3 ready.
Replace example values such as my-bucket, my-function, 111122223333 (an account ID) and us-east-1 with your own.
import boto3
client = boto3.client("bedrock-runtime", region_name="us-east-1")
conversation = {"system": [{"text": system_prompt}], "messages": history}
resp = client.count_tokens(modelId=MODEL_ID, input={"converse": conversation})
print(resp["inputTokens"])For an InvokeModel body, pass input={"invokeModel": {"body": json.dumps(body)}}. Some newer Anthropic models, including ones launched only with cross-Region inference, don’t support CountTokens on bedrock-runtime; count those with the /anthropic/v1/messages/count_tokens endpoint on bedrock-mantle.
Step 2: compare with the model’s context window
Context windows on Bedrock range from 128K to about a million tokens. From the current model cards:
| Model | Context window | Max output |
|---|---|---|
| Llama 3.3 70B Instruct | 128K | 4K |
| gpt-oss-120b | 128K | 16K |
| DeepSeek V3.2 | 164K | 8K |
| Claude 3 Haiku | 200K | 4K |
| Mistral Large 3 | 256K | 32K |
| Qwen3 235B A22B 2507 | 256K | 8K |
| Nova Pro | 300K | 10K |
| Nova 2 Lite | 1M | 64K |
| Claude Fable 5.2 | 1M | 128K |
| GPT-6.2 Sol | 1.05M | 128K |
Leave room for the answer: the input plus the max_tokens you ask for should fit, and some newer models reject requests where it doesn’t. A safe habit is to keep input under about 80 percent of the window. Our Bedrock model IDs list links every model card.
Jake: "So our model has room for 200K, and we were at 210K?"
Ethan: "By turn 40, yes. Now we know the number, we can keep it under."
Fix 1: trim the conversation history
Keep the last few turns as they are and replace older turns with a short summary. A simple version with token counting:
def fit_history(history, system, model_id, budget):
while len(history) > 2:
n = client.count_tokens(modelId=model_id, input={"converse": {"system": system, "messages": history}})["inputTokens"]
if n <= budget:
break
history = history[2:] # drop the oldest user + assistant pair
return historyMessages must still start with a user turn and alternate roles, so drop turns in pairs. For long-running chats, store a running summary and send it in the system prompt.
Fix 2: send fewer, smaller retrieved chunks
- Lower the number of results you retrieve, for example from 20 to 5.
- Use smaller chunks when you build the knowledge base, so each one costs fewer tokens.
- Remove near-duplicate chunks before building the prompt.
- Put the question first and the most relevant chunks last, then stop adding when the budget is reached.
If your knowledge base itself fails while ingesting long text, see knowledge base sync failures.
Fix 3: split long documents
For a document bigger than the window, process it in parts: summarize or extract from each section, then combine the partial results in a final call. Counting each part first keeps every call safely inside the limit.
Fix 4: embeddings have much smaller limits
The same error from an embeddings model is a different limit: Titan Text Embeddings V2 takes up to 8K tokens per call. Split text into chunks before embedding; knowledge bases do this with their chunking settings.
Fix 5: use a bigger window, when it’s worth it
If your use case really needs the whole input at once, such as a contract review across hundreds of pages, move to a model with about a million tokens of context. Bigger requests cost more and take longer, and they use more of your tokens-per-minute quota, so trim first and upgrade second; quota errors are covered in too many requests.
Jake’s fix
- Counted tokens for a failing conversation: 212,000, against a 200K window.
- Kept the last 10 turns and a two-sentence summary of the rest.
- Cut retrieved chunks from 12 to 5.
- Requests now stay under 40,000 tokens: faster, cheaper, and no errors.
Jake: "And if a customer chats all day?"
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: AI Practitioner (AIF-C01) • Machine Learning Engineer – Associate (MLA-C02) • Developer – Associate (DVA-C03 from December 1, 2026).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. A Bedrock chatbot starts returning "Input is too long for requested model" late in long conversations, although each user message is short. What is the cause and fix?
The application resends the whole conversation history, so input grows past the context window. Keep recent turns, summarize older ones and count tokens before each call.
2. How can a developer measure, without cost, how many input tokens a Bedrock request will use?
Call the CountTokens API on bedrock-runtime with the same InvokeModel body or Converse messages; it returns inputTokens and is not charged. For Anthropic models that do not support it there, use count_tokens on the bedrock-mantle endpoint.
3. A RAG application exceeds the model context window. Which change reduces input tokens with the least loss of quality?
Retrieve fewer, smaller and de-duplicated chunks (lower the number of results and chunk size) and stop adding context once a token budget is reached.
4. An embeddings call with Titan Text Embeddings V2 fails because the input is too long. What is the limit and fix?
Titan Text Embeddings V2 accepts up to 8K tokens per call; split the text into chunks before embedding.
5. Does prompt caching let a request exceed a model context window?
No. Cached prefixes still count toward the context window; caching only reduces cost and latency for repeated content.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
Ethan: "The summary grows a little; the history stays short. We never get near the limit again."
Official references for this guide
- Count tokens before running inference: CountTokens on bedrock-runtime, the bedrock-mantle alternative, no charge.
- CountTokens API reference: request formats for InvokeModel and Converse.
- Model cards for context window and maximum output per model.
Frequently asked questions
What does "Input is too long for requested model" mean in Bedrock?
Your request has more input tokens than the model’s context window can take. Everything counts: the system prompt, every message in the conversation, retrieved documents, tool definitions and images.
How do I count tokens before calling a Bedrock model?
Call CountTokens on bedrock-runtime with the same body you would send to InvokeModel or Converse; it returns inputTokens and costs nothing. For Anthropic models that don’t support it there, use the count_tokens endpoint on bedrock-mantle.
Why do I get this error when my text is much shorter than the context window?
Characters aren’t tokens, and a chatbot resends the whole conversation every turn. Long chat histories, many retrieved chunks or large tool definitions add up quickly. Count the tokens of the actual request.
Does max_tokens count towards the input limit?
Not as input, but some newer models check that the input plus the requested output fit in the context window. If the input is close to the limit, lower max_tokens or trim the input.
What is the context window of models on Bedrock?
It varies widely: for example 128K tokens for Llama 3.3 70B, 200K for Claude 3 Haiku, 300K for Nova Pro, and about 1M for Nova 2 Lite and the newest Anthropic and OpenAI models. Each model card lists it.
How do I fix "Input is too long" in a chatbot?
Keep only the last few turns, and replace older turns with a short summary. Count tokens before each call and trim until the request fits with room for the answer.
How do I fix "Input is too long" in a RAG application?
Send fewer and smaller retrieved chunks: lower the number of results, use smaller chunk sizes, and drop near-duplicates before adding them to the prompt.
Can I send a whole PDF or book to a Bedrock model?
Only if its tokens fit in the model’s context window. Otherwise split it into sections, process each one, and combine the results, or put it in a knowledge base and retrieve only the relevant parts.
Why do embeddings models say the input is too long?
Embeddings models have small limits: Titan Text Embeddings V2 takes up to 8K tokens per call. Split text into chunks before embedding.
Is CountTokens free?
Yes. Calling CountTokens doesn’t incur charges, and its count matches the input tokens you would be billed for.
Do images count towards the context window?
Yes. Images are converted to tokens too, and large images cost many tokens. Resize images to what the task needs.
Which Bedrock models have the largest context windows?
Several current models offer about 1 million tokens, including Nova 2 Lite and the newest Anthropic, OpenAI and Kimi models on Bedrock. Check the model card, since context and maximum output are listed separately.
Does prompt caching increase the context window?
No. Caching makes repeated prefixes cheaper and faster, but the cached part still counts towards the context window.
Is "Input is too long" the same as throttling?
No. Throttling is about how many tokens or requests you send per minute and goes away with time. Input too long is about one request’s size and needs a smaller request or a bigger model.
Why does the same request work with one model and fail with another?
Context windows and tokenizers differ by model. The same text can be more tokens for one model, and the windows range from 128K to about 1M tokens.
How much room should I leave for the answer?
At least the max_tokens you request, and more for reasoning models that think before answering. A simple rule: keep input under about 80 percent of the context window.
Revision note. Originally Written November 30, 2026, and checked the same day against how the Bedrock CountTokens API works and each model’s current context window. “Don’t bite off more than you can chew”: count first, then send. See you on next post!