Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 93 additions & 93 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ generation:
generateNewTests: true
skipResponseBodyAssertions: false
typescript:
version: 0.0.1
version: 0.1.0
acceptHeaderEnum: false
additionalDependencies:
dependencies: {}
Expand All @@ -39,6 +39,7 @@ typescript:
vitest: ^3.2.4
peerDependencies: {}
additionalPackageJSON: {}
additionalScripts: {}
author: OpenRouter
baseErrorName: OpenRouterError
clientServerStatusCodesAsErrors: true
Expand Down
4 changes: 2 additions & 2 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
speakeasyVersion: 1.643.2
speakeasyVersion: 1.648.1
sources:
OpenRouter API:
sourceNamespace: open-router-chat-completions-api
Expand All @@ -14,7 +14,7 @@ targets:
sourceRevisionDigest: sha256:1076c98248df2a8c6c6a22cb2fcefd3a517f2dc346c0c5b410abfe301bdb1dad
sourceBlobDigest: sha256:da053f100fc1b8b64975f7612dd8970661444f9156cd295a6cc49fd5914e8247
codeSamplesNamespace: open-router-chat-completions-api-typescript-code-samples
codeSamplesRevisionDigest: sha256:5ebfa7c0a3f1ea7ef487fc4560666289a2a46e64eb7aefa144a760cb61a65dd4
codeSamplesRevisionDigest: sha256:812e850dbf1a556527446c6d855475fd5019953bfb0156058fd5e003beb83b79
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
110 changes: 1 addition & 109 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,115 +29,7 @@ const openRouter = new OpenRouterCore({
});

async function run() {
const res = await betaResponsesSend(openRouter, {
input: [
{
type: "message",
role: "user",
content: "Hello, how are you?",
},
],
instructions: "<value>",
metadata: {
"user_id": "123",
"session_id": "abc-def-ghi",
},
tools: [
{
type: "function",
name: "get_current_weather",
description: "Get the current weather in a given location",
strict: true,
parameters: {
"type": "object",
"properties": {
"location": {
"type": "string",
},
},
},
},
],
toolChoice: {
type: "function",
name: "<value>",
},
parallelToolCalls: true,
model: "anthropic/claude-4.5-sonnet-20250929",
models: [
"<value 1>",
],
text: {
format: {
type: "text",
},
verbosity: "medium",
},
reasoning: {
effort: "high",
summary: "auto",
maxTokens: 8661.16,
enabled: true,
},
maxOutputTokens: null,
temperature: 0.7,
topP: 0.9,
topK: 193.77,
promptCacheKey: "<value>",
previousResponseId: "<id>",
prompt: {
id: "<id>",
variables: {
"key": {
type: "input_text",
text: "Hello, how can I help you?",
},
},
},
include: [
"reasoning.encrypted_content",
],
background: true,
safetyIdentifier: "<value>",
store: true,
serviceTier: "auto",
truncation: "auto",
provider: {
allowFallbacks: null,
requireParameters: true,
dataCollection: "deny",
zdr: true,
order: [
"OpenAI",
],
only: [
"OpenAI",
],
ignore: null,
quantizations: [
"fp16",
],
sort: "price",
maxPrice: {
prompt: "1000",
completion: 1000,
image: 1000,
audio: "1000",
request: 1000,
},
experimental: {},
},
plugins: [
{
id: "file-parser",
maxFiles: 4870.55,
pdf: {
engine: "mistral-ocr",
},
},
],
user: "Elmer_Yundt72",
});
const res = await betaResponsesSend(openRouter, {});
if (res.ok) {
const { value: result } = res;
console.log(result);
Expand Down
101 changes: 101 additions & 0 deletions OVERVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# OpenRouter TypeScript SDK

The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.

## Why use the OpenRouter SDK?

Integrating AI models into applications involves handling different provider APIs, managing model-specific requirements, and avoiding common implementation mistakes. The OpenRouter SDK standardizes these integrations and protects you from footguns.

```typescript
import OpenRouter from '@openrouter/sdk';

const client = new OpenRouter({
apiKey: process.env.OPENROUTER_API_KEY
});

const response = await client.chat.completions.create({
model: "minimax/minimax-m2",
messages: [
{ role: "user", content: "Explain quantum computing" }
]
});
```

The SDK provides three core benefits:

### Auto-generated from API specifications

The SDK is automatically generated from OpenRouter's OpenAPI specs and updated with every API change. New models, parameters, and features appear in your IDE autocomplete immediately. No manual updates. No version drift.

```typescript
// When new models launch, they're available instantly
const response = await client.chat.completions.create({
model: "minimax/minimax-m2",
});
```

### Type-safe by default

Every parameter, response field, and configuration option is fully typed. Invalid configurations are caught at compile time, not in production.

```typescript
const response = await client.chat.completions.create({
model: "minimax/minimax-m2",
messages: [
{ role: "user", content: "Hello" }
// ← Your IDE validates message structure
],
temperature: 0.7, // ← Type-checked
stream: true // ← Response type changes based on this
});
```

**Actionable error messages:**

```typescript
// Instead of generic errors, get specific guidance:
// "Model 'openai/o1-preview' requires at least 2 messages.
// You provided 1 message. Add a system or user message."
```

**Type-safe streaming:**

```typescript
const stream = await client.chat.completions.create({
model: "minimax/minimax-m2",
messages: [{ role: "user", content: "Write a story" }],
stream: true
});

for await (const chunk of stream) {
// Full type information for streaming responses
const content = chunk.choices[0]?.delta?.content;
}
```

## Installation

```bash
npm install @openrouter/sdk
```

Get your API key from [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys).

## Quick start

```typescript
import OpenRouter from '@openrouter/sdk';

const client = new OpenRouter({
apiKey: process.env.OPENROUTER_API_KEY
});

const response = await client.chat.completions.create({
model: "minimax/minimax-m2",
messages: [
{ role: "user", content: "Hello!" }
]
});

console.log(response.choices[0].message.content);
```
Loading