Skip to content

Commit ee03388

Browse files
authored
Doc updates (#52)
2 parents 00d6b82 + 9f1990a commit ee03388

File tree

163 files changed

+276
-2813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+276
-2813
lines changed

.speakeasy/gen.lock

Lines changed: 93 additions & 93 deletions
Large diffs are not rendered by default.

.speakeasy/gen.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ generation:
2929
generateNewTests: true
3030
skipResponseBodyAssertions: false
3131
typescript:
32-
version: 0.0.1
32+
version: 0.1.0
3333
acceptHeaderEnum: false
3434
additionalDependencies:
3535
dependencies: {}
@@ -39,6 +39,7 @@ typescript:
3939
vitest: ^3.2.4
4040
peerDependencies: {}
4141
additionalPackageJSON: {}
42+
additionalScripts: {}
4243
author: OpenRouter
4344
baseErrorName: OpenRouterError
4445
clientServerStatusCodesAsErrors: true

.speakeasy/workflow.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
speakeasyVersion: 1.643.2
1+
speakeasyVersion: 1.648.1
22
sources:
33
OpenRouter API:
44
sourceNamespace: open-router-chat-completions-api
@@ -14,7 +14,7 @@ targets:
1414
sourceRevisionDigest: sha256:1076c98248df2a8c6c6a22cb2fcefd3a517f2dc346c0c5b410abfe301bdb1dad
1515
sourceBlobDigest: sha256:da053f100fc1b8b64975f7612dd8970661444f9156cd295a6cc49fd5914e8247
1616
codeSamplesNamespace: open-router-chat-completions-api-typescript-code-samples
17-
codeSamplesRevisionDigest: sha256:5ebfa7c0a3f1ea7ef487fc4560666289a2a46e64eb7aefa144a760cb61a65dd4
17+
codeSamplesRevisionDigest: sha256:812e850dbf1a556527446c6d855475fd5019953bfb0156058fd5e003beb83b79
1818
workflow:
1919
workflowVersion: 1.0.0
2020
speakeasyVersion: latest

FUNCTIONS.md

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -29,115 +29,7 @@ const openRouter = new OpenRouterCore({
2929
});
3030

3131
async function run() {
32-
const res = await betaResponsesSend(openRouter, {
33-
input: [
34-
{
35-
type: "message",
36-
role: "user",
37-
content: "Hello, how are you?",
38-
},
39-
],
40-
instructions: "<value>",
41-
metadata: {
42-
"user_id": "123",
43-
"session_id": "abc-def-ghi",
44-
},
45-
tools: [
46-
{
47-
type: "function",
48-
name: "get_current_weather",
49-
description: "Get the current weather in a given location",
50-
strict: true,
51-
parameters: {
52-
"type": "object",
53-
"properties": {
54-
"location": {
55-
"type": "string",
56-
},
57-
},
58-
},
59-
},
60-
],
61-
toolChoice: {
62-
type: "function",
63-
name: "<value>",
64-
},
65-
parallelToolCalls: true,
66-
model: "anthropic/claude-4.5-sonnet-20250929",
67-
models: [
68-
"<value 1>",
69-
],
70-
text: {
71-
format: {
72-
type: "text",
73-
},
74-
verbosity: "medium",
75-
},
76-
reasoning: {
77-
effort: "high",
78-
summary: "auto",
79-
maxTokens: 8661.16,
80-
enabled: true,
81-
},
82-
maxOutputTokens: null,
83-
temperature: 0.7,
84-
topP: 0.9,
85-
topK: 193.77,
86-
promptCacheKey: "<value>",
87-
previousResponseId: "<id>",
88-
prompt: {
89-
id: "<id>",
90-
variables: {
91-
"key": {
92-
type: "input_text",
93-
text: "Hello, how can I help you?",
94-
},
95-
},
96-
},
97-
include: [
98-
"reasoning.encrypted_content",
99-
],
100-
background: true,
101-
safetyIdentifier: "<value>",
102-
store: true,
103-
serviceTier: "auto",
104-
truncation: "auto",
105-
provider: {
106-
allowFallbacks: null,
107-
requireParameters: true,
108-
dataCollection: "deny",
109-
zdr: true,
110-
order: [
111-
"OpenAI",
112-
],
113-
only: [
114-
"OpenAI",
115-
],
116-
ignore: null,
117-
quantizations: [
118-
"fp16",
119-
],
120-
sort: "price",
121-
maxPrice: {
122-
prompt: "1000",
123-
completion: 1000,
124-
image: 1000,
125-
audio: "1000",
126-
request: 1000,
127-
},
128-
experimental: {},
129-
},
130-
plugins: [
131-
{
132-
id: "file-parser",
133-
maxFiles: 4870.55,
134-
pdf: {
135-
engine: "mistral-ocr",
136-
},
137-
},
138-
],
139-
user: "Elmer_Yundt72",
140-
});
32+
const res = await betaResponsesSend(openRouter, {});
14133
if (res.ok) {
14234
const { value: result } = res;
14335
console.log(result);

OVERVIEW.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# OpenRouter TypeScript SDK
2+
3+
The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.
4+
5+
## Why use the OpenRouter SDK?
6+
7+
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.
8+
9+
```typescript
10+
import OpenRouter from '@openrouter/sdk';
11+
12+
const client = new OpenRouter({
13+
apiKey: process.env.OPENROUTER_API_KEY
14+
});
15+
16+
const response = await client.chat.completions.create({
17+
model: "minimax/minimax-m2",
18+
messages: [
19+
{ role: "user", content: "Explain quantum computing" }
20+
]
21+
});
22+
```
23+
24+
The SDK provides three core benefits:
25+
26+
### Auto-generated from API specifications
27+
28+
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.
29+
30+
```typescript
31+
// When new models launch, they're available instantly
32+
const response = await client.chat.completions.create({
33+
model: "minimax/minimax-m2",
34+
});
35+
```
36+
37+
### Type-safe by default
38+
39+
Every parameter, response field, and configuration option is fully typed. Invalid configurations are caught at compile time, not in production.
40+
41+
```typescript
42+
const response = await client.chat.completions.create({
43+
model: "minimax/minimax-m2",
44+
messages: [
45+
{ role: "user", content: "Hello" }
46+
// ← Your IDE validates message structure
47+
],
48+
temperature: 0.7, // ← Type-checked
49+
stream: true // ← Response type changes based on this
50+
});
51+
```
52+
53+
**Actionable error messages:**
54+
55+
```typescript
56+
// Instead of generic errors, get specific guidance:
57+
// "Model 'openai/o1-preview' requires at least 2 messages.
58+
// You provided 1 message. Add a system or user message."
59+
```
60+
61+
**Type-safe streaming:**
62+
63+
```typescript
64+
const stream = await client.chat.completions.create({
65+
model: "minimax/minimax-m2",
66+
messages: [{ role: "user", content: "Write a story" }],
67+
stream: true
68+
});
69+
70+
for await (const chunk of stream) {
71+
// Full type information for streaming responses
72+
const content = chunk.choices[0]?.delta?.content;
73+
}
74+
```
75+
76+
## Installation
77+
78+
```bash
79+
npm install @openrouter/sdk
80+
```
81+
82+
Get your API key from [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys).
83+
84+
## Quick start
85+
86+
```typescript
87+
import OpenRouter from '@openrouter/sdk';
88+
89+
const client = new OpenRouter({
90+
apiKey: process.env.OPENROUTER_API_KEY
91+
});
92+
93+
const response = await client.chat.completions.create({
94+
model: "minimax/minimax-m2",
95+
messages: [
96+
{ role: "user", content: "Hello!" }
97+
]
98+
});
99+
100+
console.log(response.choices[0].message.content);
101+
```

0 commit comments

Comments
 (0)