sp-openrouter

Provides reference guidance for integrating 300+ AI models via the OpenRouter TypeScript SDK.

Updated Aug 30, 2026
One-click install
npx skills add https://github.com/Mushfiq2002/stack-cost --skill sp-openrouter-mushfiq2002
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sp-openrouter
Source: https://github.com/Mushfiq2002/stack-cost/tree/main/.agents/skills/sp-openrouter
Command: npx skills add https://github.com/Mushfiq2002/stack-cost --skill sp-openrouter-mushfiq2002

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers integrating OpenRouter into TypeScript applications need accurate, up-to-date guidance on the SDK's callModel pattern, authentication, tools, and streaming without digging through external documentation. ## Core Features & Use Cases - callModel Integration: Covers text generation, streaming, structured responses, and multi-turn conversations through a unified type-safe interface. - Authentication Setup: Documents API key management and the OAuth PKCE flow for user-facing applications. - Tool System & Stop Conditions: Explains Zod-based tool definitions, automatic tool execution, and stop conditions like stepCountIs and maxCost. - Use Case: While building a Next.js app that calls OpenRouter free-tier models, use this Skill to correctly implement the client setup, fallback model chains, and streaming response handling. ## Quick Start Ask the AI to show how to initialize the OpenRouter client and make a streaming callModel request with a tool attached.

Frequently Asked Questions about sp-openrouter

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?

Use the callModel function from @openrouter/agent with a model slug and input string, then await result.getText() for the response. Initialize the client with your OPENROUTER_API_KEY environment variable first.

What is the difference between @openrouter/agent and @openrouter/sdk?

@openrouter/agent provides agent features like callModel, tool definitions, stop conditions, and streaming. @openrouter/sdk covers platform features such as model listing, credits, OAuth, and API key management.

Does the OpenRouter SDK support streaming responses?

Yes, the result object exposes getTextStream() for text deltas, getReasoningStream() for reasoning tokens, and getToolCallsStream() for tool calls. Multiple consumers can read from a single result concurrently.

How do I add tool calling to an OpenRouter request?

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

Can I use OAuth instead of API keys with OpenRouter?

Yes, the SDK supports an OAuth PKCE flow using createAuthCode to generate an authorization URL and exchangeAuthCodeForAPIKey to trade the returned code for a user-specific API key.

Why does my OpenRouter call fail with a 402 error?

A 402 error means the account has no credits and the requested model is paid. Use :free model slugs as a fallback chain and verify current model identifiers at the OpenRouter models endpoint.