Learning resourcesReviewed · OpenRouter

OpenRouter Agent SDK: Tools Guide

OpenRouter’s Tools guide teaches developers to connect AI models to application functions, but its examples require application code and execution safeguards. It covers TypeScript with Zod and Python with Pydantic; the Go examples require a custom tool loop because there is no Go agent SDK.

Researched 23 Nov 2026

In short.

OpenRouter’s Tools guide is a reference for developers building AI applications that call functions, with application integration and safe execution still their responsibility. It explains automatic tool loops, progress events, manual handling, human review, persistent context and MCP result typing. Its language differences matter: TypeScript and Python use SDK interfaces, while Go examples use application-defined helpers or direct HTTP requests. Runtime correctness, performance and compatibility were not assessed; prices and licence terms are unknown.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage comprises the complete captured Tools page at [https://openrouter.ai/docs/agent-sdk/call-model/tools.md], including language-specific examples, execution modes, context, streaming, validation, concurrency, error handling and the 0.8.0 event notice. Linked pages, the documentation index and SDK source code are excluded. The page’s warnings about Go placeholders, repeated stream calls, unsafe example operations and atomic idempotency are included. No examples were executed; runtime behavior, performance and model compatibility remain unassessed, and costs and licence permissions remain unknown.

The overview

Resource identity

This is OpenRouter’s Tools documentation page for the Agent SDK’s callModel interface [https://openrouter.ai/docs/agent-sdk/call-model/tools.md]. It is implementation guidance rather than a ready-made assistant. Here, a tool means an application function that a model can request, such as retrieving weather, searching documents or requesting a payment decision.

Practical assessment

The guide is useful when an application needs model-requested functions with validated inputs, structured results and control over when execution pauses. Its strongest practical detail is the distinction between automatically executed tools, manually handled calls and calls that can pause for a human decision.

Treat it as a reference to adapt alongside your own application code. Many snippets depend on undefined helpers such as fetchWeather or searchBatch, and the presence of Go examples does not establish a Go SDK. The documented behavior has not been verified by execution.

Who it suits

It suits TypeScript and Python developers adding searches, external API calls or approval steps to an AI application. Beginners get concrete examples of schemas and execution loops, but need familiarity with functions, asynchronous programming, environment variables and external services.

Experienced developers will find detail on typed event unions, context mutation, paused conversation states and concurrent calls. Go developers can use the HTTP and loop patterns, but must implement the supporting types, helpers and execution control themselves.

Documented capabilities

The page covers regular tools with an execution callback, generator tools that emit progress, manual tools without automatic execution and human-in-the-loop tools with decision hooks. Input schemas constrain arguments; output schemas describe results; event schemas define generator progress. TypeScript type helpers can infer tool input, output and event types.

It also documents parallel execution of multiple calls, streams for arguments and results, execution errors returned to the model, and controls for stopping tool rounds. Tool-specific context persists across turns, while shared context lets tools exchange state. MCP branding distinguishes local schema-derived results from MCP results whose shape remains unknown.

Using it

Requirements

The TypeScript examples import OpenRouter and tool from @openrouter/agent and schemas from Zod. Python examples import openrouter_agent and Pydantic, with additional dependencies for particular operations. Examples read an OpenRouter API key from OPENROUTER_API_KEY and supply a model identifier.

Your application must provide the actual weather service, database, email sender or other operation behind each callback. Go examples require HTTP request handling and an application-owned tool loop. Installation commands, supported runtime versions, a full dependency matrix and general model compatibility are not established by this page.

How execution works

The documented automatic loop sends the request and tool definitions to the model, validates a requested tool’s arguments, executes the callback and returns its result to the model. It repeats if the model requests more tools. Multiple calls can execute in parallel. Invalid arguments are caught before execution, and execution errors can be sent back for the model to handle.

Unresolved manual calls pause with status awaiting_client_tools and can persist in serialized conversation state. A later callModel request with new input clears the stale pending calls and proceeds as a normal turn. HITL tools instead pause with awaiting_hitl when onToolCalled returns null; callers resume them with matching function_call_output items. Their required outputSchema validates the returned decision, including any transformation by onResponseReceived.

Approval gates and HITL serve different purposes: requireApproval pauses before execution for a yes/no decision, while HITL lets application logic run first and pause conditionally. A tool description saying that confirmation is required does not itself implement confirmation.

Integration approach

Define a named tool with an input schema and an appropriate callback or manual handling mode. Add an output schema where structured results are needed, and an event schema for generator progress. Pass the tool to callModel with a model identifier and input, then consume the final text or relevant streams.

Pass tool context under the tool’s name. Dynamic context initialization runs once at turn 0; later updates use setContext. Shared state uses the documented shared schemas and setters. These mechanisms provide state plumbing, while the application still needs to manage permissions and concurrent access.

Choose execution controls carefully. TypeScript maxToolRounds: 0 disables automatic execution. Stopping after one round still permits an automatic tool to run; declaration-only tools use execute: false, or execute=False in Python. The Python streaming example also tracks call IDs because a completed call can appear again when the final response arrives.

Representative examples

The weather example accepts a location, returns temperature and conditions, and lets the SDK feed that result back to the model. The self-contained Python callback returns a fixed 22 degrees and sunny conditions. That illustrates the data flow; it does not demonstrate a live weather lookup or establish current weather.

The payment example shows conditional human review: amounts below 100 return an approval result, while other amounts return null and pause. That threshold is sample application logic. The search generator illustrates another distinction: TypeScript returns its final result from the async generator, while the Python example yields the final output after its progress events.

Assessment & evidence

Limitations and implementation hazards

The snippets are not uniformly complete applications, and equivalent-looking language tabs do not establish identical SDK support. The page explicitly identifies Go types and functions such as Tool, TurnContext and callModel as application-defined placeholders.

Some TypeScript examples need stronger restrictions before accepting untrusted requests. The calculator calls eval on model-supplied text, and the fetch example validates URL syntax without restricting destinations. The Python examples instead constrain arithmetic operations and use an HTTPS host allow-list with redirects disabled.

The TypeScript timeout example races an operation against a timer but does not show cancellation of the underlying work. The idempotency discussion also warns that lookup followed by creation is not atomic: preventing duplicates requires a backing-store uniqueness constraint or an atomic create-or-get operation.

Fit and tradeoffs

The documented design fits applications whose functions have clear arguments and results, and whose developers want the SDK to manage repeated model/tool exchanges. Manual and HITL modes provide control when execution must move outside that automatic loop.

Schema validation can establish that an argument has an expected shape or satisfies a declared constraint; it does not establish that an action is authorized. Likewise, MCP branding is explicitly informational. It supports result-type narrowing, while MCP output remains unknown and needs validation before use. These distinctions make the guide useful without establishing production security or reliability.

Documented alternatives

Within the page, the main choices are automatic execution for ordinary functions, manual handling when the application processes calls itself, HITL for conditional escalation and requireApproval for explicit consent before execution. Generator tools add progress reporting for operations that take longer.

For Go, the documented route is direct API requests with a custom execution loop. That gives the application control but leaves orchestration and validation to its implementation. Other libraries and services are not compared, so relative performance, portability and migration effort are unknown.

Evidence and confidence

The evidence is the complete captured OpenRouter Tools page [https://openrouter.ai/docs/agent-sdk/call-model/tools.md]. It supports descriptions of the documented APIs, examples and cautions. Displayed outputs are illustrative documentation, not observed execution results.

No code was executed. Runtime correctness, latency, reliability, compatibility across models and behavior under load were not assessed. Linked documentation and package source code are outside the evidence.

Access & freshness

Costs and usage

The page gives no SDK price, model rates, service fees or worked cost estimate. Total cost is unknown. A budget would need to account for the chosen model, repeated model requests and any external services used by tool callbacks.

Usage metadata is illustrated, but it is not a price quote. The Go example explicitly reports only the final request’s usage unless the application accumulates usage across rounds. A round limit constrains execution rounds; it does not establish a monetary spending limit.

Licensing and rights

The supplied page does not state licence terms for its prose, code examples or SDK packages. Permission to redistribute, modify or commercially reuse those materials is unknown from this evidence. Public availability of the documentation does not establish those permissions.

Terms governing OpenRouter access and any external services used by tools are also outside the supplied page.

Version and freshness limits

The page was captured on 23 November 2026 at 07:14:16 UTC. Its publication date, last substantive update and the latest SDK release are unknown.

A specific compatibility notice says that @openrouter/agent 0.8.0 added source to tool.result events, affecting consumers that exhaustively match or construct those events. This identifies a documented version boundary; it does not establish that 0.8.0 is the current release. Applicability to a particular installed version needs confirmation.

Suggested next steps

Start with one read-only function and implement its real backend separately from the model call. Confirm the API names against your installed package version, then check valid arguments, rejected arguments, backend failures and stopping behavior before adding more tools.

For actions with side effects, implement the appropriate approval or HITL path and handle repeated calls safely. Restrict executable expressions and network destinations, validate MCP results, and review shared-state updates for concurrent calls. Confirm licence terms and model pricing separately because this page does not establish them.

Evidence for this report

selected-page.txtselected · checked 2026-11-23