@openrouter/ai-sdk-provider 0.0.3 → 0.0.5
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 +75 -7
- package/dist/index.d.mts +8 -18
- package/dist/index.d.ts +8 -18
- package/dist/index.js +12 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -17
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +3 -1
- package/internal/dist/index.d.ts +3 -1
- package/internal/dist/index.js +4 -4
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +4 -4
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -7,27 +7,27 @@ contains 160+ language model support for the OpenRouter chat and completion APIs
|
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
9
|
# For pnpm
|
|
10
|
-
pnpm add openrouter
|
|
10
|
+
pnpm add @openrouter/ai-sdk-provider
|
|
11
11
|
|
|
12
12
|
# For npm
|
|
13
|
-
npm install openrouter
|
|
13
|
+
npm install @openrouter/ai-sdk-provider
|
|
14
14
|
|
|
15
15
|
# For yarn
|
|
16
|
-
yarn add openrouter
|
|
16
|
+
yarn add @openrouter/ai-sdk-provider
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Provider Instance
|
|
20
20
|
|
|
21
|
-
You can import the default provider instance `openrouter` from
|
|
21
|
+
You can import the default provider instance `openrouter` from `@openrouter/ai-sdk-provider`:
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import { openrouter } from "openrouter
|
|
24
|
+
import { openrouter } from "@openrouter/ai-sdk-provider";
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Example
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import { openrouter } from "openrouter
|
|
30
|
+
import { openrouter } from "@openrouter/ai-sdk-provider";
|
|
31
31
|
import { generateText } from "ai";
|
|
32
32
|
|
|
33
33
|
const { text } = await generateText({
|
|
@@ -38,7 +38,7 @@ const { text } = await generateText({
|
|
|
38
38
|
|
|
39
39
|
## Supported models
|
|
40
40
|
|
|
41
|
-
This list is not a definitive list of models supported by OpenRouter, as it constantly changes as we add new models to our system.
|
|
41
|
+
This list is not a definitive list of models supported by OpenRouter, as it constantly changes as we add new models (and deprecate old ones) to our system.
|
|
42
42
|
You can find the latest list of models supported by OpenRouter [here](https://openrouter.ai/models).
|
|
43
43
|
|
|
44
44
|
| Model | ID | Input Price ($/1M tokens) | Output Price ($/1M tokens) | Context Window | Moderation |
|
|
@@ -191,3 +191,71 @@ You can find the latest list of models supported by OpenRouter [here](https://op
|
|
|
191
191
|
| Mistral: Mistral 7B Instruct (free) | mistralai/mistral-7b-instruct:free | $0 (100% off) | $0 (100% off) | 32,768 | None |
|
|
192
192
|
| Pygmalion: Mythalion 13B | pygmalionai/mythalion-13b | $1.125 (25% off) | $1.125 (25% off) | 8,192 | None |
|
|
193
193
|
| OpenAI: GPT-3.5 Turbo 16k | openai/gpt-3.5-turbo-16k | $3 | $4 | 16,385 | Moderated |
|
|
194
|
+
|
|
195
|
+
## Models with Tool Calling Capabilities Compatible with AI SDK
|
|
196
|
+
|
|
197
|
+
_Last Update: 2024-08-19_
|
|
198
|
+
|
|
199
|
+
This list is not a definitive list of tool-calling models supported by OpenRouter, as it constantly changes as we add new models (and deprecate old ones) to our system.
|
|
200
|
+
You can find the latest list of tool-supported models supported by OpenRouter [here](https://openrouter.ai/models?order=newest&supported_parameters=tools). (Note: This list may contain models that are not compatible with the AI SDK.)
|
|
201
|
+
|
|
202
|
+
- openai/gpt-3.5-turbo
|
|
203
|
+
- openai/gpt-3.5-turbo-0125
|
|
204
|
+
- openai/gpt-3.5-turbo-1106
|
|
205
|
+
- openai/gpt-3.5-turbo-0613
|
|
206
|
+
- openai/gpt-3.5-turbo-16k
|
|
207
|
+
- openai/gpt-4o
|
|
208
|
+
- openai/gpt-4o-2024-05-13
|
|
209
|
+
- openai/gpt-4o-2024-08-06
|
|
210
|
+
- openai/gpt-4o-mini
|
|
211
|
+
- openai/gpt-4o-mini-2024-07-18
|
|
212
|
+
- openai/gpt-4-turbo
|
|
213
|
+
- openai/gpt-4-turbo-preview
|
|
214
|
+
- openai/gpt-4-1106-preview
|
|
215
|
+
- openai/gpt-4
|
|
216
|
+
- openai/gpt-4-32k
|
|
217
|
+
- openai/gpt-4-vision-preview
|
|
218
|
+
- google/gemini-pro
|
|
219
|
+
- google/gemini-pro-vision
|
|
220
|
+
- google/gemini-pro-1.5
|
|
221
|
+
- google/gemini-flash-1.5
|
|
222
|
+
- mistralai/mistral-small
|
|
223
|
+
- mistralai/mistral-large
|
|
224
|
+
- 01-ai/yi-large-fc
|
|
225
|
+
- anthropic/claude-3-opus
|
|
226
|
+
- anthropic/claude-3-opus:beta
|
|
227
|
+
- anthropic/claude-3-sonnet
|
|
228
|
+
- anthropic/claude-3-sonnet:beta
|
|
229
|
+
- anthropic/claude-3.5-sonnet
|
|
230
|
+
- anthropic/claude-3.5-sonnet:beta
|
|
231
|
+
- anthropic/claude-3-haiku
|
|
232
|
+
- anthropic/claude-3-haiku:beta
|
|
233
|
+
- meta-llama/llama-3-8b-instruct
|
|
234
|
+
- mistralai/mixtral-8x22b-instruct
|
|
235
|
+
|
|
236
|
+
## Passing Extra Body to OpenRouter
|
|
237
|
+
|
|
238
|
+
When you want to pass extra body to OpenRouter or to the upstream provider, you can do so by setting the `extraBody` property on the language model.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { createOpenRouter } from "@ai-sdk/openrouter";
|
|
242
|
+
|
|
243
|
+
const provider = createOpenRouter({
|
|
244
|
+
apiKey: "your-api-key",
|
|
245
|
+
// Extra body to pass to OpenRouter
|
|
246
|
+
extraBody: {
|
|
247
|
+
custom_field: "custom_value",
|
|
248
|
+
providers: {
|
|
249
|
+
anthropic: {
|
|
250
|
+
custom_field: "custom_value",
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
const model = provider.chat("anthropic/claude-3.5-sonnet");
|
|
256
|
+
const response = await model.doStream({
|
|
257
|
+
inputFormat: "prompt",
|
|
258
|
+
mode: { type: "regular" },
|
|
259
|
+
prompt: [{ role: "user", content: "Hello" }],
|
|
260
|
+
});
|
|
261
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -49,6 +49,7 @@ type OpenRouterChatConfig = {
|
|
|
49
49
|
path: string;
|
|
50
50
|
}) => string;
|
|
51
51
|
fetch?: typeof fetch;
|
|
52
|
+
extraBody?: Record<string, unknown>;
|
|
52
53
|
};
|
|
53
54
|
declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
54
55
|
readonly specificationVersion = "v1";
|
|
@@ -63,7 +64,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
|
63
64
|
doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
type OpenRouterCompletionModelId =
|
|
67
|
+
type OpenRouterCompletionModelId = string & {};
|
|
67
68
|
interface OpenRouterCompletionSettings {
|
|
68
69
|
/**
|
|
69
70
|
Echo back the prompt in addition to the completion.
|
|
@@ -116,6 +117,7 @@ type OpenRouterCompletionConfig = {
|
|
|
116
117
|
path: string;
|
|
117
118
|
}) => string;
|
|
118
119
|
fetch?: typeof fetch;
|
|
120
|
+
extraBody?: Record<string, unknown>;
|
|
119
121
|
};
|
|
120
122
|
declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
|
|
121
123
|
readonly specificationVersion = "v1";
|
|
@@ -158,14 +160,6 @@ interface OpenRouterProviderSettings {
|
|
|
158
160
|
*/
|
|
159
161
|
apiKey?: string;
|
|
160
162
|
/**
|
|
161
|
-
OpenRouter Organization.
|
|
162
|
-
*/
|
|
163
|
-
organization?: string;
|
|
164
|
-
/**
|
|
165
|
-
OpenRouter project.
|
|
166
|
-
*/
|
|
167
|
-
project?: string;
|
|
168
|
-
/**
|
|
169
163
|
Custom headers to include in the requests.
|
|
170
164
|
*/
|
|
171
165
|
headers?: Record<string, string>;
|
|
@@ -180,6 +174,10 @@ interface OpenRouterProviderSettings {
|
|
|
180
174
|
or to provide a custom fetch implementation for e.g. testing.
|
|
181
175
|
*/
|
|
182
176
|
fetch?: typeof fetch;
|
|
177
|
+
/**
|
|
178
|
+
A JSON object to send as the request body to access OpenRouter features & upstream provider features.
|
|
179
|
+
*/
|
|
180
|
+
extraBody?: Record<string, unknown>;
|
|
183
181
|
}
|
|
184
182
|
/**
|
|
185
183
|
Create an OpenRouter provider instance.
|
|
@@ -201,18 +199,10 @@ declare class OpenRouter {
|
|
|
201
199
|
readonly baseURL: string;
|
|
202
200
|
/**
|
|
203
201
|
API key that is being send using the `Authorization` header.
|
|
204
|
-
It defaults to the `
|
|
202
|
+
It defaults to the `OPENROUTER_API_KEY` environment variable.
|
|
205
203
|
*/
|
|
206
204
|
readonly apiKey?: string;
|
|
207
205
|
/**
|
|
208
|
-
OpenRouter Organization.
|
|
209
|
-
*/
|
|
210
|
-
readonly organization?: string;
|
|
211
|
-
/**
|
|
212
|
-
OpenRouter project.
|
|
213
|
-
*/
|
|
214
|
-
readonly project?: string;
|
|
215
|
-
/**
|
|
216
206
|
Custom headers to include in the requests.
|
|
217
207
|
*/
|
|
218
208
|
readonly headers?: Record<string, string>;
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ type OpenRouterChatConfig = {
|
|
|
49
49
|
path: string;
|
|
50
50
|
}) => string;
|
|
51
51
|
fetch?: typeof fetch;
|
|
52
|
+
extraBody?: Record<string, unknown>;
|
|
52
53
|
};
|
|
53
54
|
declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
54
55
|
readonly specificationVersion = "v1";
|
|
@@ -63,7 +64,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
|
63
64
|
doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
type OpenRouterCompletionModelId =
|
|
67
|
+
type OpenRouterCompletionModelId = string & {};
|
|
67
68
|
interface OpenRouterCompletionSettings {
|
|
68
69
|
/**
|
|
69
70
|
Echo back the prompt in addition to the completion.
|
|
@@ -116,6 +117,7 @@ type OpenRouterCompletionConfig = {
|
|
|
116
117
|
path: string;
|
|
117
118
|
}) => string;
|
|
118
119
|
fetch?: typeof fetch;
|
|
120
|
+
extraBody?: Record<string, unknown>;
|
|
119
121
|
};
|
|
120
122
|
declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
|
|
121
123
|
readonly specificationVersion = "v1";
|
|
@@ -158,14 +160,6 @@ interface OpenRouterProviderSettings {
|
|
|
158
160
|
*/
|
|
159
161
|
apiKey?: string;
|
|
160
162
|
/**
|
|
161
|
-
OpenRouter Organization.
|
|
162
|
-
*/
|
|
163
|
-
organization?: string;
|
|
164
|
-
/**
|
|
165
|
-
OpenRouter project.
|
|
166
|
-
*/
|
|
167
|
-
project?: string;
|
|
168
|
-
/**
|
|
169
163
|
Custom headers to include in the requests.
|
|
170
164
|
*/
|
|
171
165
|
headers?: Record<string, string>;
|
|
@@ -180,6 +174,10 @@ interface OpenRouterProviderSettings {
|
|
|
180
174
|
or to provide a custom fetch implementation for e.g. testing.
|
|
181
175
|
*/
|
|
182
176
|
fetch?: typeof fetch;
|
|
177
|
+
/**
|
|
178
|
+
A JSON object to send as the request body to access OpenRouter features & upstream provider features.
|
|
179
|
+
*/
|
|
180
|
+
extraBody?: Record<string, unknown>;
|
|
183
181
|
}
|
|
184
182
|
/**
|
|
185
183
|
Create an OpenRouter provider instance.
|
|
@@ -201,18 +199,10 @@ declare class OpenRouter {
|
|
|
201
199
|
readonly baseURL: string;
|
|
202
200
|
/**
|
|
203
201
|
API key that is being send using the `Authorization` header.
|
|
204
|
-
It defaults to the `
|
|
202
|
+
It defaults to the `OPENROUTER_API_KEY` environment variable.
|
|
205
203
|
*/
|
|
206
204
|
readonly apiKey?: string;
|
|
207
205
|
/**
|
|
208
|
-
OpenRouter Organization.
|
|
209
|
-
*/
|
|
210
|
-
readonly organization?: string;
|
|
211
|
-
/**
|
|
212
|
-
OpenRouter project.
|
|
213
|
-
*/
|
|
214
|
-
readonly project?: string;
|
|
215
|
-
/**
|
|
216
206
|
Custom headers to include in the requests.
|
|
217
207
|
*/
|
|
218
208
|
readonly headers?: Record<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -221,7 +221,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
221
221
|
seed
|
|
222
222
|
}) {
|
|
223
223
|
const type = mode.type;
|
|
224
|
-
const baseArgs = {
|
|
224
|
+
const baseArgs = __spreadValues({
|
|
225
225
|
// model id:
|
|
226
226
|
model: this.modelId,
|
|
227
227
|
// model specific settings:
|
|
@@ -239,7 +239,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
239
239
|
seed,
|
|
240
240
|
// messages:
|
|
241
241
|
messages: convertToOpenRouterChatMessages(prompt)
|
|
242
|
-
};
|
|
242
|
+
}, this.config.extraBody);
|
|
243
243
|
switch (type) {
|
|
244
244
|
case "regular": {
|
|
245
245
|
return __spreadValues(__spreadValues({}, baseArgs), prepareToolsAndToolChoice(mode));
|
|
@@ -741,7 +741,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
741
741
|
var _a;
|
|
742
742
|
const type = mode.type;
|
|
743
743
|
const { prompt: completionPrompt, stopSequences } = convertToOpenRouterCompletionPrompt({ prompt, inputFormat });
|
|
744
|
-
const baseArgs = {
|
|
744
|
+
const baseArgs = __spreadValues({
|
|
745
745
|
// model id:
|
|
746
746
|
model: this.modelId,
|
|
747
747
|
// model specific settings:
|
|
@@ -761,7 +761,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
761
761
|
prompt: completionPrompt,
|
|
762
762
|
// stop sequences:
|
|
763
763
|
stop: stopSequences
|
|
764
|
-
};
|
|
764
|
+
}, this.config.extraBody);
|
|
765
765
|
switch (type) {
|
|
766
766
|
case "regular": {
|
|
767
767
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
@@ -961,22 +961,17 @@ var OpenRouter = class {
|
|
|
961
961
|
var _a, _b;
|
|
962
962
|
this.baseURL = (_b = (0, import_provider_utils5.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://openrouter.ai/api/v1";
|
|
963
963
|
this.apiKey = options.apiKey;
|
|
964
|
-
this.organization = options.organization;
|
|
965
|
-
this.project = options.project;
|
|
966
964
|
this.headers = options.headers;
|
|
967
965
|
}
|
|
968
966
|
get baseConfig() {
|
|
969
967
|
return {
|
|
970
|
-
organization: this.organization,
|
|
971
968
|
baseURL: this.baseURL,
|
|
972
969
|
headers: () => __spreadValues({
|
|
973
970
|
Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({
|
|
974
971
|
apiKey: this.apiKey,
|
|
975
|
-
environmentVariableName: "
|
|
972
|
+
environmentVariableName: "OPENROUTER_API_KEY",
|
|
976
973
|
description: "OpenRouter"
|
|
977
|
-
})}
|
|
978
|
-
"OpenRouter-Organization": this.organization,
|
|
979
|
-
"OpenRouter-Project": this.project
|
|
974
|
+
})}`
|
|
980
975
|
}, this.headers)
|
|
981
976
|
};
|
|
982
977
|
}
|
|
@@ -1007,25 +1002,25 @@ function createOpenRouter(options = {}) {
|
|
|
1007
1002
|
const getHeaders = () => __spreadValues({
|
|
1008
1003
|
Authorization: `Bearer ${(0, import_provider_utils6.loadApiKey)({
|
|
1009
1004
|
apiKey: options.apiKey,
|
|
1010
|
-
environmentVariableName: "
|
|
1005
|
+
environmentVariableName: "OPENROUTER_API_KEY",
|
|
1011
1006
|
description: "OpenRouter"
|
|
1012
|
-
})}
|
|
1013
|
-
"OpenRouter-Organization": options.organization,
|
|
1014
|
-
"OpenRouter-Project": options.project
|
|
1007
|
+
})}`
|
|
1015
1008
|
}, options.headers);
|
|
1016
1009
|
const createChatModel = (modelId, settings = {}) => new OpenRouterChatLanguageModel(modelId, settings, {
|
|
1017
1010
|
provider: "openrouter.chat",
|
|
1018
1011
|
url: ({ path }) => `${baseURL}${path}`,
|
|
1019
1012
|
headers: getHeaders,
|
|
1020
1013
|
compatibility,
|
|
1021
|
-
fetch: options.fetch
|
|
1014
|
+
fetch: options.fetch,
|
|
1015
|
+
extraBody: options.extraBody
|
|
1022
1016
|
});
|
|
1023
1017
|
const createCompletionModel = (modelId, settings = {}) => new OpenRouterCompletionLanguageModel(modelId, settings, {
|
|
1024
1018
|
provider: "openrouter.completion",
|
|
1025
1019
|
url: ({ path }) => `${baseURL}${path}`,
|
|
1026
1020
|
headers: getHeaders,
|
|
1027
1021
|
compatibility,
|
|
1028
|
-
fetch: options.fetch
|
|
1022
|
+
fetch: options.fetch,
|
|
1023
|
+
extraBody: options.extraBody
|
|
1029
1024
|
});
|
|
1030
1025
|
const createLanguageModel = (modelId, settings) => {
|
|
1031
1026
|
if (new.target) {
|