@langchain/openrouter 0.1.0
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/LICENSE +21 -0
- package/README.md +174 -0
- package/dist/api-types.d.cts +368 -0
- package/dist/api-types.d.cts.map +1 -0
- package/dist/api-types.d.ts +368 -0
- package/dist/api-types.d.ts.map +1 -0
- package/dist/chat_models/index.cjs +401 -0
- package/dist/chat_models/index.cjs.map +1 -0
- package/dist/chat_models/index.d.cts +160 -0
- package/dist/chat_models/index.d.cts.map +1 -0
- package/dist/chat_models/index.d.ts +160 -0
- package/dist/chat_models/index.d.ts.map +1 -0
- package/dist/chat_models/index.js +401 -0
- package/dist/chat_models/index.js.map +1 -0
- package/dist/chat_models/types.d.cts +97 -0
- package/dist/chat_models/types.d.cts.map +1 -0
- package/dist/chat_models/types.d.ts +97 -0
- package/dist/chat_models/types.d.ts.map +1 -0
- package/dist/converters/messages.cjs +90 -0
- package/dist/converters/messages.cjs.map +1 -0
- package/dist/converters/messages.js +87 -0
- package/dist/converters/messages.js.map +1 -0
- package/dist/converters/tools.cjs +30 -0
- package/dist/converters/tools.cjs.map +1 -0
- package/dist/converters/tools.js +29 -0
- package/dist/converters/tools.js.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/profiles.cjs +2570 -0
- package/dist/profiles.cjs.map +1 -0
- package/dist/profiles.d.cts +7 -0
- package/dist/profiles.d.cts.map +1 -0
- package/dist/profiles.d.ts +7 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +2569 -0
- package/dist/profiles.js.map +1 -0
- package/dist/utils/errors.cjs +82 -0
- package/dist/utils/errors.cjs.map +1 -0
- package/dist/utils/errors.d.cts +68 -0
- package/dist/utils/errors.d.cts.map +1 -0
- package/dist/utils/errors.d.ts +68 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +80 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/stream.cjs +28 -0
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.js +27 -0
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/structured_output.cjs +44 -0
- package/dist/utils/structured_output.cjs.map +1 -0
- package/dist/utils/structured_output.js +43 -0
- package/dist/utils/structured_output.js.map +1 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LangChain, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @langchain/openrouter
|
|
2
|
+
|
|
3
|
+
This package contains the LangChain.js integrations for [OpenRouter](https://openrouter.ai/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash npm2yarn
|
|
8
|
+
npm install @langchain/openrouter @langchain/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
|
|
12
|
+
If you are using this package with other LangChain packages, you should make sure that all of the packages depend on the same instance of @langchain/core.
|
|
13
|
+
You can do so by adding appropriate fields to your project's `package.json` like this:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"name": "your-project",
|
|
18
|
+
"version": "0.0.0",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@langchain/openrouter": "^0.0.1",
|
|
21
|
+
"@langchain/core": "^1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"resolutions": {
|
|
24
|
+
"@langchain/core": "^1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"overrides": {
|
|
27
|
+
"@langchain/core": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"pnpm": {
|
|
30
|
+
"overrides": {
|
|
31
|
+
"@langchain/core": "^1.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The field you need depends on the package manager you're using, but we recommend adding a field for the common `pnpm`, `npm`, and `yarn` to maximize compatibility.
|
|
38
|
+
|
|
39
|
+
## Chat Models
|
|
40
|
+
|
|
41
|
+
This package contains the `ChatOpenRouter` class, which is the recommended way to interface with any model available on OpenRouter. Pass any OpenRouter model identifier (e.g. `"anthropic/claude-4-sonnet"`, `"openai/gpt-4o"`) as the `model` param.
|
|
42
|
+
|
|
43
|
+
Set the necessary environment variable (or pass it in via the constructor):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
export OPENROUTER_API_KEY=your-api-key
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then initialize
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { ChatOpenRouter } from "@langchain/openrouter";
|
|
53
|
+
|
|
54
|
+
const model = new ChatOpenRouter({
|
|
55
|
+
model: "openai/gpt-4o",
|
|
56
|
+
});
|
|
57
|
+
const response = await model.invoke([{ role: "user", content: "Hello world!" }]);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Streaming
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { ChatOpenRouter } from "@langchain/openrouter";
|
|
64
|
+
|
|
65
|
+
const model = new ChatOpenRouter({
|
|
66
|
+
model: "openai/gpt-4o",
|
|
67
|
+
});
|
|
68
|
+
const stream = await model.stream([{ role: "user", content: "Hello world!" }]);
|
|
69
|
+
for await (const chunk of stream) {
|
|
70
|
+
console.log(chunk.content);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Tool Calling
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { ChatOpenRouter } from "@langchain/openrouter";
|
|
78
|
+
import { tool } from "@langchain/core/tools";
|
|
79
|
+
import { z } from "zod";
|
|
80
|
+
|
|
81
|
+
const adder = tool(async ({ a, b }) => `${a + b}`, {
|
|
82
|
+
name: "add",
|
|
83
|
+
description: "Add two numbers",
|
|
84
|
+
schema: z.object({ a: z.number(), b: z.number() }),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const model = new ChatOpenRouter({
|
|
88
|
+
model: "openai/gpt-4o",
|
|
89
|
+
}).bindTools([adder]);
|
|
90
|
+
|
|
91
|
+
const response = await model.invoke("What is 2 + 3?");
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Structured Output
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { ChatOpenRouter } from "@langchain/openrouter";
|
|
98
|
+
import { z } from "zod";
|
|
99
|
+
|
|
100
|
+
const model = new ChatOpenRouter({
|
|
101
|
+
model: "openai/gpt-4o",
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const structured = model.withStructuredOutput(
|
|
105
|
+
z.object({
|
|
106
|
+
answer: z.string(),
|
|
107
|
+
confidence: z.number(),
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const response = await structured.invoke("What is the capital of France?");
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### OpenRouter-Specific Features
|
|
115
|
+
|
|
116
|
+
OpenRouter supports model routing, provider preferences, and plugins:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { ChatOpenRouter } from "@langchain/openrouter";
|
|
120
|
+
|
|
121
|
+
const model = new ChatOpenRouter({
|
|
122
|
+
model: "openai/gpt-4o",
|
|
123
|
+
models: ["openai/gpt-4o", "anthropic/claude-4-sonnet"],
|
|
124
|
+
route: "fallback",
|
|
125
|
+
provider: {
|
|
126
|
+
allow_fallbacks: true,
|
|
127
|
+
},
|
|
128
|
+
transforms: ["middle-out"],
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
To develop the `@langchain/openrouter` package, you'll need to follow these instructions:
|
|
135
|
+
|
|
136
|
+
### Install dependencies
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pnpm install
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Build the package
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
pnpm build
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Or from the repo root:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pnpm build --filter @langchain/openrouter
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Run tests
|
|
155
|
+
|
|
156
|
+
Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
|
|
157
|
+
end in `.int.test.ts`:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pnpm test
|
|
161
|
+
pnpm test:int
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Lint & Format
|
|
165
|
+
|
|
166
|
+
Run the linter & formatter to ensure your code is up to standard:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
pnpm lint && pnpm format
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Adding new entrypoints
|
|
173
|
+
|
|
174
|
+
If you add a new file to be exported, either import & re-export from `src/index.ts`, or add it to the `exports` field in the `package.json` file and run `pnpm build` to generate the new entrypoint.
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
//#region src/api-types.d.ts
|
|
2
|
+
declare namespace OpenRouter {
|
|
3
|
+
/** An OpenRouter model identifier, e.g. `"anthropic/claude-4-sonnet"`. */
|
|
4
|
+
export type ModelName = string;
|
|
5
|
+
/**
|
|
6
|
+
* A string that represents a large number (price per million tokens).
|
|
7
|
+
* Encoded as a string to avoid floating-point precision issues.
|
|
8
|
+
*/
|
|
9
|
+
export type BigNumberUnion = string;
|
|
10
|
+
export type ReasoningSummaryVerbosity = "auto" | "concise" | "detailed" | (string & {});
|
|
11
|
+
export type DataCollection = "deny" | "allow" | (string & {});
|
|
12
|
+
export type Quantization = "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32" | "unknown" | (string & {});
|
|
13
|
+
export type ProviderSort = "price" | "throughput" | "latency" | (string & {});
|
|
14
|
+
export type ProviderName = "AI21" | "AionLabs" | "Alibaba" | "Ambient" | "Amazon Bedrock" | "Amazon Nova" | "Anthropic" | "Arcee AI" | "AtlasCloud" | "Avian" | "Azure" | "BaseTen" | "BytePlus" | "Black Forest Labs" | "Cerebras" | "Chutes" | "Cirrascale" | "Clarifai" | "Cloudflare" | "Cohere" | "Crusoe" | "DeepInfra" | "DeepSeek" | "Featherless" | "Fireworks" | "Friendli" | "GMICloud" | "Google" | "Google AI Studio" | "Groq" | "Hyperbolic" | "Inception" | "Inceptron" | "InferenceNet" | "Infermatic" | "Io Net" | "Inflection" | "Liquid" | "Mara" | "Mancer 2" | "Minimax" | "ModelRun" | "Mistral" | "Modular" | "Moonshot AI" | "Morph" | "NCompass" | "Nebius" | "NextBit" | "Novita" | "Nvidia" | "OpenAI" | "OpenInference" | "Parasail" | "Perplexity" | "Phala" | "Relace" | "SambaNova" | "Seed" | "SiliconFlow" | "Sourceful" | "StepFun" | "Stealth" | "StreamLake" | "Switchpoint" | "Together" | "Upstage" | "Venice" | "WandB" | "Xiaomi" | "xAI" | "Z.AI" | "FakeProvider" | (string & {});
|
|
15
|
+
export type ChatCompletionFinishReason = "tool_calls" | "stop" | "length" | "content_filter" | "error" | (string & {});
|
|
16
|
+
export type ReasoningDetailFormat = "unknown" | "openai-responses-v1" | "azure-openai-responses-v1" | "xai-responses-v1" | "anthropic-claude-v1" | "google-gemini-v1" | (string & {});
|
|
17
|
+
export interface ChatMessageContentItemCacheControl {
|
|
18
|
+
type: "ephemeral";
|
|
19
|
+
ttl?: "5m" | "1h" | (string & {});
|
|
20
|
+
}
|
|
21
|
+
export interface ChatMessageContentItemText {
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
cache_control?: ChatMessageContentItemCacheControl;
|
|
25
|
+
}
|
|
26
|
+
export interface ChatMessageContentItemImage {
|
|
27
|
+
type: "image_url";
|
|
28
|
+
image_url: {
|
|
29
|
+
url: string;
|
|
30
|
+
detail?: "auto" | "low" | "high" | (string & {});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface ChatMessageContentItemAudio {
|
|
34
|
+
type: "input_audio";
|
|
35
|
+
input_audio: {
|
|
36
|
+
data: string;
|
|
37
|
+
format: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export type ChatMessageContentItemVideo = {
|
|
41
|
+
type: "input_video";
|
|
42
|
+
video_url: {
|
|
43
|
+
url: string;
|
|
44
|
+
};
|
|
45
|
+
} | {
|
|
46
|
+
type: "video_url";
|
|
47
|
+
video_url: {
|
|
48
|
+
url: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** Discriminated union of all content part types (discriminant: `type`). */
|
|
52
|
+
export type ChatMessageContentItem = ChatMessageContentItemText | ChatMessageContentItemImage | ChatMessageContentItemAudio | ChatMessageContentItemVideo;
|
|
53
|
+
interface ReasoningDetailBase {
|
|
54
|
+
id?: string | null;
|
|
55
|
+
format?: ReasoningDetailFormat | null;
|
|
56
|
+
index?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface ReasoningSummaryDetail extends ReasoningDetailBase {
|
|
59
|
+
type: "reasoning.summary";
|
|
60
|
+
summary: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ReasoningEncryptedDetail extends ReasoningDetailBase {
|
|
63
|
+
type: "reasoning.encrypted";
|
|
64
|
+
data: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ReasoningTextDetail extends ReasoningDetailBase {
|
|
67
|
+
type: "reasoning.text";
|
|
68
|
+
text?: string | null;
|
|
69
|
+
signature?: string | null;
|
|
70
|
+
}
|
|
71
|
+
export type ReasoningDetail = ReasoningSummaryDetail | ReasoningEncryptedDetail | ReasoningTextDetail;
|
|
72
|
+
export interface SystemMessage {
|
|
73
|
+
role: "system";
|
|
74
|
+
content: string | ChatMessageContentItemText[];
|
|
75
|
+
name?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface UserMessage {
|
|
78
|
+
role: "user";
|
|
79
|
+
content: string | ChatMessageContentItem[];
|
|
80
|
+
name?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface DeveloperMessage {
|
|
83
|
+
role: "developer";
|
|
84
|
+
content: string | ChatMessageContentItemText[];
|
|
85
|
+
name?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface AssistantMessage {
|
|
88
|
+
role: "assistant";
|
|
89
|
+
content?: string | ChatMessageContentItem[] | null;
|
|
90
|
+
name?: string;
|
|
91
|
+
tool_calls?: ChatMessageToolCall[];
|
|
92
|
+
refusal?: string | null;
|
|
93
|
+
reasoning?: string | null;
|
|
94
|
+
reasoning_details?: ReasoningDetail[];
|
|
95
|
+
images?: Array<{
|
|
96
|
+
image_url: {
|
|
97
|
+
url: string;
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
export interface ToolResponseMessage {
|
|
102
|
+
role: "tool";
|
|
103
|
+
content: string | ChatMessageContentItem[];
|
|
104
|
+
tool_call_id: string;
|
|
105
|
+
}
|
|
106
|
+
/** Discriminated union of all message types (discriminant: `role`). */
|
|
107
|
+
export type Message = SystemMessage | UserMessage | DeveloperMessage | AssistantMessage | ToolResponseMessage;
|
|
108
|
+
export interface ChatMessageToolCall {
|
|
109
|
+
id: string;
|
|
110
|
+
type: "function";
|
|
111
|
+
function: {
|
|
112
|
+
name: string;
|
|
113
|
+
arguments: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export interface ChatStreamingMessageToolCall {
|
|
117
|
+
index: number;
|
|
118
|
+
id?: string;
|
|
119
|
+
type?: "function";
|
|
120
|
+
function?: {
|
|
121
|
+
name?: string;
|
|
122
|
+
arguments?: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export interface ToolDefinitionJson {
|
|
126
|
+
type: "function";
|
|
127
|
+
function: {
|
|
128
|
+
name: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
parameters?: Record<string, unknown>;
|
|
131
|
+
strict?: boolean | null;
|
|
132
|
+
};
|
|
133
|
+
cache_control?: ChatMessageContentItemCacheControl;
|
|
134
|
+
}
|
|
135
|
+
export interface NamedToolChoice {
|
|
136
|
+
type: "function";
|
|
137
|
+
function: {
|
|
138
|
+
name: string;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export type ToolChoiceOption = "none" | "auto" | "required" | NamedToolChoice;
|
|
142
|
+
export interface JSONSchemaConfig {
|
|
143
|
+
name: string;
|
|
144
|
+
description?: string;
|
|
145
|
+
schema?: Record<string, unknown>;
|
|
146
|
+
strict?: boolean | null;
|
|
147
|
+
}
|
|
148
|
+
export interface ResponseFormatJSONSchema {
|
|
149
|
+
type: "json_schema";
|
|
150
|
+
json_schema: JSONSchemaConfig;
|
|
151
|
+
}
|
|
152
|
+
export interface ResponseFormatTextGrammar {
|
|
153
|
+
type: "grammar";
|
|
154
|
+
grammar: string;
|
|
155
|
+
}
|
|
156
|
+
export interface ChatMessageTokenLogprob {
|
|
157
|
+
token: string;
|
|
158
|
+
logprob: number;
|
|
159
|
+
bytes: number[] | null;
|
|
160
|
+
top_logprobs: Array<{
|
|
161
|
+
token: string;
|
|
162
|
+
logprob: number;
|
|
163
|
+
bytes: number[] | null;
|
|
164
|
+
}>;
|
|
165
|
+
}
|
|
166
|
+
export interface ChatMessageTokenLogprobs {
|
|
167
|
+
content: ChatMessageTokenLogprob[] | null;
|
|
168
|
+
refusal: ChatMessageTokenLogprob[] | null;
|
|
169
|
+
}
|
|
170
|
+
export interface ChatGenerationTokenUsage {
|
|
171
|
+
completion_tokens: number;
|
|
172
|
+
prompt_tokens: number;
|
|
173
|
+
total_tokens: number;
|
|
174
|
+
completion_tokens_details?: {
|
|
175
|
+
reasoning_tokens?: number | null;
|
|
176
|
+
audio_tokens?: number | null;
|
|
177
|
+
accepted_prediction_tokens?: number | null;
|
|
178
|
+
rejected_prediction_tokens?: number | null;
|
|
179
|
+
} | null;
|
|
180
|
+
prompt_tokens_details?: {
|
|
181
|
+
cached_tokens?: number;
|
|
182
|
+
cache_write_tokens?: number;
|
|
183
|
+
audio_tokens?: number;
|
|
184
|
+
video_tokens?: number;
|
|
185
|
+
} | null;
|
|
186
|
+
}
|
|
187
|
+
export interface PercentileLatencyCutoffs {
|
|
188
|
+
p50?: number | null;
|
|
189
|
+
p75?: number | null;
|
|
190
|
+
p90?: number | null;
|
|
191
|
+
p99?: number | null;
|
|
192
|
+
}
|
|
193
|
+
export interface PercentileThroughputCutoffs {
|
|
194
|
+
p50?: number | null;
|
|
195
|
+
p75?: number | null;
|
|
196
|
+
p90?: number | null;
|
|
197
|
+
p99?: number | null;
|
|
198
|
+
}
|
|
199
|
+
export type PreferredMaxLatency = number | PercentileLatencyCutoffs;
|
|
200
|
+
export type PreferredMinThroughput = number | PercentileThroughputCutoffs;
|
|
201
|
+
export interface ProviderSortConfig {
|
|
202
|
+
by?: ProviderSort | null;
|
|
203
|
+
partition?: "model" | "none" | (string & {}) | null;
|
|
204
|
+
}
|
|
205
|
+
export type ProviderSortUnion = ProviderSort | ProviderSortConfig;
|
|
206
|
+
export interface ProviderPreferences {
|
|
207
|
+
allow_fallbacks?: boolean | null;
|
|
208
|
+
require_parameters?: boolean | null;
|
|
209
|
+
data_collection?: DataCollection;
|
|
210
|
+
zdr?: boolean | null;
|
|
211
|
+
enforce_distillable_text?: boolean | null;
|
|
212
|
+
order?: Array<ProviderName | string> | null;
|
|
213
|
+
only?: Array<ProviderName | string> | null;
|
|
214
|
+
ignore?: Array<ProviderName | string> | null;
|
|
215
|
+
quantizations?: Quantization[] | null;
|
|
216
|
+
sort?: ProviderSortUnion | null;
|
|
217
|
+
max_price?: {
|
|
218
|
+
prompt?: BigNumberUnion;
|
|
219
|
+
completion?: BigNumberUnion;
|
|
220
|
+
image?: BigNumberUnion;
|
|
221
|
+
audio?: BigNumberUnion;
|
|
222
|
+
request?: BigNumberUnion;
|
|
223
|
+
};
|
|
224
|
+
preferred_min_throughput?: PreferredMinThroughput;
|
|
225
|
+
preferred_max_latency?: PreferredMaxLatency;
|
|
226
|
+
}
|
|
227
|
+
export interface AutoRouterPlugin {
|
|
228
|
+
id: "auto-router";
|
|
229
|
+
enabled?: boolean;
|
|
230
|
+
allowed_models?: string[];
|
|
231
|
+
}
|
|
232
|
+
export interface ModerationPlugin {
|
|
233
|
+
id: "moderation";
|
|
234
|
+
}
|
|
235
|
+
export interface WebPlugin {
|
|
236
|
+
id: "web";
|
|
237
|
+
enabled?: boolean;
|
|
238
|
+
max_results?: number;
|
|
239
|
+
search_prompt?: string;
|
|
240
|
+
engine?: "native" | "exa" | (string & {});
|
|
241
|
+
}
|
|
242
|
+
export interface FileParserPlugin {
|
|
243
|
+
id: "file-parser";
|
|
244
|
+
enabled?: boolean;
|
|
245
|
+
pdf?: {
|
|
246
|
+
engine?: "mistral-ocr" | "pdf-text" | "native" | (string & {});
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export interface ResponseHealingPlugin {
|
|
250
|
+
id: "response-healing";
|
|
251
|
+
enabled?: boolean;
|
|
252
|
+
}
|
|
253
|
+
export type PluginDefinition = AutoRouterPlugin | ModerationPlugin | WebPlugin | FileParserPlugin | ResponseHealingPlugin | {
|
|
254
|
+
id: string;
|
|
255
|
+
[key: string]: unknown;
|
|
256
|
+
};
|
|
257
|
+
export interface TraceConfig {
|
|
258
|
+
trace_id?: string;
|
|
259
|
+
trace_name?: string;
|
|
260
|
+
span_name?: string;
|
|
261
|
+
generation_name?: string;
|
|
262
|
+
parent_span_id?: string;
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
export interface ChatStreamOptions {
|
|
266
|
+
include_usage?: boolean;
|
|
267
|
+
}
|
|
268
|
+
export interface ChatGenerationParams {
|
|
269
|
+
messages: Message[];
|
|
270
|
+
model?: ModelName;
|
|
271
|
+
models?: ModelName[];
|
|
272
|
+
provider?: ProviderPreferences | null;
|
|
273
|
+
plugins?: PluginDefinition[];
|
|
274
|
+
route?: "fallback" | "sort" | (string & {}) | null;
|
|
275
|
+
user?: string;
|
|
276
|
+
session_id?: string;
|
|
277
|
+
trace?: TraceConfig;
|
|
278
|
+
frequency_penalty?: number | null;
|
|
279
|
+
logit_bias?: Record<string, number> | null;
|
|
280
|
+
logprobs?: boolean | null;
|
|
281
|
+
top_logprobs?: number | null;
|
|
282
|
+
max_completion_tokens?: number | null;
|
|
283
|
+
max_tokens?: number | null;
|
|
284
|
+
metadata?: Record<string, string>;
|
|
285
|
+
presence_penalty?: number | null;
|
|
286
|
+
reasoning?: {
|
|
287
|
+
effort?: "xhigh" | "high" | "medium" | "low" | "minimal" | "none" | (string & {}) | null;
|
|
288
|
+
summary?: ReasoningSummaryVerbosity | null;
|
|
289
|
+
};
|
|
290
|
+
response_format?: {
|
|
291
|
+
type: "text";
|
|
292
|
+
} | {
|
|
293
|
+
type: "json_object";
|
|
294
|
+
} | ResponseFormatJSONSchema | ResponseFormatTextGrammar | {
|
|
295
|
+
type: "python";
|
|
296
|
+
};
|
|
297
|
+
seed?: number | null;
|
|
298
|
+
stop?: string | string[] | null;
|
|
299
|
+
stream?: boolean;
|
|
300
|
+
stream_options?: ChatStreamOptions | null;
|
|
301
|
+
temperature?: number | null;
|
|
302
|
+
parallel_tool_calls?: boolean | null;
|
|
303
|
+
tool_choice?: ToolChoiceOption;
|
|
304
|
+
tools?: ToolDefinitionJson[];
|
|
305
|
+
top_p?: number | null;
|
|
306
|
+
debug?: {
|
|
307
|
+
echo_upstream_body?: boolean;
|
|
308
|
+
};
|
|
309
|
+
image_config?: Record<string, string | number | unknown[]>;
|
|
310
|
+
modalities?: Array<"text" | "image" | (string & {})>;
|
|
311
|
+
}
|
|
312
|
+
export interface ChatResponseChoice {
|
|
313
|
+
finish_reason: ChatCompletionFinishReason | null;
|
|
314
|
+
index: number;
|
|
315
|
+
message: AssistantMessage;
|
|
316
|
+
logprobs?: ChatMessageTokenLogprobs | null;
|
|
317
|
+
}
|
|
318
|
+
export interface ChatResponse {
|
|
319
|
+
id: string;
|
|
320
|
+
choices: ChatResponseChoice[];
|
|
321
|
+
created: number;
|
|
322
|
+
model: string;
|
|
323
|
+
object: "chat.completion";
|
|
324
|
+
system_fingerprint?: string | null;
|
|
325
|
+
usage?: ChatGenerationTokenUsage;
|
|
326
|
+
}
|
|
327
|
+
export interface ChatStreamingMessageChunk {
|
|
328
|
+
role?: "assistant";
|
|
329
|
+
content?: string | null;
|
|
330
|
+
reasoning?: string | null;
|
|
331
|
+
refusal?: string | null;
|
|
332
|
+
tool_calls?: ChatStreamingMessageToolCall[];
|
|
333
|
+
reasoning_details?: ReasoningDetail[];
|
|
334
|
+
}
|
|
335
|
+
export interface ChatStreamingChoice {
|
|
336
|
+
delta: ChatStreamingMessageChunk;
|
|
337
|
+
finish_reason: ChatCompletionFinishReason | null;
|
|
338
|
+
index: number;
|
|
339
|
+
logprobs?: ChatMessageTokenLogprobs | null;
|
|
340
|
+
}
|
|
341
|
+
export interface ChatStreamingResponseChunk {
|
|
342
|
+
data: {
|
|
343
|
+
id: string;
|
|
344
|
+
choices: ChatStreamingChoice[];
|
|
345
|
+
created: number;
|
|
346
|
+
model: string;
|
|
347
|
+
object: "chat.completion.chunk";
|
|
348
|
+
system_fingerprint?: string | null;
|
|
349
|
+
error?: {
|
|
350
|
+
message: string;
|
|
351
|
+
code: number;
|
|
352
|
+
};
|
|
353
|
+
usage?: ChatGenerationTokenUsage;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
export interface ChatError {
|
|
357
|
+
error: {
|
|
358
|
+
code: string | number | null;
|
|
359
|
+
message: string;
|
|
360
|
+
param?: string | null;
|
|
361
|
+
type?: string | null;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
export {};
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
export { OpenRouter };
|
|
368
|
+
//# sourceMappingURL=api-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-types.d.cts","names":[],"sources":["../src/api-types.ts"],"mappings":";kBAMiB,UAAA;EAAA;EAAA,YAMH,SAAA;;;;;cAMA,cAAA;EAAA,YAMA,yBAAA;EAAA,YAMA,cAAA;EAAA,YAEA,YAAA;EAAA,YAYA,YAAA;EAAA,YAEA,YAAA;EAAA,YA4EA,0BAAA;EAAA,YAQA,qBAAA;EAAA,iBAaK,kCAAA;IACf,IAAA;IACA,GAAA;EAAA;EAAA,iBAOe,0BAAA;IACf,IAAA;IACA,IAAA;IACA,aAAA,GAAgB,kCAAA;EAAA;EAAA,iBAGD,2BAAA;IACf,IAAA;IACA,SAAA;MACE,GAAA;MACA,MAA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