
Openrouter Typescript Sdk
Wire your TypeScript app or agent to 300+ models through OpenRouter using the type-safe callModel pattern, streaming, and tools.
Overview
openrouter-typescript-sdk is an agent skill for the Build phase that teaches type-safe OpenRouter integration in TypeScript via callModel, streaming, tools, and multi-turn conversations across 300+ models.
Install
npx skills add https://github.com/openrouterteam/agent-skills --skill openrouter-typescript-sdkWhat is this skill?
- Reference skill for @openrouter/sdk with the callModel pattern for generation, tools, streaming, and multi-turn chat
- Documents API key auth and OAuth PKCE for user-facing apps
- Single client access to 300+ models via OpenRouter’s unified API
- TypeScript-first setup with environment-based OPENROUTER_API_KEY
- Covers installation, client initialization, and authentication flows end-to-end
- 300+ AI models via unified API
Adoption & trust: 1.9k installs on skills.sh; 28 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need one maintained TypeScript pattern to call many LLM providers without copy-pasting disparate SDK docs into your agent session.
Who is it for?
TypeScript SaaS and agent backends that route inference through OpenRouter during feature development.
Skip if: Python-only stacks, teams that standardize on a single vendor native SDK only, or non-coding GTM tasks with no API integration work.
When should I use this skill?
You are implementing or debugging TypeScript code that uses @openrouter/sdk for generation, tools, streaming, or authenticated user sessions.
What do I get? / Deliverables
Your agent implements a configured OpenRouter client, correct auth, and callModel usage so your app can swap models and use streaming or tools reliably.
- Configured OpenRouter client
- callModel integration patterns
- Auth setup for API key or PKCE
Recommended Skills
Journey fit
SDK integration happens while you build the product surface that calls models—not during idea research or post-launch SEO. This is third-party API/SDK wiring for model routing, auth, and conversation flows—classic integrations work.
How it compares
SDK integration reference for a unified model router—not a prompt library or local model runner skill.
Common Questions / FAQ
Who is openrouter-typescript-sdk for?
Solo builders and small teams shipping TypeScript services or agents who want OpenRouter’s multi-model API with documented callModel, streaming, and tool patterns.
When should I use openrouter-typescript-sdk?
During Build while you add or refactor LLM calls, OAuth flows, or streaming chat in your codebase—typically under integrations or agent-tooling work.
Is openrouter-typescript-sdk safe to install?
Check the Security Audits panel on this Prism page; the skill instructs API key usage—never commit keys and scope OAuth appropriately for user-facing apps.
SKILL.md
READMESKILL.md - Openrouter Typescript Sdk
# OpenRouter TypeScript SDK A comprehensive TypeScript SDK for interacting with OpenRouter's unified API, providing access to 300+ AI models through a single, type-safe interface. This skill enables AI agents to leverage the `callModel` pattern for text generation, tool usage, streaming, and multi-turn conversations. --- ## Installation ```bash npm install @openrouter/sdk ``` ## Setup Get your API key from [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys), then initialize: ```typescript import OpenRouter from '@openrouter/sdk'; const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }); ``` --- ## Authentication The SDK supports two authentication methods: API keys for server-side applications and OAuth PKCE flow for user-facing applications. ### API Key Authentication The primary authentication method uses API keys from your OpenRouter account. #### Obtaining an API Key 1. Visit [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys) 2. Create a new API key 3. Store securely in an environment variable #### Environment Setup ```bash export OPENROUTER_API_KEY=sk-or-v1-your-key-here ``` #### Client Initialization ```typescript import OpenRouter from '@openrouter/sdk'; const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }); ``` The client automatically uses this key for all subsequent requests: ```typescript // API key is automatically included const result = client.callModel({ model: 'openai/gpt-5-nano', input: 'Hello!' }); ``` #### Get Current Key Metadata Retrieve information about the currently configured API key: ```typescript const keyInfo = await client.apiKeys.getCurrentKeyMetadata(); console.log('Key name:', keyInfo.name); console.log('Created:', keyInfo.createdAt); ``` #### API Key Management Programmatically manage API keys: ```typescript // List all keys const keys = await client.apiKeys.list(); // Create a new key const newKey = await client.apiKeys.create({ name: 'Production API Key' }); // Get a specific key by hash const key = await client.apiKeys.get({ hash: 'sk-or-v1-...' }); // Update a key await client.apiKeys.update({ hash: 'sk-or-v1-...', requestBody: { name: 'Updated Key Name' } }); // Delete a key await client.apiKeys.delete({ hash: 'sk-or-v1-...' }); ``` ### OAuth Authentication (PKCE Flow) For user-facing applications where users should control their own API keys, OpenRouter supports OAuth with PKCE (Proof Key for Code Exchange). This flow allows users to generate API keys through a browser authorization flow without your application handling their credentials. #### createAuthCode Generate an authorization code and URL to start the OAuth flow: ```typescript const authResponse = await client.oAuth.createAuthCode({ callbackUrl: 'https://myapp.com/auth/callback' }); // authResponse contains: // - authorizationUrl: URL to redirect the user to // - code: The authorization code for later exchange console.log('Redirect user to:', authResponse.authorizationUrl); ``` **Parameters:** | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | `callbackUrl` | `string` | Yes | Your application's callback URL after user authorization | **Browser Redirect:** ```typescript // In a browser environment window.location.href = authResponse.authorizationUrl; // Or in a server-rendered app, return a redirect response res.redirect(authResponse.authorizationUrl); ``` #### exchangeAuthCodeForAPIKey After the user authorizes your application, they are redirected back to your callback URL with an authorization code. Exchange this code for an API key: ```typescript // In your callback handler const code = req.query.code; // From the redirect URL const apiKeyResponse = await cl