OpenRouter TypeScript SDK Brings Typed Tool Context to AI Agents

OpenRouterOpenRouter

· Updated

OpenRouter's TypeScript SDK now supports typed tool context. Define a contextSchema on your tools and mutate context across agentic turns — changes persist and are Zod-validated. A research agent can accumulate sources across iterations.

OpenRouter's SDK adds typed context and state for AI agents. Define a contextSchema on your tools, pass context from callModel keyed by tool name, then mutate it mid-execution using setContext() — changes persist across turns and are Zod-validated. A research agent accumulates sources as it iterates, keeping memory between calls.

The feature ties state directly to individual tools rather than managing it externally. Context is keyed per tool name and type-checked at runtime, so each tool in an agentic workflow carries its own validated state across turns without additional wiring.

Add contextSchema to your tool definitions and let setContext() handle persistence. The SDK supports TypeScript and Python, with Go and Java also available.

OpenRouter
OpenRouter
@OpenRouter
X

New in the OpenRouter TypeScript SDK: typed tool context/state. Define a contextSchema on tools. Pass context from callModel keyed by tool name. Mutate it mid-execution with `setContext()`. Changes persist across turns and are Zod-validated. Here's a research agent that builds up sources as it goes:

2retweets
View on X

Every HeadsUpAI update is written based on its original source and reviewed before it's published. Read our editorial standards →

Share this update