

Guides, walkthroughs, and integration how-tos.


When an agent running in your harness sends a tool the wrong argument, or one step takes two minutes, a request log will not tell you much. It shows each call on its own, so you cannot see which step in the run went wrong or why.


In an AI agent, the session history fills with tool calls, file reads, and logs over dozens of turns, and the model gets worse at using what's already in its window. Late in a long session, the model can lose count of how many times a test failed, even though the question it's asked stays the same. Models now advertise 1M-token windows, so the question has moved from whether a session fits to whether the model still works once it does. We wanted to know where current models break down and whether there's a cheap fix, so we ran the same long coding-agent session on five models from five labs through OpenRouter and tested two ways of shortening the history. If you only want the fix, skip to how to fix context rot with compaction. ## Tl;dr - Context rot means a model gets worse at using its prompt as the prompt grows, even well inside its context window. - In our October 22, 2026 run on five 1M-context models, finding one fact, tracking a setting's latest value, and following an early rule stayed at 100% up to about 900K tokens. Counting three failed test runs spread across the session fell from 67% correct at about 20K tokens to 40% at about 80K and 27% at about 600K. - Dropping old turns to fit a smaller token budget cut accuracy at 2M characters from 49/60 to 9/60, and one run invented a ticket ID (SEC-8492) that appeared nowhere in the session. - Chunked compaction with scaledown/summarize ($0.04 per million input tokens) raised accuracy at 2M characters from 49/60 to 54/60. The average prompt fell from 605K tokens to 112K, and the average request cost fell from $0.224 to $0.041. ## What is context rot in AI? Context rot is the drop in how well a language model uses the information in its prompt as the prompt gets longer, even when the whole prompt fits inside the context window. The window sets how many tokens a model can read in one request. It doesn't promise that the model uses all of them equally well. Agents run into it because their prompts grow with every turn. The user's first instructions and the early test failures end up under hundreds of thousands of tokens of tool output. Chroma's research report on context rot measured the effect on earlier models with retrieval-style tasks. Current 1M-context models recalled single facts perfectly up to about 900K tokens, but accuracy dropped early on questions that required counting events across the whole session. ### How we built the test We generated a synthetic coding-agent session in the OpenAI chat format. Each session opens with a system prompt and a user task ("fix the flaky refund rounding test in src/orders and tidy up the ingest worker config"). Hundreds of tool calls and results follow, filled with TypeScript file reads, grep output, .env files, and test logs. We planted four facts in every session, each at a fixed point and each with one exact answer. The percentages show how far into the session each fact appears. - Ticket ID. At 27%, the user gives the ticket OPS-4471 and mentions an unrelated OPS-4417. The answer is OPS-4471. - Latest value. The ingest worker's MAX_WORKERS starts at 4 and changes to 8, then 16, and finally 14 at 83%. At 66%, another service sets MAX_WORKERS=6 as a distractor. The answer is 14. - Early rule. At 4%, the user says not to touch src/billing. We ask whether the agent may edit src/billing/invoice.ts. The answer is false. - Count across the session. Three full test runs, at 18%, 45%, and 74%, each report one failing test, and every other run passes. We ask how many runs failed. The answer is 3. At the end of the session, the user asks all four questions and requests a JSON reply, which we scored by exact match. We built five session lengths (64K, 256K, 1M, 2M, and 3.2M characters) with three random seeds each. Then we sent the same sessions to five models, each with a window of about 1M tokens and reasoning.effort: "low": - anthropic/claude-haiku-5.5 - openai/gpt-6-luna - google/gemini-3.8-flash - deepseek/deepseek-v4.1-flash - minimax/minimax-m3.1-flash With three sessions per model per length, the samples are small, so read the results as a direction rather than as precise rates. The same text turns into a different number of tokens on each tokenizer. Claude Haiku 5.5 counted about 1.5 times as many tokens as GPT-6 Luna for the same session. | Session length | Claude Haiku 5.5 | GPT-6 Luna | Gemini 3.8 Flash | DeepSeek V4.1 Flash | MiniMax M3.1 Flash | | --- | --- | --- | --- | --- | --- | | 64K chars | 27K | 17K | 20K | 19K | 18K | | 256K chars | 105K | 67K | 78K | 74K | 70K | | 1M chars | 405K | 260K | 299K | 286K | 270K | | 2M chars | 806K | 518K | 596K | 571K | 537K | | 3.2M chars | Too long (1.28M to 1.29M) | 828K | Not run | 913K | 859K |


