Agent SDK
Build AI agents with multi-turn loops, tools, and conversation state
Build AI agents with multi-turn loops, tools, and conversation state
The Agent SDK (@openrouter/agent) provides the primitives you need to build agentic applications on OpenRouter. Instead of manually wiring up conversation loops, tool dispatch, and state tracking, the Agent SDK handles all of that so you can focus on defining what your agent does.
The Agent SDK is built to work alongside the Client SDKs. Installing @openrouter/agent automatically includes the Client SDKs as well, but each package can work independently.
Choose the Agent SDK when you need agentic behavior — multi-step reasoning where the model calls tools, processes results, and decides what to do next:
callModel automatically loops until a stop condition is mettool() helper and the SDK executes them for youstepCountIs, hasToolCall, maxCost, and moreIf you only need simple request/response calls to a model without agent loops, the Client SDKs are a lighter-weight option.
The SDK sends the message to the model, receives a tool call, executes get_weather, feeds the result back, and returns the final response — all in one callModel invocation.
callModelThe main entry point. It runs an inference loop that:
See the Call Model documentation for the full API.
Define tools with the tool() helper. Each tool has a name, description, Zod parameter schema, and an execute function. The SDK handles serialization, validation, and dispatch.
Control when the agent loop terminates:
callModel API reference