OpenRouter's Agent SDK Simplifies Multi-Turn AI Workflows, Adds Cost & Tool Control
Written byPixel
Drafted with AI; edited and reviewed by a human.
![]()
TL;DR
- OpenRouter has launched a new TypeScript Agent SDK (
@openrouter/agent) to streamline building multi-turn AI agent workflows. - The SDK's core
callModelfunction manages complex agentic behaviors like tool execution, looping, streaming, and cost tracking. - It is model-agnostic, working seamlessly with over 300 models available on OpenRouter.
- Developers gain precise control over agent runs with features like composable stop conditions and integrated cost tracking.
Building sophisticated AI agents that can perform multi-step tasks often involves intricate logic for tool invocation, managing conversational turns, and ensuring responsible resource use. OpenRouter addresses this complexity with its new Agent SDK, a TypeScript library (@openrouter/agent) designed to simplify the development of robust, multi-turn agent workflows. This powerful SDK abstracts away much of the boilerplate associated with agentic behaviors, enabling developers to focus on the core logic of their AI applications rather than the underlying orchestration. For more details, see the official Agent SDK Announcement.
At the heart of the Agent SDK is the callModel function, which acts as a comprehensive engine for agent interactions. This function seamlessly integrates crucial agentic capabilities, from tool execution and input validation using tool() and Zod schemas, to handling multi-turn conversational loops. Instead of manually parsing model outputs for tool calls or managing the feedback loop, callModel automates these processes. Developers can define custom stop conditions, such as stepCountIs(10) to cap turns or maxCost(1.00) to set a budget, preventing runaway agent execution and ensuring cost control.
Furthermore, the SDK provides robust streaming capabilities, allowing agents to show real-time progress. With functions like getTextStream(), getToolCallsStream(), and getReasoningStream(), developers can concurrently process different aspects of the agent's response, enhancing user experience. Every agent run also includes integrated cost tracking and token counts via result.getResponse(), offering transparency into usage. A notable feature is tool approval, which allows the SDK to pause execution and await user confirmation before critical real-world actions are taken. Being model-agnostic, the SDK works with over 300 models on OpenRouter, giving developers unparalleled flexibility to swap models without code changes.
To get started, developers can acquire an OpenRouter API key and delve into the comprehensive callModel SDK Documentation. OpenRouter also provides a practical tutorial on creating an Agent TUI using the SDK, demonstrating its capabilities in building interactive agent interfaces. For further discussion, community support, and sharing insights on agent development, the OpenRouter Discord channel is available.
Summary
- OpenRouter's new
@openrouter/agentTypeScript SDK significantly simplifies the development of multi-turn AI agent workflows. - The
callModelfunction handles complex behaviors like tool execution, multi-turn looping, streaming, and integrated cost tracking. - The SDK is model-agnostic, supporting over 300 models on the OpenRouter platform without requiring code changes.
- Developers gain robust control through features such as Zod-validated tool definitions, composable stop conditions (e.g.,
maxCost), and optional tool approval mechanisms.
Source: Agent SDK: Building Multi-turn Agent Workflows on OpenRouter
Read next

Cursor AI Boosts Dev Workflow with Parallel Tasks, Worktrees, and Cross-Repo Changes
Cursor's latest update introduces `/multitask` for parallel agent execution, enhanced worktrees, and multi-root workspaces to streamline cross-repository development.
Continue reading