
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
@openrouter/sdk
Advanced tools
The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 400+ language models through a unified API.

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 400+ 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
pnpm add @openrouter/sdk
bun add @openrouter/sdk
yarn add @openrouter/sdk
[!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.
callModel to @openrouter/agent[!IMPORTANT]
callModeland its associated types have moved to the@openrouter/agentpackage. If you are usingcallModel, tool definitions, or related types from@openrouter/sdk, you should migrate to@openrouter/agent.To assist with the migration, run:
npx skills add OpenRouterTeam/skills --skill openrouter-agent-migration
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 result) {
console.log(chunk.choices[0].delta.content)
}
Some of the endpoints in this SDK support pagination. To use pagination, you
make your SDK calls as usual, but the returned response object will also be an
async iterable that can be consumed using the for await...of
syntax.
Here's an example of one such pagination call:
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.byok.list();
for await (const page of result) {
console.log(page);
}
}
run();
Certain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
[!TIP]
Depending on your JavaScript runtime, there are convenient utilities that return a handle to a file without reading the entire contents into memory:
- Node.js v20+: Since v20, Node.js comes with a native
openAsBlobfunction innode:fs.- Bun: The native
Bun.filefunction produces a file handle that can be used for streaming file uploads.- Browsers: All supported browsers return an instance to a
Filewhen reading the value from an<input type="file">element.- Node.js v18: A file stream can be created using the
fileFromhelper fromfetch-blob/from.js.
import { OpenRouter } from "@openrouter/sdk";
import { openAsBlob } from "node:fs";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.files.upload({
requestBody: {
file: await openAsBlob("example.file"),
},
});
console.log(result);
}
run();
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
FAQs
The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 400+ language models through a unified API.
The npm package @openrouter/sdk receives a total of 471,703 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 7 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.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.