@openrouter/sdk 0.0.1-beta.16 → 0.0.1-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,30 +1,14 @@
1
+ ![hero illustration](./assets/banner.png)
2
+
1
3
  # OpenRouter SDK (Beta)
2
4
 
3
- The [OpenRouter](https://openrouter.ai/) SDK gives access to over 300 large language models on the OpenRouter chat and completion APIs, as well as the rest of our full API. For more information about the API: [OpenRouter Documentation](https://openrouter.ai/docs)
5
+ The [OpenRouter SDK](https://openrouter.ai/docs/sdks/typescript) 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.
4
6
 
5
- <!-- No Summary [summary] -->
7
+ To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/typescript/reference) and [Documentation](https://openrouter.ai/docs/sdks/typescript).
6
8
 
7
- <!-- Start Table of Contents [toc] -->
8
- ## Table of Contents
9
- <!-- $toc-max-depth=2 -->
10
- * [OpenRouter SDK (Beta)](#openrouter-sdk-beta)
11
- * [SDK Installation](#sdk-installation)
12
- * [Requirements](#requirements)
13
- * [SDK Example Usage](#sdk-example-usage)
14
- * [Authentication](#authentication)
15
- * [Available Resources and Operations](#available-resources-and-operations)
16
- * [Standalone functions](#standalone-functions)
17
- * [React hooks with TanStack Query](#react-hooks-with-tanstack-query)
18
- * [Server-sent event streaming](#server-sent-event-streaming)
19
- * [Retries](#retries)
20
- * [Error Handling](#error-handling)
21
- * [Debugging](#debugging)
22
- * [Development](#development)
23
- * [Running Tests](#running-tests)
24
- * [Maturity](#maturity)
25
- * [Contributions](#contributions)
9
+ <!-- No Summary [summary] -->
26
10
 
27
- <!-- End Table of Contents [toc] -->
11
+ <!-- No Table of Contents [toc] -->
28
12
 
29
13
  <!-- Start SDK Installation [installation] -->
30
14
  ## SDK Installation
@@ -74,1067 +58,48 @@ yarn add @tanstack/react-query react react-dom
74
58
  For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
75
59
  <!-- End Requirements [requirements] -->
76
60
 
77
- <!-- Start SDK Example Usage [usage] -->
78
- ## SDK Example Usage
79
-
80
- ### Example
81
-
82
- ```typescript
83
- import { OpenRouter } from "@openrouter/sdk";
84
-
85
- const openRouter = new OpenRouter({
86
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
87
- });
88
-
89
- async function run() {
90
- const result = await openRouter.beta.responses.send({
91
- input: [
92
- {
93
- type: "message",
94
- role: "user",
95
- content: "Hello, how are you?",
96
- },
97
- ],
98
- instructions: "<value>",
99
- metadata: {
100
- "user_id": "123",
101
- "session_id": "abc-def-ghi",
102
- },
103
- tools: [
104
- {
105
- type: "function",
106
- name: "get_current_weather",
107
- description: "Get the current weather in a given location",
108
- strict: true,
109
- parameters: {
110
- "type": "object",
111
- "properties": {
112
- "location": {
113
- "type": "string",
114
- },
115
- },
116
- },
117
- },
118
- ],
119
- toolChoice: {
120
- type: "function",
121
- name: "<value>",
122
- },
123
- parallelToolCalls: true,
124
- model: "anthropic/claude-4.5-sonnet-20250929",
125
- models: [
126
- "<value 1>",
127
- ],
128
- text: {
129
- format: {
130
- type: "text",
131
- },
132
- verbosity: "medium",
133
- },
134
- reasoning: {
135
- effort: "high",
136
- summary: "auto",
137
- maxTokens: 8661.16,
138
- enabled: true,
139
- },
140
- maxOutputTokens: null,
141
- temperature: 0.7,
142
- topP: 0.9,
143
- topK: 193.77,
144
- promptCacheKey: "<value>",
145
- previousResponseId: "<id>",
146
- prompt: {
147
- id: "<id>",
148
- variables: {
149
- "key": {
150
- type: "input_text",
151
- text: "Hello, how can I help you?",
152
- },
153
- },
154
- },
155
- include: [
156
- "reasoning.encrypted_content",
157
- ],
158
- background: true,
159
- safetyIdentifier: "<value>",
160
- store: true,
161
- serviceTier: "auto",
162
- truncation: "auto",
163
- provider: {
164
- allowFallbacks: null,
165
- requireParameters: true,
166
- dataCollection: "deny",
167
- zdr: true,
168
- order: [
169
- "OpenAI",
170
- ],
171
- only: [
172
- "OpenAI",
173
- ],
174
- ignore: null,
175
- quantizations: [
176
- "fp16",
177
- ],
178
- sort: "price",
179
- maxPrice: {
180
- prompt: "1000",
181
- completion: 1000,
182
- image: 1000,
183
- audio: "1000",
184
- request: 1000,
185
- },
186
- experimental: {},
187
- },
188
- plugins: [
189
- {
190
- id: "file-parser",
191
- maxFiles: 4870.55,
192
- pdf: {
193
- engine: "mistral-ocr",
194
- },
195
- },
196
- ],
197
- user: "Elmer_Yundt72",
198
- });
199
-
200
- console.log(result);
201
- }
202
-
203
- run();
204
-
205
- ```
206
- <!-- End SDK Example Usage [usage] -->
207
-
208
- <!-- Start Authentication [security] -->
209
- ## Authentication
210
-
211
- ### Per-Client Security Schemes
212
-
213
- This SDK supports the following security scheme globally:
214
-
215
- | Name | Type | Scheme | Environment Variable |
216
- | -------- | ---- | ----------- | -------------------- |
217
- | `apiKey` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
218
-
219
- To authenticate with the API the `apiKey` parameter must be set when initializing the SDK client instance. For example:
220
- ```typescript
221
- import { OpenRouter } from "@openrouter/sdk";
222
-
223
- const openRouter = new OpenRouter({
224
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
225
- });
226
-
227
- async function run() {
228
- const result = await openRouter.beta.responses.send({
229
- input: [
230
- {
231
- type: "message",
232
- role: "user",
233
- content: "Hello, how are you?",
234
- },
235
- ],
236
- instructions: "<value>",
237
- metadata: {
238
- "user_id": "123",
239
- "session_id": "abc-def-ghi",
240
- },
241
- tools: [
242
- {
243
- type: "function",
244
- name: "get_current_weather",
245
- description: "Get the current weather in a given location",
246
- strict: true,
247
- parameters: {
248
- "type": "object",
249
- "properties": {
250
- "location": {
251
- "type": "string",
252
- },
253
- },
254
- },
255
- },
256
- ],
257
- toolChoice: {
258
- type: "function",
259
- name: "<value>",
260
- },
261
- parallelToolCalls: true,
262
- model: "anthropic/claude-4.5-sonnet-20250929",
263
- models: [
264
- "<value 1>",
265
- ],
266
- text: {
267
- format: {
268
- type: "text",
269
- },
270
- verbosity: "medium",
271
- },
272
- reasoning: {
273
- effort: "high",
274
- summary: "auto",
275
- maxTokens: 8661.16,
276
- enabled: true,
277
- },
278
- maxOutputTokens: null,
279
- temperature: 0.7,
280
- topP: 0.9,
281
- topK: 193.77,
282
- promptCacheKey: "<value>",
283
- previousResponseId: "<id>",
284
- prompt: {
285
- id: "<id>",
286
- variables: {
287
- "key": {
288
- type: "input_text",
289
- text: "Hello, how can I help you?",
290
- },
291
- },
292
- },
293
- include: [
294
- "reasoning.encrypted_content",
295
- ],
296
- background: true,
297
- safetyIdentifier: "<value>",
298
- store: true,
299
- serviceTier: "auto",
300
- truncation: "auto",
301
- provider: {
302
- allowFallbacks: null,
303
- requireParameters: true,
304
- dataCollection: "deny",
305
- zdr: true,
306
- order: [
307
- "OpenAI",
308
- ],
309
- only: [
310
- "OpenAI",
311
- ],
312
- ignore: null,
313
- quantizations: [
314
- "fp16",
315
- ],
316
- sort: "price",
317
- maxPrice: {
318
- prompt: "1000",
319
- completion: 1000,
320
- image: 1000,
321
- audio: "1000",
322
- request: 1000,
323
- },
324
- experimental: {},
325
- },
326
- plugins: [
327
- {
328
- id: "file-parser",
329
- maxFiles: 4870.55,
330
- pdf: {
331
- engine: "mistral-ocr",
332
- },
333
- },
334
- ],
335
- user: "Elmer_Yundt72",
336
- });
337
-
338
- console.log(result);
339
- }
340
-
341
- run();
342
-
343
- ```
344
-
345
- ### Per-Operation Security Schemes
61
+ <!-- No SDK Example Usage [usage] -->
62
+ ## SDK Usage
346
63
 
347
- Some operations in this SDK require the security scheme to be specified at the request level. For example:
348
64
  ```typescript
349
65
  import { OpenRouter } from "@openrouter/sdk";
350
66
 
351
67
  const openRouter = new OpenRouter();
352
68
 
353
- async function run() {
354
- const result = await openRouter.credits.createCoinbaseCharge({
355
- bearer: process.env["OPENROUTER_BEARER"] ?? "",
356
- }, {
357
- amount: 100,
358
- sender: "0x1234567890123456789012345678901234567890",
359
- chainId: 1,
360
- });
361
-
362
- console.log(result);
363
- }
364
-
365
- run();
366
-
367
- ```
368
- <!-- End Authentication [security] -->
369
-
370
- <!-- Start Available Resources and Operations [operations] -->
371
- ## Available Resources and Operations
372
-
373
- <details open>
374
- <summary>Available methods</summary>
375
-
376
- ### [analytics](docs/sdks/analytics/README.md)
377
-
378
- * [getUserActivity](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
379
-
380
- ### [apiKeys](docs/sdks/apikeys/README.md)
381
-
382
- * [list](docs/sdks/apikeys/README.md#list) - List API keys
383
- * [create](docs/sdks/apikeys/README.md#create) - Create a new API key
384
- * [update](docs/sdks/apikeys/README.md#update) - Update an API key
385
- * [delete](docs/sdks/apikeys/README.md#delete) - Delete an API key
386
- * [get](docs/sdks/apikeys/README.md#get) - Get a single API key
387
- * [getCurrentKeyMetadata](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
388
-
389
- #### [beta.responses](docs/sdks/responses/README.md)
390
-
391
- * [send](docs/sdks/responses/README.md#send) - Create a response
392
-
393
- ### [chat](docs/sdks/chat/README.md)
394
-
395
- * [send](docs/sdks/chat/README.md#send) - Create a chat completion
396
-
397
- ### [completions](docs/sdks/completions/README.md)
398
-
399
- * [generate](docs/sdks/completions/README.md#generate) - Create a completion
400
-
401
- ### [credits](docs/sdks/credits/README.md)
402
-
403
- * [getCredits](docs/sdks/credits/README.md#getcredits) - Get remaining credits
404
- * [createCoinbaseCharge](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
405
-
406
- ### [endpoints](docs/sdks/endpoints/README.md)
407
-
408
- * [list](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
409
- * [listZdrEndpoints](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
410
-
411
- ### [generations](docs/sdks/generations/README.md)
412
-
413
- * [getGeneration](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
414
-
415
- ### [models](docs/sdks/models/README.md)
416
-
417
- * [count](docs/sdks/models/README.md#count) - Get total count of available models
418
- * [list](docs/sdks/models/README.md#list) - List all models and their properties
419
- * [listForUser](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
420
-
421
- ### [oAuth](docs/sdks/oauth/README.md)
422
-
423
- * [exchangeAuthCodeForAPIKey](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
424
- * [createAuthCode](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
425
-
426
- ### [parameters](docs/sdks/parameters/README.md)
427
-
428
- * [getParameters](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
429
-
430
- ### [providers](docs/sdks/providers/README.md)
431
-
432
- * [list](docs/sdks/providers/README.md#list) - List all providers
433
-
434
- </details>
435
- <!-- End Available Resources and Operations [operations] -->
436
-
437
- <!-- Start Standalone functions [standalone-funcs] -->
438
- ## Standalone functions
439
-
440
- All the methods listed above are available as standalone functions. These
441
- functions are ideal for use in applications running in the browser, serverless
442
- runtimes or other environments where application bundle size is a primary
443
- concern. When using a bundler to build your application, all unused
444
- functionality will be either excluded from the final bundle or tree-shaken away.
445
-
446
- To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
447
-
448
- <details>
449
-
450
- <summary>Available standalone functions</summary>
451
-
452
- - [`analyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
453
- - [`apiKeysCreate`](docs/sdks/apikeys/README.md#create) - Create a new API key
454
- - [`apiKeysDelete`](docs/sdks/apikeys/README.md#delete) - Delete an API key
455
- - [`apiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
456
- - [`apiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
457
- - [`apiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
458
- - [`apiKeysUpdate`](docs/sdks/apikeys/README.md#update) - Update an API key
459
- - [`betaResponsesSend`](docs/sdks/responses/README.md#send) - Create a response
460
- - [`chatSend`](docs/sdks/chat/README.md#send) - Create a chat completion
461
- - [`completionsGenerate`](docs/sdks/completions/README.md#generate) - Create a completion
462
- - [`creditsCreateCoinbaseCharge`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
463
- - [`creditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
464
- - [`endpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
465
- - [`endpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
466
- - [`generationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
467
- - [`modelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
468
- - [`modelsList`](docs/sdks/models/README.md#list) - List all models and their properties
469
- - [`modelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
470
- - [`oAuthCreateAuthCode`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
471
- - [`oAuthExchangeAuthCodeForAPIKey`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
472
- - [`parametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
473
- - [`providersList`](docs/sdks/providers/README.md#list) - List all providers
474
-
475
- </details>
476
- <!-- End Standalone functions [standalone-funcs] -->
477
-
478
- <!-- Start React hooks with TanStack Query [react-query] -->
479
- ## React hooks with TanStack Query
480
-
481
- React hooks built on [TanStack Query][tanstack-query] are included in this SDK.
482
- These hooks and the utility functions provided alongside them can be used to
483
- build rich applications that pull data from the API using one of the most
484
- popular asynchronous state management library.
485
-
486
- [tanstack-query]: https://tanstack.com/query/v5/docs/framework/react/overview
487
-
488
- To learn about this feature and how to get started, check
489
- [REACT_QUERY.md](./REACT_QUERY.md).
490
-
491
- > [!WARNING]
492
- >
493
- > This feature is currently in **preview** and is subject to breaking changes
494
- > within the current major version of the SDK as we gather user feedback on it.
495
-
496
- <details>
497
-
498
- <summary>Available React hooks</summary>
499
-
500
- - [`useAnalyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
501
- - [`useApiKeysCreateMutation`](docs/sdks/apikeys/README.md#create) - Create a new API key
502
- - [`useApiKeysDeleteMutation`](docs/sdks/apikeys/README.md#delete) - Delete an API key
503
- - [`useApiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
504
- - [`useApiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
505
- - [`useApiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
506
- - [`useApiKeysUpdateMutation`](docs/sdks/apikeys/README.md#update) - Update an API key
507
- - [`useBetaResponsesSendMutation`](docs/sdks/responses/README.md#send) - Create a response
508
- - [`useChatSendMutation`](docs/sdks/chat/README.md#send) - Create a chat completion
509
- - [`useCompletionsGenerateMutation`](docs/sdks/completions/README.md#generate) - Create a completion
510
- - [`useCreditsCreateCoinbaseChargeMutation`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
511
- - [`useCreditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
512
- - [`useEndpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
513
- - [`useEndpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
514
- - [`useGenerationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
515
- - [`useModelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
516
- - [`useModelsList`](docs/sdks/models/README.md#list) - List all models and their properties
517
- - [`useModelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
518
- - [`useOAuthCreateAuthCodeMutation`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
519
- - [`useOAuthExchangeAuthCodeForAPIKeyMutation`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
520
- - [`useParametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
521
- - [`useProvidersList`](docs/sdks/providers/README.md#list) - List all providers
522
-
523
- </details>
524
- <!-- End React hooks with TanStack Query [react-query] -->
525
-
526
- <!-- Start Server-sent event streaming [eventstream] -->
527
- ## Server-sent event streaming
528
-
529
- [Server-sent events][mdn-sse] are used to stream content from certain
530
- operations. These operations will expose the stream as an async iterable that
531
- can be consumed using a [`for await...of`][mdn-for-await-of] loop. The loop will
532
- terminate when the server no longer has any events to send and closes the
533
- underlying connection.
534
-
535
- ```typescript
536
- import { OpenRouter } from "@openrouter/sdk";
537
-
538
- const openRouter = new OpenRouter({
539
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
540
- });
541
-
542
- async function run() {
543
- const result = await openRouter.beta.responses.send({
544
- input: [
545
- {
546
- type: "message",
547
- role: "user",
548
- content: "Hello, how are you?",
549
- },
550
- ],
551
- instructions: "<value>",
552
- metadata: {
553
- "user_id": "123",
554
- "session_id": "abc-def-ghi",
555
- },
556
- tools: [
557
- {
558
- type: "function",
559
- name: "get_current_weather",
560
- description: "Get the current weather in a given location",
561
- strict: true,
562
- parameters: {
563
- "type": "object",
564
- "properties": {
565
- "location": {
566
- "type": "string",
567
- },
568
- },
569
- },
570
- },
571
- ],
572
- toolChoice: {
573
- type: "function",
574
- name: "<value>",
575
- },
576
- parallelToolCalls: true,
577
- model: "anthropic/claude-4.5-sonnet-20250929",
578
- models: [
579
- "<value 1>",
580
- ],
581
- text: {
582
- format: {
583
- type: "text",
584
- },
585
- verbosity: "medium",
586
- },
587
- reasoning: {
588
- effort: "high",
589
- summary: "auto",
590
- maxTokens: 8661.16,
591
- enabled: true,
592
- },
593
- maxOutputTokens: null,
594
- temperature: 0.7,
595
- topP: 0.9,
596
- topK: 193.77,
597
- promptCacheKey: "<value>",
598
- previousResponseId: "<id>",
599
- prompt: {
600
- id: "<id>",
601
- variables: {
602
- "key": {
603
- type: "input_text",
604
- text: "Hello, how can I help you?",
605
- },
606
- },
607
- },
608
- include: [
609
- "reasoning.encrypted_content",
610
- ],
611
- background: true,
612
- safetyIdentifier: "<value>",
613
- store: true,
614
- serviceTier: "auto",
615
- truncation: "auto",
616
- provider: {
617
- allowFallbacks: null,
618
- requireParameters: true,
619
- dataCollection: "deny",
620
- zdr: true,
621
- order: [
622
- "OpenAI",
623
- ],
624
- only: [
625
- "OpenAI",
626
- ],
627
- ignore: null,
628
- quantizations: [
629
- "fp16",
630
- ],
631
- sort: "price",
632
- maxPrice: {
633
- prompt: "1000",
634
- completion: 1000,
635
- image: 1000,
636
- audio: "1000",
637
- request: 1000,
638
- },
639
- experimental: {},
640
- },
641
- plugins: [
642
- {
643
- id: "file-parser",
644
- maxFiles: 4870.55,
645
- pdf: {
646
- engine: "mistral-ocr",
647
- },
648
- },
649
- ],
650
- user: "Elmer_Yundt72",
651
- });
652
-
653
- console.log(result);
654
- }
655
-
656
- run();
657
-
658
- ```
659
-
660
- [mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
661
- [mdn-for-await-of]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
662
- <!-- End Server-sent event streaming [eventstream] -->
663
-
664
- <!-- Start Retries [retries] -->
665
- ## Retries
666
-
667
- Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
668
-
669
- To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
670
- ```typescript
671
- import { OpenRouter } from "@openrouter/sdk";
672
-
673
- const openRouter = new OpenRouter({
674
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
675
- });
676
-
677
- async function run() {
678
- const result = await openRouter.beta.responses.send({
679
- input: [
680
- {
681
- type: "message",
682
- role: "user",
683
- content: "Hello, how are you?",
684
- },
685
- ],
686
- instructions: "<value>",
687
- metadata: {
688
- "user_id": "123",
689
- "session_id": "abc-def-ghi",
690
- },
691
- tools: [
692
- {
693
- type: "function",
694
- name: "get_current_weather",
695
- description: "Get the current weather in a given location",
696
- strict: true,
697
- parameters: {
698
- "type": "object",
699
- "properties": {
700
- "location": {
701
- "type": "string",
702
- },
703
- },
704
- },
705
- },
706
- ],
707
- toolChoice: {
708
- type: "function",
709
- name: "<value>",
710
- },
711
- parallelToolCalls: true,
712
- model: "anthropic/claude-4.5-sonnet-20250929",
713
- models: [
714
- "<value 1>",
715
- ],
716
- text: {
717
- format: {
718
- type: "text",
719
- },
720
- verbosity: "medium",
721
- },
722
- reasoning: {
723
- effort: "high",
724
- summary: "auto",
725
- maxTokens: 8661.16,
726
- enabled: true,
727
- },
728
- maxOutputTokens: null,
729
- temperature: 0.7,
730
- topP: 0.9,
731
- topK: 193.77,
732
- promptCacheKey: "<value>",
733
- previousResponseId: "<id>",
734
- prompt: {
735
- id: "<id>",
736
- variables: {
737
- "key": {
738
- type: "input_text",
739
- text: "Hello, how can I help you?",
740
- },
741
- },
742
- },
743
- include: [
744
- "reasoning.encrypted_content",
745
- ],
746
- background: true,
747
- safetyIdentifier: "<value>",
748
- store: true,
749
- serviceTier: "auto",
750
- truncation: "auto",
751
- provider: {
752
- allowFallbacks: null,
753
- requireParameters: true,
754
- dataCollection: "deny",
755
- zdr: true,
756
- order: [
757
- "OpenAI",
758
- ],
759
- only: [
760
- "OpenAI",
761
- ],
762
- ignore: null,
763
- quantizations: [
764
- "fp16",
765
- ],
766
- sort: "price",
767
- maxPrice: {
768
- prompt: "1000",
769
- completion: 1000,
770
- image: 1000,
771
- audio: "1000",
772
- request: 1000,
773
- },
774
- experimental: {},
775
- },
776
- plugins: [
777
- {
778
- id: "file-parser",
779
- maxFiles: 4870.55,
780
- pdf: {
781
- engine: "mistral-ocr",
782
- },
783
- },
784
- ],
785
- user: "Elmer_Yundt72",
786
- }, {
787
- retries: {
788
- strategy: "backoff",
789
- backoff: {
790
- initialInterval: 1,
791
- maxInterval: 50,
792
- exponent: 1.1,
793
- maxElapsedTime: 100,
794
- },
795
- retryConnectionErrors: false,
796
- },
797
- });
798
-
799
- console.log(result);
800
- }
801
-
802
- run();
803
-
804
- ```
805
-
806
- If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
807
- ```typescript
808
- import { OpenRouter } from "@openrouter/sdk";
809
-
810
- const openRouter = new OpenRouter({
811
- retryConfig: {
812
- strategy: "backoff",
813
- backoff: {
814
- initialInterval: 1,
815
- maxInterval: 50,
816
- exponent: 1.1,
817
- maxElapsedTime: 100,
818
- },
819
- retryConnectionErrors: false,
69
+ const result = await openRouter.chat.send({
70
+ messages: [
71
+ {
72
+ role: "user",
73
+ content: "Hello, how are you?",
74
+ },
75
+ ],
76
+ model: "openai/gpt-5"
77
+ provider: {
78
+ zdr: true,
79
+ sort: "price",
820
80
  },
821
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
822
- });
823
-
824
- async function run() {
825
- const result = await openRouter.beta.responses.send({
826
- input: [
827
- {
828
- type: "message",
829
- role: "user",
830
- content: "Hello, how are you?",
831
- },
832
- ],
833
- instructions: "<value>",
834
- metadata: {
835
- "user_id": "123",
836
- "session_id": "abc-def-ghi",
837
- },
838
- tools: [
839
- {
840
- type: "function",
841
- name: "get_current_weather",
842
- description: "Get the current weather in a given location",
843
- strict: true,
844
- parameters: {
845
- "type": "object",
846
- "properties": {
847
- "location": {
848
- "type": "string",
849
- },
850
- },
851
- },
852
- },
853
- ],
854
- toolChoice: {
855
- type: "function",
856
- name: "<value>",
857
- },
858
- parallelToolCalls: true,
859
- model: "anthropic/claude-4.5-sonnet-20250929",
860
- models: [
861
- "<value 1>",
862
- ],
863
- text: {
864
- format: {
865
- type: "text",
866
- },
867
- verbosity: "medium",
868
- },
869
- reasoning: {
870
- effort: "high",
871
- summary: "auto",
872
- maxTokens: 8661.16,
873
- enabled: true,
874
- },
875
- maxOutputTokens: null,
876
- temperature: 0.7,
877
- topP: 0.9,
878
- topK: 193.77,
879
- promptCacheKey: "<value>",
880
- previousResponseId: "<id>",
881
- prompt: {
882
- id: "<id>",
883
- variables: {
884
- "key": {
885
- type: "input_text",
886
- text: "Hello, how can I help you?",
887
- },
888
- },
889
- },
890
- include: [
891
- "reasoning.encrypted_content",
892
- ],
893
- background: true,
894
- safetyIdentifier: "<value>",
895
- store: true,
896
- serviceTier: "auto",
897
- truncation: "auto",
898
- provider: {
899
- allowFallbacks: null,
900
- requireParameters: true,
901
- dataCollection: "deny",
902
- zdr: true,
903
- order: [
904
- "OpenAI",
905
- ],
906
- only: [
907
- "OpenAI",
908
- ],
909
- ignore: null,
910
- quantizations: [
911
- "fp16",
912
- ],
913
- sort: "price",
914
- maxPrice: {
915
- prompt: "1000",
916
- completion: 1000,
917
- image: 1000,
918
- audio: "1000",
919
- request: 1000,
920
- },
921
- experimental: {},
922
- },
923
- plugins: [
924
- {
925
- id: "file-parser",
926
- maxFiles: 4870.55,
927
- pdf: {
928
- engine: "mistral-ocr",
929
- },
930
- },
931
- ],
932
- user: "Elmer_Yundt72",
933
- });
934
-
935
- console.log(result);
936
- }
937
-
938
- run();
939
-
940
- ```
941
- <!-- End Retries [retries] -->
942
-
943
- <!-- Start Error Handling [errors] -->
944
- ## Error Handling
945
-
946
- [`OpenRouterError`](./src/models/errors/openroutererror.ts) is the base class for all HTTP error responses. It has the following properties:
947
-
948
- | Property | Type | Description |
949
- | ------------------- | ---------- | --------------------------------------------------------------------------------------- |
950
- | `error.message` | `string` | Error message |
951
- | `error.statusCode` | `number` | HTTP response status code eg `404` |
952
- | `error.headers` | `Headers` | HTTP response headers |
953
- | `error.body` | `string` | HTTP body. Can be empty string if no body is returned. |
954
- | `error.rawResponse` | `Response` | Raw HTTP response |
955
- | `error.data$` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
956
-
957
- ### Example
958
- ```typescript
959
- import { OpenRouter } from "@openrouter/sdk";
960
- import * as errors from "@openrouter/sdk/models/errors";
961
-
962
- const openRouter = new OpenRouter({
963
- apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
81
+ stream: true
964
82
  });
965
83
 
966
- async function run() {
967
- try {
968
- const result = await openRouter.beta.responses.send({
969
- input: [
970
- {
971
- type: "message",
972
- role: "user",
973
- content: "Hello, how are you?",
974
- },
975
- ],
976
- instructions: "<value>",
977
- metadata: {
978
- "user_id": "123",
979
- "session_id": "abc-def-ghi",
980
- },
981
- tools: [
982
- {
983
- type: "function",
984
- name: "get_current_weather",
985
- description: "Get the current weather in a given location",
986
- strict: true,
987
- parameters: {
988
- "type": "object",
989
- "properties": {
990
- "location": {
991
- "type": "string",
992
- },
993
- },
994
- },
995
- },
996
- ],
997
- toolChoice: {
998
- type: "function",
999
- name: "<value>",
1000
- },
1001
- parallelToolCalls: true,
1002
- model: "anthropic/claude-4.5-sonnet-20250929",
1003
- models: [
1004
- "<value 1>",
1005
- ],
1006
- text: {
1007
- format: {
1008
- type: "text",
1009
- },
1010
- verbosity: "medium",
1011
- },
1012
- reasoning: {
1013
- effort: "high",
1014
- summary: "auto",
1015
- maxTokens: 8661.16,
1016
- enabled: true,
1017
- },
1018
- maxOutputTokens: null,
1019
- temperature: 0.7,
1020
- topP: 0.9,
1021
- topK: 193.77,
1022
- promptCacheKey: "<value>",
1023
- previousResponseId: "<id>",
1024
- prompt: {
1025
- id: "<id>",
1026
- variables: {
1027
- "key": {
1028
- type: "input_text",
1029
- text: "Hello, how can I help you?",
1030
- },
1031
- },
1032
- },
1033
- include: [
1034
- "reasoning.encrypted_content",
1035
- ],
1036
- background: true,
1037
- safetyIdentifier: "<value>",
1038
- store: true,
1039
- serviceTier: "auto",
1040
- truncation: "auto",
1041
- provider: {
1042
- allowFallbacks: null,
1043
- requireParameters: true,
1044
- dataCollection: "deny",
1045
- zdr: true,
1046
- order: [
1047
- "OpenAI",
1048
- ],
1049
- only: [
1050
- "OpenAI",
1051
- ],
1052
- ignore: null,
1053
- quantizations: [
1054
- "fp16",
1055
- ],
1056
- sort: "price",
1057
- maxPrice: {
1058
- prompt: "1000",
1059
- completion: 1000,
1060
- image: 1000,
1061
- audio: "1000",
1062
- request: 1000,
1063
- },
1064
- experimental: {},
1065
- },
1066
- plugins: [
1067
- {
1068
- id: "file-parser",
1069
- maxFiles: 4870.55,
1070
- pdf: {
1071
- engine: "mistral-ocr",
1072
- },
1073
- },
1074
- ],
1075
- user: "Elmer_Yundt72",
1076
- });
1077
-
1078
- console.log(result);
1079
- } catch (error) {
1080
- // The base class for HTTP error responses
1081
- if (error instanceof errors.OpenRouterError) {
1082
- console.log(error.message);
1083
- console.log(error.statusCode);
1084
- console.log(error.body);
1085
- console.log(error.headers);
1086
-
1087
- // Depending on the method different errors may be thrown
1088
- if (error instanceof errors.BadRequestResponseError) {
1089
- console.log(error.data$.error); // models.BadRequestResponseErrorData
1090
- console.log(error.data$.userId); // string
1091
- }
1092
- }
1093
- }
84
+ for await (const chunk of stream) {
85
+ console.log(hunk.choices[0].delta.content)
1094
86
  }
1095
87
 
1096
- run();
1097
-
1098
88
  ```
1099
89
 
1100
- ### Error Classes
1101
- **Primary errors:**
1102
- * [`OpenRouterError`](./src/models/errors/openroutererror.ts): The base class for HTTP error responses.
1103
- * [`InternalServerResponseError`](./src/models/errors/internalserverresponseerror.ts): Internal Server Error - Unexpected server error. Status code `500`. *
1104
-
1105
- <details><summary>Less common errors (20)</summary>
90
+ <!-- No Authentication [security] -->
1106
91
 
1107
- <br />
92
+ <!-- No Available Resources and Operations [operations] -->
1108
93
 
1109
- **Network errors:**
1110
- * [`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
1111
- * [`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
1112
- * [`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
1113
- * [`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
1114
- * [`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
94
+ <!-- No Standalone functions [standalone-funcs] -->
1115
95
 
96
+ <!-- No React hooks with TanStack Query [react-query] -->
1116
97
 
1117
- **Inherit from [`OpenRouterError`](./src/models/errors/openroutererror.ts)**:
1118
- * [`UnauthorizedResponseError`](./src/models/errors/unauthorizedresponseerror.ts): Unauthorized - Authentication required or invalid credentials. Status code `401`. Applicable to 14 of 22 methods.*
1119
- * [`BadRequestResponseError`](./src/models/errors/badrequestresponseerror.ts): Bad Request - Invalid request parameters or malformed input. Status code `400`. Applicable to 8 of 22 methods.*
1120
- * [`TooManyRequestsResponseError`](./src/models/errors/toomanyrequestsresponseerror.ts): Too Many Requests - Rate limit exceeded. Status code `429`. Applicable to 8 of 22 methods.*
1121
- * [`NotFoundResponseError`](./src/models/errors/notfoundresponseerror.ts): Not Found - Resource does not exist. Status code `404`. Applicable to 7 of 22 methods.*
1122
- * [`ForbiddenResponseError`](./src/models/errors/forbiddenresponseerror.ts): Forbidden - Authentication successful but insufficient permissions. Status code `403`. Applicable to 3 of 22 methods.*
1123
- * [`ChatError`](./src/models/errors/chaterror.ts): Bad request - invalid parameters. Applicable to 2 of 22 methods.*
1124
- * [`PaymentRequiredResponseError`](./src/models/errors/paymentrequiredresponseerror.ts): Payment Required - Insufficient credits or quota to complete request. Status code `402`. Applicable to 2 of 22 methods.*
1125
- * [`BadGatewayResponseError`](./src/models/errors/badgatewayresponseerror.ts): Bad Gateway - Provider/upstream API failure. Status code `502`. Applicable to 2 of 22 methods.*
1126
- * [`EdgeNetworkTimeoutResponseError`](./src/models/errors/edgenetworktimeoutresponseerror.ts): Infrastructure Timeout - Provider request timed out at edge network. Status code `524`. Applicable to 2 of 22 methods.*
1127
- * [`ProviderOverloadedResponseError`](./src/models/errors/provideroverloadedresponseerror.ts): Provider Overloaded - Provider is temporarily overloaded. Status code `529`. Applicable to 2 of 22 methods.*
1128
- * [`RequestTimeoutResponseError`](./src/models/errors/requesttimeoutresponseerror.ts): Request Timeout - Operation exceeded time limit. Status code `408`. Applicable to 1 of 22 methods.*
1129
- * [`PayloadTooLargeResponseError`](./src/models/errors/payloadtoolargeresponseerror.ts): Payload Too Large - Request payload exceeds size limits. Status code `413`. Applicable to 1 of 22 methods.*
1130
- * [`UnprocessableEntityResponseError`](./src/models/errors/unprocessableentityresponseerror.ts): Unprocessable Entity - Semantic validation failure. Status code `422`. Applicable to 1 of 22 methods.*
1131
- * [`ServiceUnavailableResponseError`](./src/models/errors/serviceunavailableresponseerror.ts): Service Unavailable - Service temporarily unavailable. Status code `503`. Applicable to 1 of 22 methods.*
1132
- * [`ResponseValidationError`](./src/models/errors/responsevalidationerror.ts): Type mismatch between the data returned from the server and the structure expected by the SDK. See `error.rawValue` for the raw value and `error.pretty()` for a nicely formatted multi-line string.
98
+ <!-- No Server-sent event streaming [eventstream] -->
1133
99
 
1134
- </details>
100
+ <!-- No Retries [retries] -->
1135
101
 
1136
- \* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
1137
- <!-- End Error Handling [errors] -->
102
+ <!-- No Error Handling [errors] -->
1138
103
 
1139
104
  <!-- No Server Selection [server] -->
1140
105
 
@@ -1192,8 +157,3 @@ To run the test suite, you'll need to set up your environment with an OpenRouter
1192
157
  This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
1193
158
  to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
1194
159
  looking for the latest version.
1195
-
1196
- ## Contributions
1197
-
1198
- While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
1199
- We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
@@ -37,8 +37,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
37
37
  export declare const SDK_METADATA: {
38
38
  readonly language: "typescript";
39
39
  readonly openapiDocVersion: "1.0.0";
40
- readonly sdkVersion: "0.0.1-beta.16";
41
- readonly genVersion: "2.731.4";
42
- readonly userAgent: "speakeasy-sdk/typescript 0.0.1-beta.16 2.731.4 1.0.0 @openrouter/sdk";
40
+ readonly sdkVersion: "0.0.1-beta.18";
41
+ readonly genVersion: "2.731.6";
42
+ readonly userAgent: "speakeasy-sdk/typescript 0.0.1-beta.18 2.731.6 1.0.0 @openrouter/sdk";
43
43
  };
44
44
  //# sourceMappingURL=config.d.ts.map
package/esm/lib/config.js CHANGED
@@ -25,8 +25,8 @@ export function serverURLFromOptions(options) {
25
25
  export const SDK_METADATA = {
26
26
  language: "typescript",
27
27
  openapiDocVersion: "1.0.0",
28
- sdkVersion: "0.0.1-beta.16",
29
- genVersion: "2.731.4",
30
- userAgent: "speakeasy-sdk/typescript 0.0.1-beta.16 2.731.4 1.0.0 @openrouter/sdk",
28
+ sdkVersion: "0.0.1-beta.18",
29
+ genVersion: "2.731.6",
30
+ userAgent: "speakeasy-sdk/typescript 0.0.1-beta.18 2.731.6 1.0.0 @openrouter/sdk",
31
31
  };
32
32
  //# sourceMappingURL=config.js.map
@@ -5,6 +5,7 @@ export declare const InputModality: {
5
5
  readonly Image: "image";
6
6
  readonly File: "file";
7
7
  readonly Audio: "audio";
8
+ readonly Video: "video";
8
9
  };
9
10
  export type InputModality = OpenEnum<typeof InputModality>;
10
11
  /** @internal */
@@ -8,6 +8,7 @@ export const InputModality = {
8
8
  Image: "image",
9
9
  File: "file",
10
10
  Audio: "audio",
11
+ Video: "video",
11
12
  };
12
13
  /** @internal */
13
14
  export const InputModality$inboundSchema = z
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@openrouter/sdk",
5
- "version": "0.0.1-beta.16",
5
+ "version": "0.0.1-beta.18",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./models/errors": "./src/models/errors/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrouter/sdk",
3
- "version": "0.0.1-beta.16",
3
+ "version": "0.0.1-beta.18",
4
4
  "author": "OpenRouter",
5
5
  "type": "module",
6
6
  "main": "./esm/index.js",