openrouterteam/agent-skills/typescript-sdk
Claude Code and agent skill by openrouterteam/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Complete reference for integrating with 300+ AI models through the OpenRouter TypeScript SDK using the callModel pattern
Install
npx vskill@latest install openrouterteam/agent-skills/typescript-sdkSKILL.md
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
Setup
Get your API key from openrouter.ai/settings/keys, then initialize:
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
- Visit openrouter.ai/settings/keys
- Create a new API key
- Store securely in an environment variable
Environment Setup
Client Initialization
The client automatically uses this key for all subsequent requests:
Get Current Key Metadata
Retrieve information about the currently configured API key:
API Key Management
Programmatically manage API keys:
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:
Parameters:
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
callbackUrl | string | Yes | Your application's callback URL after user authorization |
Browser Redirect:
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:
Parameters:
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
code | string | Yes | The authorization code from the OAuth redirect |
Complete OAuth Flow Example
Security Best Practices
- Environment Variables: Store API keys in environment variables, never in code
- Key Rotation: Rotate keys periodically using the key management API
- Environment Separation: Use different keys for development, staging, and production
- OAuth for Users: Use the OAuth PKCE flow for user-facing apps to avoid handling user credentials
- Secure Storage: Store user API keys encrypted in your database
- Minimal Scope: Create keys with only the permissions needed
Core Concepts: callModel
The callModel function is the primary interface for text generation. It provides a unified, type-safe way to interact with any supported model.
Basic Usage
Key Benefits
- Type-safe parameters with full IDE autocomplete
- Auto-generated from OpenAPI specs - automatically updates with new models
- Multiple consumption patterns - text, streaming, structured data
- Automatic tool execution with multi-turn support
Input Formats
The SDK accepts flexible input types for the input parameter:
String Input
A simple string becomes a user message:
Message Arrays
For multi-turn conversations:
Multimodal Content
Including images and text:
System Instructions
Use the instructions parameter for system-level guidance:
Response Methods
The result object provides multiple methods for consuming the response:
| Method | Purpose | |
|---|---|---|
getText() | Get complete text after all tools complete | |
getResponse() | Full response object with token usage | |
getTextStream() | Stream text deltas as they arrive | |
getReasoningStream() | Stream reasoning tokens (for o1/reasoning models) | |
getToolCallsStream() | Stream tool calls as they complete |
getText()
getResponse()
getTextStream()
Tool System
Create strongly-typed tools using Zod schemas for automatic validation and type inference.
Defining Tools
Using Tools with callModel
Tool Types
Regular Tools
Standard execute functions that return a result:
Generator Tools
Yield progress events using eventSchema:
Manual Tools
Set execute: false to handle tool calls yourself:
Multi-Turn Conversations with Stop Conditions
Control automatic tool execution with stop conditions:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/typescript-sdk/SKILL.md
Popularity
- Repository stars
- 27
- Repository forks
- 10
- 7-day trend score
- 17
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 27 Apr 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/openrouterteam/agent-skills/typescript-sdk)