An AI agent resends its whole conversation to the model on every step, so a long session's token count and its bill grow with every call. This guide shows you how to bring both down, using measurements instead of guesswork.


Claude has no image model of its own, so it draws with code or says it can't. A connector lets it call one: the image model draws, and Claude writes the prompt, shows it to you before you pay, and checks what comes back. We ran it in the Claude app and in Claude Code on four image models and measured what each image cost.


When a RAG (Retrieval-Augmented Generation) app gives wrong answers even though the right information is in your documents, retrieval is often the cause. Vector search is great at finding chunks on the right topic, but it often falls for near misses, like pulling the bucket limit for the Enterprise plan when the user asked about the Growth plan. Reranking in RAG fixes this by taking your vector search’s top 30 candidates and passing them through a dedicated cross-encoder model that re-scores each chunk directly against the question.


An AI agent gets stuck in an infinite loop when a model keeps calling a tool that fails, usually with the same arguments, because nothing in the agent loop tells it to stop. Each retry resends the whole conversation, so every turn costs more than the last, and a loop left running overnight can cost thousands of dollars.


Choose models using evidence from your application’s inputs and output formats. Run identical tasks through OpenRouter and compare graded accuracy, billed cost, and request time. On our 60 synthetic tasks, GPT-6.1 Sol passed 180/180 trials across three repeats under the tested contracts and settings.


A 429 Too Many Requests error means you sent more requests or tokens than your limit allows in the current time window. OpenAI, Anthropic and OpenRouter all return it, and it usually shows up the first time an app runs under real load or a batch job fans out across several workers.


A voice agent needs to do more than generate a good answer. It must understand what someone said, decide what to do, call any needed tools, and start speaking again before the pause gets awkward.


When your code reads fields from a model's reply, like an order ID or a refund amount, it expects clean JSON every time. Most of the time, it gets it. But now and then the model wraps the JSON in a code fence, adds a field you didn't ask for, or sends a number as text, and your code breaks. If you use several models, one fix won't cover them all, because each model and provider handles structured output in its own way.


Code reviewers that only read a Git diff have to guess whether a change breaks anything, and their fixes come back as prose you apply by hand. This guide builds a Python reviewer on the OpenRouter Responses API that uploads your changed files into a Linux sandbox, runs checks to confirm each bug, and returns validated patches. A review takes one to four minutes and costs $0.015 to $0.045.


An always-on AI agent wakes up on a schedule, checks something with tools, and reports or acts without you asking. This tutorial builds one in TypeScript with the OpenRouter Agent SDK that watches Hacker News, remembers what it has seen across restarts, stops any run at five cents, and waits for your approval before it posts.


Send a PDF to a model that reads files, with a strict JSON schema for one row, and you get typed rows back, even from scans and tables that run across pages. We tested five routes on five PDFs and found two failures that return a normal response with no error, and the checks that catch them.


If your app has a model read documents, emails or web pages, anyone who writes in them can try to give it instructions. We ran 25 attacks against four current models with each defense on and off. Labels cut attack emails, but only checking every tool call with Armor stopped all of them.


A 529 overloaded_error from Claude means Anthropic's API is out of capacity for the model you asked for, not that your key or plan is wrong. This guide shows how to retry with backoff, send the same Claude model to another provider through OpenRouter, add a fallback model, and stop the error in Claude Code.


When Claude Code hits your plan's five-hour or weekly limit, you can keep working by pointing it at an OpenRouter API key. You pay per token for the same Claude models, with no usage window. This guide sets it up as a separate command, checks the cost, and switches back when your plan resets.

