In short.
OpenRouter’s Stop Conditions page is a guide for TypeScript developers setting limits on AI tool loops, but a stop can still be followed by pending tool execution and a final model turn. It documents stopWhen helpers, conditions combined with any-match logic, custom callbacks and controls for final answers. It is useful for understanding execution boundaries, but does not establish strict total-spend ceilings, immediate cancellation or runtime reliability. No code was executed.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage includes the complete supplied page at [https://openrouter.ai/docs/agent-sdk/call-model/stop-conditions.md], including built-in and custom conditions, combination rules, final-response and empty-output caveats, advanced patterns, migration and usage recommendations. The documentation index and all linked pages are excluded. No code was executed, and runtime behavior, installation compatibility, actual costs and reuse permissions remain unverified.
The overview
Identity
This is the Stop Conditions documentation page for the OpenRouter Agent SDK’s callModel method, at [https://openrouter.ai/docs/agent-sdk/call-model/stop-conditions.md]. Its subject is configuring when a model-and-tool loop should end.
The resource is a feature guide with TypeScript examples, rather than a standalone application or a complete agent project. The examples use the @openrouter/agent package.
Assessment
The guide is useful when an application needs explicit limits instead of relying solely on the model to finish. Its most decision-relevant detail is what happens after a condition fires: stopping the loop can still involve completing pending tools and requesting a final answer.
The documentation supports choosing configuration patterns and understanding their tradeoffs. It supplies no measured reliability, latency, task-quality or spending results, so those outcomes remain unassessed.
Users
The intended users are developers building tool-using AI applications with OpenRouter. Beginners can start with a step limit; experienced developers can inspect completed results, combine stopping signals and control the final-answer contract.
The research, writing, data-processing and scoring examples illustrate possible uses. The page assumes familiarity with TypeScript, model requests and tool definitions, so it is not a complete introduction to building an agent.
Capabilities
Built-in helpers stop by step count with stepCountIs(n), a named tool call with hasToolCall(name), total token usage with maxTokensUsed(n), a cost threshold with maxCost(amount), or a model finish reason with finishReasonIs(reason). An array of conditions stops execution when any condition is met.
Custom functions can inspect completed steps. Examples use elapsed time, response markers and scores returned by tools. The page also covers allowFinalResponse, strictFinalResponse and migration from maxToolRounds.
Using it
Requirements
The examples require the OpenRouter client and relevant helpers from @openrouter/agent, an API key supplied through process.env.OPENROUTER_API_KEY, a model identifier and any tools referenced by the request.
Several snippets assume existing tool objects. The finish-tool example also uses tool() and z.object(), without showing their imports. Installation commands, supported runtimes, minimum package versions and account requirements are not established by this page.
Mechanism
Without stopWhen, the documented default is to continue until the model produces a turn with no tool calls. A custom condition receives a steps array containing completed StepResult records. Each record includes a response, optional tool calls and results, input/output/cached token counts, and cost.
If a stop condition halts a turn containing executable tool calls, the default behavior executes those pending tools and makes one additional model turn with toolChoice set to 'none'. Tools remain in the request to preserve the prompt-cache prefix, and a built-in final-answer directive is appended as a user message.
allowFinalResponse can replace that directive with custom text, retain the final turn without an appended message by using an empty string, or disable the final turn with false. The extra turn does not occur on natural completion, human approval pauses or interruption.
Setup
The documented starting pattern is to create an OpenRouter client with the API key, supply a model, input and tools to callModel, and add stopWhen: stepCountIs(5). More complex configurations add a cost threshold and an application-specific completion signal.
Choose final-output behavior separately from loop limits. Keep the default directive when a natural-language wrap-up is desired, customize it for a particular summary, or disable the final turn when the application should end at the halted tool-call turn. These are documented configurations; their behavior was not executed here.
Example
The research example combines stepCountIs(10), maxCost(0.50) and hasToolCall('finish') in one stopWhen array, alongside search and finish tools. Any one of those signals can stop the loop; all three do not need to occur.
This pattern gives research work an iteration limit, a spending threshold and a model-selected completion signal. The application must supply the tools, and default final-response handling can still perform additional work after a stopping signal. The $0.50 value is an example threshold, not a reported task cost.
Assessment & evidence
Limitations
The elapsed-time example checks Date.now() inside a condition. The page does not establish immediate cancellation of an in-flight request or tool at the configured deadline. Exact threshold-check timing and guarantees against token or cost overshoot are also unspecified.
After at least one completed tool execution round, the SDK documents one retry for an empty final output, followed by resolving with empty text if it remains empty. strictFinalResponse: true restores error behavior. Runs with no tool work still throw on an empty final response.
An empty allowFinalResponse string removes the appended directive while retaining the final turn. The page warns that without a directive, some models can emit unparsed tool-call syntax into final content. Neither a stopping condition nor a non-empty answer establishes task correctness.
Reasoning
A practical implication of the documented any-match behavior is that a completion signal can coexist with independent step and cost limits. A finish tool or score threshold expresses success, while another condition can end an unsuccessful or prolonged attempt.
Success signals still require application judgment. Finding a marker in serialized response content only establishes that the marker appeared; exceeding a tool-provided score only establishes that the tool returned that score. Applications that require final text should also distinguish stopping successfully from receiving a usable answer.
Alternatives
Within this SDK, built-in helpers suit straightforward thresholds, while custom callbacks support conditions based on response content, tool results or elapsed time. Arrays provide any-match behavior; more complex combined logic can be expressed within a custom function.
For older code, the page demonstrates replacing maxToolRounds: 5 with stopWhen: stepCountIs(5). It does not compare other agent libraries or establish equivalent behavior elsewhere, so external alternatives are not assessed.
Evidence
The evidence consists of the complete supplied Stop Conditions page from OpenRouter’s documentation. It contains API descriptions, TypeScript snippets, configuration defaults, caveats and migration guidance.
No code was executed. Runtime correctness, model availability, observed spending, latency and task quality are not established. The documentation index and linked pages on tools, dynamic parameters and nextTurnParams are outside this resource’s assessed scope.
Access & freshness
Costs
Actual costs are unknown. The page provides configurable dollar thresholds and per-step cost fields, but no SDK pricing, model rate table, tool charges or measured end-to-end spending.
maxCost expresses a stopping threshold. Because the documented default can execute pending tools and make another model turn after stopping, this page does not establish that the threshold is a strict ceiling on the final bill. Overshoot behavior and treatment of external tool costs are not specified.
Rights
The supplied page includes no licence or explicit redistribution permission for its text or code examples. Commercial reuse terms, attribution obligations and permission to redistribute the captured document are unknown.
The licence of the @openrouter/agent package is also not established by this documentation page.
Freshness
The supplied document was captured on 13 November 2026 at 04:23:25.858 UTC. No publication date, last-updated date or current SDK release number is supplied.
The strictFinalResponse explanation refers to restoring pre-0.8.0 behavior. That is a historical compatibility reference, not proof of the current release or support across all versions. Compatibility with a particular installed package remains unknown.
Actions
Start with an explicit step limit, add a cost threshold where appropriate, and define a completion signal that matches the application’s task. Decide whether pending tools and a final summary should run after stopping, and whether empty final text should raise an error.
Before relying on the configuration, verify it with low limits in the intended SDK version. Check stopping during tool calls, final-turn usage, empty-output handling and the reason each run ended. For time-sensitive work, separately establish how in-flight requests and tools are cancelled; this guide does not supply that guarantee.
