
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
@openrouter/sdk
Advanced tools

The OpenRouter SDK is a TypeScript toolkit designed to help you build AI-powered features and solutions in any JS or TS based runtime. Giving you easy access to over 300 models across providers in an easy and type-safe way.
To learn more about how to use the OpenRouter SDK, check out our API Reference and Documentation.
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
npm add @openrouter/sdk
# Install optional peer dependencies if you plan to use React hooks
npm add @tanstack/react-query react react-dom
pnpm add @openrouter/sdk
# Install optional peer dependencies if you plan to use React hooks
pnpm add @tanstack/react-query react react-dom
bun add @openrouter/sdk
# Install optional peer dependencies if you plan to use React hooks
bun add @tanstack/react-query react react-dom
yarn add @openrouter/sdk
# Install optional peer dependencies if you plan to use React hooks
yarn add @tanstack/react-query react react-dom
[!NOTE] This package is published as an ES Module (ESM) only. For applications using CommonJS, use
await import("@openrouter/sdk")to import and use this package.
For supported JavaScript runtimes, please consult RUNTIMES.md.
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter();
const result = await openRouter.chat.send({
messages: [
{
role: "user",
content: "Hello, how are you?",
},
],
model: "openai/gpt-5"
provider: {
zdr: true,
sort: "price",
},
stream: true
});
for await (const chunk of stream) {
console.log(hunk.choices[0].delta.content)
}
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console's interface as an SDK option.
[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
import { OpenRouter } from "@openrouter/sdk";
const sdk = new OpenRouter({ debugLogger: console });
You can also enable a default debug logger by setting an environment variable OPENROUTER_DEBUG to true.
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
Copy the example environment file:
cp .env.example .env
Edit .env and add your OpenRouter API key:
OPENROUTER_API_KEY=your_api_key_here
Run the tests:
npx vitest
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
FAQs
The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.
The npm package @openrouter/sdk receives a total of 504,246 weekly downloads. As such, @openrouter/sdk popularity was classified as popular.
We found that @openrouter/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.