Cheap-first routing sends routine support questions to a small, inexpensive model and escalates selected hard or uncertain requests to a stronger one. This guide compares the three application-side routing patterns, separates what your application owns from what OpenRouter's Auto Router and model fallbacks handle, walks through a support flow with a copyable request, and sets out how to measure escalation rate and cost per resolved ticket.

A one-line prompt change can ship an agent that tells customers the wrong refund window, and nothing in a normal CI pipeline checks what the model says. This guide builds a fixed eval set for a support agent, a script that exits non-zero below a measured threshold, and a GitHub Actions job that blocks the merge when the pass rate drops.

An agent's behavior can change when you edit a prompt, swap a model, change a tool schema, or change what retrieval returns. This guide covers the locked case set, the per-case behavioral contract, and how to run the same suite against two concrete model slugs through OpenRouter so the diff shows what the change did.

A golden eval dataset is a curated set of production inputs with reviewed expected outputs, versioned in Git and run before every deploy. This guide covers the five steps to build one from live traffic and how to run the same set against many candidate models through one API.

An agent can call the wrong tool, or call the right tool with the wrong arguments. This guide covers three ways to test each failure mode, a Python harness that grades both, and how to run the same test cases against several tool-capable models through OpenRouter.

A method for putting Jev to work on a new problem, worked end to end on marketplace listing moderation: what stays in code, what Jev sees, how to phrase the questions, and how to turn its probabilities into publish, hold, or reject.

An LLM judge writes a verdict. Jev returns a probability. We graded the same labeled answers and expert-rated summaries with both, and the difference decides which one you should use for a given rubric. Jev matched the LLM judge on agreement at a fifth of the cost and a tenth of the latency, and its probabilities meant what they said. The LLM judge won on the open rubric.

Jev returns typed judgments with probabilities. An LLM returns prose. We benchmarked both on 100 support cases through OpenRouter, then wired them together so Jev routes and the LLM writes.

A tool-calling agent loop sends the conversation and tool definitions to a model, runs the tool calls the model returns, appends the results, and repeats until the model answers or a stop condition fires. This guide builds that loop in TypeScript with the OpenRouter SDK, then adds an iteration cap, repeated-call detection, model fallback, and history controls.

An LLM judge is a second model that scores an agent's output against criteria you write in plain language. This guide explains where a judge fits beside deterministic tests and human review, then shows how to add one to an Ori Eval test, compare candidate models, calibrate the threshold against human-labeled examples, and keep evaluation cost under control.

Our OpenAI-compatible speech endpoint puts TTS models from Mistral, xAI, Microsoft, and more behind one request shape. Here's the path from API key to a playable MP3 in cURL, Python, JavaScript, and the OpenAI SDK, plus the response checks that keep JSON errors out of your audio files.

A preset is config-as-code for your LLM calls: a named, versioned set of models, system prompts, provider routing, and sampling parameters. Define it once, reference it as @preset/your-slug everywhere, and update every app from the dashboard without a redeploy.

Send a source image and an edit prompt in one request, get the edited image back, and change the editing model by editing a single field. Runnable Python and TypeScript included.

There's no single best AI model, only the best model for a given task, budget, and moment. This article describes a six-step framework for choosing one, and how to run every step from your editor through the OpenRouter MCP server.

Every video provider has its own endpoint, job statuses, polling logic, and output format. Our async video API puts Seedance, Veo, Wan, and more behind one submit, poll, and download loop. Here's the full lifecycle in Python and TypeScript.

Supporting more than one image provider means handling different endpoints, data formats, and billing models. Our dedicated Image API gives you one request format and one key across supported models. Here's the full prompt-to-local-file workflow in Python and JavaScript.

To get a model to read a screenshot, you need the right request body. This guide shows the content-array pattern that works across every vision-capable model we support, when to use base64 instead of a hosted URL, and how to build multimodal RAG on top of it.

