openrouter-typescript-sdk

Integrates 300+ AI models through the OpenRouter TypeScript SDK callModel pattern.

2|1|Updated Jun 9, 2026
One-click install
npx skills add https://github.com/zester4/zilmate --skill openrouter-typescript-sdk-zester4
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: openrouter-typescript-sdk
Source: https://github.com/zester4/zilmate/tree/main/.agents/skills/openrouter-typescript-sdk
Command: npx skills add https://github.com/zester4/zilmate --skill openrouter-typescript-sdk-zester4

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @openrouter/sdk, zod.

What problem does it solve? Building applications that call multiple AI models usually means juggling different provider APIs, authentication schemes, and response formats. This Skill provides a complete reference for the OpenRouter TypeScript SDK, giving you one type-safe interface to access 300+ models with unified tool calling, streaming, and multi-turn conversation handling. ## Core Features & Use Cases - Unified callModel Interface: Send text, message arrays, or multimodal input to any supported model and consume results via getText(), getResponse(), or streaming methods. - Typed Tool System: Define tools with Zod schemas for automatic validation, automatic execution, generator tools with progress events, and stop conditions like stepCountIs and maxCost. - Authentication Options: Use API keys for server-side apps or the OAuth PKCE flow for user-facing applications, plus programmatic API key management. - Use Case: Build a research agent that searches the web via a custom tool, streams progress to the user, stops after 10 turns or when a finish tool is called, and converts responses between OpenAI and Claude message formats. ## Quick Start Install @openrouter/sdk, set your OPENROUTER_API_KEY environment variable, and ask the agent to write a TypeScript script that calls a model with client.callModel and prints the streamed response.

Frequently Asked Questions about openrouter-typescript-sdk

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call an AI model with the OpenRouter TypeScript SDK?

Install @openrouter/sdk, create a client with your API key, and call client.callModel with a model identifier and input. Await result.getText() for the full text or iterate result.getTextStream() for streaming deltas.

How do I add tool calling to an OpenRouter agent?

Define tools with the tool() helper using Zod input and output schemas, then pass them in the tools array of callModel. The SDK validates arguments, executes the tools automatically, and continues the conversation until a stop condition is met.

Does the OpenRouter SDK support streaming responses?

Yes, the result object exposes getTextStream(), getReasoningStream(), getToolCallsStream(), and getFullResponsesStream(). Multiple consumers can read from the same result object concurrently.

Can I use OAuth instead of API keys with OpenRouter?

Yes, the SDK supports an OAuth PKCE flow for user-facing applications. Call client.oAuth.createAuthCode to get an authorization URL, then exchange the returned code with exchangeAuthCodeForAPIKey to obtain a user-specific API key.

How do I prevent runaway costs in multi-turn tool loops?

Pass stop conditions via the stopWhen parameter, such as stepCountIs(10) to cap turns, maxCost(1.00) to limit spending, or hasToolCall('finish') to stop when a specific tool is called. Custom stop condition functions are also supported.

What do OpenRouter SDK error status codes mean?

Status 401 indicates an invalid API key, 402 means insufficient credits, 429 signals rate limiting, and 503 means the model is temporarily unavailable. Implement exponential backoff retries for 429 and 5xx errors.