页面简介
Tutorials from the OpenRouter blog.
正文摘录
Agent Memory: 4 Designs Tested Across 12 SessionsA model doesn't remember anything between API calls. End a chat with your coding assistant, open a new one, and it has forgotten that your repo uses pnpm, that nobody pushes to main, and which host runs staging. When an agent does seem to remember you, it's because your app saved something from an earlier session and put it back into the prompt.December 4, 2026Track and Cap LLM Cost per Customer (With Real Numbers)When customers pay a flat monthly fee for an AI product, heavy users can cost hundreds of times more than light ones. We tested three simulated customers to show how to tag requests with customer IDs, record exact costs from each response, and enforce spending limits.December 4, 2026Text-to-SQL Agent: How It Works and What Makes It AccurateWhen you connect an LLM to a SQL database so people can ask questions in plain English, writing valid SQL is the easy part. Wrong answers often come from the data itself, such as a column that stores cents instead of dollars, or a country column that mixes names with ISO codes.December 3, 2026Agent Tracing: See Every Tool Call and Provider AttemptWhen 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.December 2, 2026Context Rot: Why Your AI Agent Gets Worse in Long SessionsIn 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. We ran the same long coding-agent session on five 1M-context models through OpenRouter to measure where they break down and tested two ways of shortening the history.December 1, 2026How to Reduce Token Usage in AI Agents (Measured)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.December 1, 2026Can Claude Generate Images? Yes, with a ConnectorClaude 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.November 23, 2026Reranking in RAG: How to Fix Bad Retrieval with a RerankerWhen 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.November 13, 2026How to Stop an AI Agent Stuck in an Infinite LoopAn 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.November 12, 2026How to Benchmark LLMsChoose 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.November 12, 2026LLM API Rate Limits: How to Fix OpenAI and Claude 429 ErrorsA 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.November 11, 2026How to Build a Voice AI AgentA 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.November 10, 2026How to Get Structured Output from Any LLM: JSON Schema, Tool Calls, or a Decision ModelWhen 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.November 10, 2026Build an AI Code Reviewer with OpenRouterCode 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.November 1, 2026How to Build Your Own Always-On AI AgentAn 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.October 31, 2026How to Extract Tables from a PDF with an LLMSend 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.October 29, 2026How to Prevent Prompt Injection: 13 Attacks, TestedIf 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.October 29, 2026Claude 529 Overloaded: What It Means and How to Fix ItA 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.October 28, 2026Hit Your Claude Code Usage Limit? How to Keep CodingWhen 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.October 28, 2026Model Routing for Support Bots: Cheap-First FAQ HandlingCheap-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.October 2, 2026How to Gate Pull Requests on LLM Evals in CIA 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.October 1, 2026AI Agent Regression Testing After a Prompt or Model ChangeAn 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.September 30, 2026Building a Golden Eval Dataset from Production TrafficA 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.September 30, 2026How to Test Tool-Calling Accuracy in AI AgentsAn 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.September 30, 2026How to Use Jev: Moderation with the Jev API in TypeScriptA 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.September 23, 2026Jev vs LLM-as-a-JudgeAn 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.September 21, 2026Jev vs LLM: When to Use a Decision Model Instead of Generating TextJev r