Most tool-calling tutorials cover one provider, so you rewrite the loop when you switch. This guide shows the full loop in Python, JavaScript, and cURL, then runs it against three providers by changing one string.

OpenRouter has five controls for team spend: an organization with a shared credit pool, presets that scope models per workload, per-key spend caps, guardrails that enforce per-member budgets, and the Activity dashboard that shows who spent what. This guide sets them all up in one pass, in order.

The LangChain integration now has a dedicated package: langchain-openrouter on PyPI and @langchain/openrouter on npm. Most guides still teach the old ChatOpenAI base_url override. This is the current path, plus the routing economics the docs skip.

The image catalog covers ten labs and the slugs change monthly. Here's how to narrow it down by job, parameter support, and price, plus what each Image API error message means and how to fix it.

Send base64 audio to POST /api/v1/audio/transcriptions and get JSON text plus a usage object back, with the same API key you already use for chat. Here's the full request contract, the model families, and the limits to design around.

Your agent sends the same system prompt, tool definitions, and schemas on every turn. Cache reads cost 0.1x to 0.5x of fresh input, but only if the next request lands on the provider holding the warm cache. Here's how caching and sticky routing work together, and how to confirm they're working.

OpenClaw has built-in OpenRouter support. One command gives your agents one key, one bill, and automatic failover across hundreds of models. Here's the setup and the fixes for the errors that trip people up.

One OpenRouter key gives SillyTavern hundreds of models in a single dropdown, many of them free to start. Here's the five-step connection, the roleplay models to try, and fixes for the errors users hit most.

Kilo Code is a bring-your-own-provider coding agent, so adding OpenRouter gives it one key for hundreds of models, provider routing, and failover. Here's the three-step setup plus the kilo.json fields that control routing.

Codex CLI supports custom OpenAI-compatible providers, so a small config.toml block routes it through OpenRouter. You get provider failover, usage tracking, and one key across every model, with no change to Codex itself.

Route Claude Code through OpenRouter with three environment variables and no local proxy. You get provider failover, budget controls, and usage visibility on top of the same Anthropic models.

Any tool that speaks the OpenAI API works with OpenRouter after two changes, the base URL and the key. Here's the setup pattern and the tools that already support it.

Stop guessing which free LLM API survives past a side project. Here's how OpenRouter, Groq, Gemini, and 10 more compare on limits, cost, and data use.

Anthropic restricted Claude Fable 5 just days after launch. If your code hard-codes a model slug, that becomes your outage too. Presets move model choice to the server so you can swap models, set fallbacks, and enforce a data policy without redeploying.

Hermes Agent has pushed over 17 trillion tokens through OpenRouter. Here's how to set it up, pick a model that clears the 64K context bar, and tune routing for cost and reliability.

Append :floor for the cheapest provider, cap spend with max_price, and start free with 20+ zero-cost models. Plus the billing gotchas to avoid.

Overpaying for reasoning you don't need? Learn how to configure Gemini 2.5 Flash API thinking budgets, compare providers, and make your first call in 5 minutes.

Use the Agent SDK's human-in-the-loop (HITL) tools to meet AI agent compliance requirements from the EU AI Act, Colorado's Automated Decision-Making Technology law (SB26-189), and NIST AI RMF.

Human-in-the-loop tools in the OpenRouter Agent SDK let your agent auto-resolve routine decisions and pause for human input on high-stakes ones, with two hooks and zero loop-management code.

The OpenRouter Agent SDK gives you callModel: one function that turns a chat completion into a multi-step agent with tool calls, stop conditions, and cost tracking across 400+ models.

Use the create-agent-tui and create-headless-agent skills to scaffold a personalized coding agent in minutes — with a terminal UI or headless for scripts and pipelines.

How to generate license-safe synthetic data workflows for model specialization
Customize once and use everywhere. Server-side presets now simplify your model workflows.
Explore it in action: See how effortlessly you can run Kimi K2 in Cursor using OpenRouter’s flexible model routing.