@providerprotocol/ai 0.0.1 → 0.0.3
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/dist/anthropic/index.js +4 -2
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-FTFX2VET.js → chunk-SUNYWHTH.js} +2 -89
- package/dist/chunk-SUNYWHTH.js.map +1 -0
- package/dist/chunk-X5G4EHL7.js +90 -0
- package/dist/chunk-X5G4EHL7.js.map +1 -0
- package/dist/google/index.js +4 -2
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.js +5 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +108 -0
- package/dist/ollama/index.js +537 -0
- package/dist/ollama/index.js.map +1 -0
- package/dist/openai/index.js +4 -2
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +235 -0
- package/dist/openrouter/index.js +1342 -0
- package/dist/openrouter/index.js.map +1 -0
- package/package.json +16 -1
- package/src/ollama/index.ts +3 -0
- package/src/openrouter/index.ts +10 -0
- package/src/providers/ollama/index.ts +43 -0
- package/src/providers/ollama/llm.ts +272 -0
- package/src/providers/ollama/transform.ts +456 -0
- package/src/providers/ollama/types.ts +260 -0
- package/src/providers/openrouter/index.ts +173 -0
- package/src/providers/openrouter/llm.completions.ts +201 -0
- package/src/providers/openrouter/llm.responses.ts +211 -0
- package/src/providers/openrouter/transform.completions.ts +605 -0
- package/src/providers/openrouter/transform.responses.ts +755 -0
- package/src/providers/openrouter/types.ts +723 -0
- package/dist/chunk-FTFX2VET.js.map +0 -1
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRouter-specific LLM parameters
|
|
3
|
+
* These are passed through to the OpenRouter APIs
|
|
4
|
+
*/
|
|
5
|
+
export interface OpenRouterLLMParams {
|
|
6
|
+
// ============================================
|
|
7
|
+
// Common Parameters (both APIs)
|
|
8
|
+
// ============================================
|
|
9
|
+
|
|
10
|
+
/** Maximum number of tokens to generate */
|
|
11
|
+
max_tokens?: number;
|
|
12
|
+
|
|
13
|
+
/** Maximum output tokens (Responses API) */
|
|
14
|
+
max_output_tokens?: number;
|
|
15
|
+
|
|
16
|
+
/** Temperature for randomness (0.0 - 2.0) */
|
|
17
|
+
temperature?: number;
|
|
18
|
+
|
|
19
|
+
/** Top-p (nucleus) sampling (0.0 - 1.0) */
|
|
20
|
+
top_p?: number;
|
|
21
|
+
|
|
22
|
+
/** Top-k sampling (not available for OpenAI models) */
|
|
23
|
+
top_k?: number;
|
|
24
|
+
|
|
25
|
+
/** Frequency penalty (-2.0 - 2.0) */
|
|
26
|
+
frequency_penalty?: number;
|
|
27
|
+
|
|
28
|
+
/** Presence penalty (-2.0 - 2.0) */
|
|
29
|
+
presence_penalty?: number;
|
|
30
|
+
|
|
31
|
+
/** Repetition penalty (0.0 - 2.0) */
|
|
32
|
+
repetition_penalty?: number;
|
|
33
|
+
|
|
34
|
+
/** Custom stop sequences */
|
|
35
|
+
stop?: string | string[];
|
|
36
|
+
|
|
37
|
+
/** Seed for deterministic sampling */
|
|
38
|
+
seed?: number;
|
|
39
|
+
|
|
40
|
+
/** User identifier for abuse detection */
|
|
41
|
+
user?: string;
|
|
42
|
+
|
|
43
|
+
/** Enable logprobs */
|
|
44
|
+
logprobs?: boolean;
|
|
45
|
+
|
|
46
|
+
/** Number of top logprobs to return */
|
|
47
|
+
top_logprobs?: number;
|
|
48
|
+
|
|
49
|
+
/** Logit bias map */
|
|
50
|
+
logit_bias?: Record<number, number>;
|
|
51
|
+
|
|
52
|
+
/** Minimum probability threshold (0.0 - 1.0) */
|
|
53
|
+
min_p?: number;
|
|
54
|
+
|
|
55
|
+
/** Top-a sampling threshold (0.0 - 1.0) */
|
|
56
|
+
top_a?: number;
|
|
57
|
+
|
|
58
|
+
// ============================================
|
|
59
|
+
// Tool Calling
|
|
60
|
+
// ============================================
|
|
61
|
+
|
|
62
|
+
/** Whether to enable parallel tool calls */
|
|
63
|
+
parallel_tool_calls?: boolean;
|
|
64
|
+
|
|
65
|
+
// ============================================
|
|
66
|
+
// Structured Output
|
|
67
|
+
// ============================================
|
|
68
|
+
|
|
69
|
+
/** Response format for structured output (Chat Completions API only) */
|
|
70
|
+
response_format?: OpenRouterResponseFormat;
|
|
71
|
+
|
|
72
|
+
// ============================================
|
|
73
|
+
// OpenRouter-Specific Parameters
|
|
74
|
+
// ============================================
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Prompt transforms to apply
|
|
78
|
+
* See: https://openrouter.ai/docs/guides/features/message-transforms
|
|
79
|
+
*/
|
|
80
|
+
transforms?: string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Multiple models for routing
|
|
84
|
+
* See: https://openrouter.ai/docs/guides/features/model-routing
|
|
85
|
+
*/
|
|
86
|
+
models?: string[];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Routing strategy (e.g., 'fallback')
|
|
90
|
+
*/
|
|
91
|
+
route?: 'fallback';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Provider routing preferences
|
|
95
|
+
* See: https://openrouter.ai/docs/guides/routing/provider-selection
|
|
96
|
+
*/
|
|
97
|
+
provider?: OpenRouterProviderPreferences;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Predicted output for latency optimization
|
|
101
|
+
* https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs
|
|
102
|
+
*/
|
|
103
|
+
prediction?: {
|
|
104
|
+
type: 'content';
|
|
105
|
+
content: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Debug options (streaming only)
|
|
110
|
+
*/
|
|
111
|
+
debug?: {
|
|
112
|
+
/** If true, returns the transformed request body sent to the provider */
|
|
113
|
+
echo_upstream_body?: boolean;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// ============================================
|
|
117
|
+
// Responses API Specific
|
|
118
|
+
// ============================================
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Reasoning configuration (Responses API)
|
|
122
|
+
*/
|
|
123
|
+
reasoning?: {
|
|
124
|
+
effort?: 'low' | 'medium' | 'high';
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* API mode for OpenRouter provider
|
|
130
|
+
*/
|
|
131
|
+
export type OpenRouterAPIMode = 'completions' | 'responses';
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Model options when creating a model reference
|
|
135
|
+
*/
|
|
136
|
+
export interface OpenRouterModelOptions {
|
|
137
|
+
/** Which API to use */
|
|
138
|
+
api?: OpenRouterAPIMode;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Model reference with OpenRouter-specific options
|
|
143
|
+
*/
|
|
144
|
+
export interface OpenRouterModelReference {
|
|
145
|
+
modelId: string;
|
|
146
|
+
options?: OpenRouterModelOptions;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* OpenRouter provider configuration
|
|
151
|
+
*/
|
|
152
|
+
export interface OpenRouterConfig {
|
|
153
|
+
/** Which API to use: 'completions' (default) or 'responses' (beta) */
|
|
154
|
+
api?: 'completions' | 'responses';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Provider routing preferences
|
|
159
|
+
*/
|
|
160
|
+
export interface OpenRouterProviderPreferences {
|
|
161
|
+
/** Allow fallback to other providers */
|
|
162
|
+
allow_fallbacks?: boolean;
|
|
163
|
+
/** Require specific parameters to be supported */
|
|
164
|
+
require_parameters?: boolean;
|
|
165
|
+
/** Data collection policy */
|
|
166
|
+
data_collection?: 'allow' | 'deny';
|
|
167
|
+
/** Order of provider preference */
|
|
168
|
+
order?: string[];
|
|
169
|
+
/** Ignore specific providers */
|
|
170
|
+
ignore?: string[];
|
|
171
|
+
/** Quantization preferences */
|
|
172
|
+
quantizations?: string[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ============================================
|
|
176
|
+
// Chat Completions API Types
|
|
177
|
+
// ============================================
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Chat Completions API request body
|
|
181
|
+
*/
|
|
182
|
+
export interface OpenRouterCompletionsRequest {
|
|
183
|
+
model: string;
|
|
184
|
+
messages?: OpenRouterCompletionsMessage[];
|
|
185
|
+
prompt?: string;
|
|
186
|
+
temperature?: number;
|
|
187
|
+
top_p?: number;
|
|
188
|
+
top_k?: number;
|
|
189
|
+
min_p?: number;
|
|
190
|
+
top_a?: number;
|
|
191
|
+
stream?: boolean;
|
|
192
|
+
stream_options?: { include_usage?: boolean };
|
|
193
|
+
stop?: string | string[];
|
|
194
|
+
max_tokens?: number;
|
|
195
|
+
presence_penalty?: number;
|
|
196
|
+
frequency_penalty?: number;
|
|
197
|
+
repetition_penalty?: number;
|
|
198
|
+
logit_bias?: Record<number, number>;
|
|
199
|
+
logprobs?: boolean;
|
|
200
|
+
top_logprobs?: number;
|
|
201
|
+
user?: string;
|
|
202
|
+
seed?: number;
|
|
203
|
+
tools?: OpenRouterCompletionsTool[];
|
|
204
|
+
tool_choice?: OpenRouterToolChoice;
|
|
205
|
+
parallel_tool_calls?: boolean;
|
|
206
|
+
response_format?: OpenRouterResponseFormat;
|
|
207
|
+
prediction?: {
|
|
208
|
+
type: 'content';
|
|
209
|
+
content: string;
|
|
210
|
+
};
|
|
211
|
+
// OpenRouter-specific
|
|
212
|
+
transforms?: string[];
|
|
213
|
+
models?: string[];
|
|
214
|
+
route?: 'fallback';
|
|
215
|
+
provider?: OpenRouterProviderPreferences;
|
|
216
|
+
debug?: {
|
|
217
|
+
echo_upstream_body?: boolean;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Chat Completions message format
|
|
223
|
+
*/
|
|
224
|
+
export type OpenRouterCompletionsMessage =
|
|
225
|
+
| OpenRouterSystemMessage
|
|
226
|
+
| OpenRouterUserMessage
|
|
227
|
+
| OpenRouterAssistantMessage
|
|
228
|
+
| OpenRouterToolMessage;
|
|
229
|
+
|
|
230
|
+
export interface OpenRouterSystemMessage {
|
|
231
|
+
role: 'system';
|
|
232
|
+
content: string;
|
|
233
|
+
name?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface OpenRouterUserMessage {
|
|
237
|
+
role: 'user';
|
|
238
|
+
content: string | OpenRouterUserContent[];
|
|
239
|
+
name?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface OpenRouterAssistantMessage {
|
|
243
|
+
role: 'assistant';
|
|
244
|
+
content?: string | null;
|
|
245
|
+
name?: string;
|
|
246
|
+
tool_calls?: OpenRouterToolCall[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface OpenRouterToolMessage {
|
|
250
|
+
role: 'tool';
|
|
251
|
+
content: string;
|
|
252
|
+
tool_call_id: string;
|
|
253
|
+
name?: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* User content types
|
|
258
|
+
*/
|
|
259
|
+
export type OpenRouterUserContent = OpenRouterTextContent | OpenRouterImageContent;
|
|
260
|
+
|
|
261
|
+
export interface OpenRouterTextContent {
|
|
262
|
+
type: 'text';
|
|
263
|
+
text: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface OpenRouterImageContent {
|
|
267
|
+
type: 'image_url';
|
|
268
|
+
image_url: {
|
|
269
|
+
url: string;
|
|
270
|
+
detail?: 'auto' | 'low' | 'high';
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Tool call format
|
|
276
|
+
*/
|
|
277
|
+
export interface OpenRouterToolCall {
|
|
278
|
+
id: string;
|
|
279
|
+
type: 'function';
|
|
280
|
+
function: {
|
|
281
|
+
name: string;
|
|
282
|
+
arguments: string;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Tool definition for Chat Completions
|
|
288
|
+
*/
|
|
289
|
+
export interface OpenRouterCompletionsTool {
|
|
290
|
+
type: 'function';
|
|
291
|
+
function: {
|
|
292
|
+
name: string;
|
|
293
|
+
description: string;
|
|
294
|
+
parameters: {
|
|
295
|
+
type: 'object';
|
|
296
|
+
properties: Record<string, unknown>;
|
|
297
|
+
required?: string[];
|
|
298
|
+
additionalProperties?: boolean;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Tool choice options
|
|
305
|
+
*/
|
|
306
|
+
export type OpenRouterToolChoice =
|
|
307
|
+
| 'none'
|
|
308
|
+
| 'auto'
|
|
309
|
+
| { type: 'function'; function: { name: string } };
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Response format
|
|
313
|
+
*/
|
|
314
|
+
export type OpenRouterResponseFormat =
|
|
315
|
+
| { type: 'text' }
|
|
316
|
+
| { type: 'json_object' }
|
|
317
|
+
| {
|
|
318
|
+
type: 'json_schema';
|
|
319
|
+
json_schema: {
|
|
320
|
+
name: string;
|
|
321
|
+
description?: string;
|
|
322
|
+
schema: Record<string, unknown>;
|
|
323
|
+
strict?: boolean;
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Chat Completions response format
|
|
329
|
+
*/
|
|
330
|
+
export interface OpenRouterCompletionsResponse {
|
|
331
|
+
id: string;
|
|
332
|
+
object: 'chat.completion';
|
|
333
|
+
created: number;
|
|
334
|
+
model: string;
|
|
335
|
+
choices: OpenRouterCompletionsChoice[];
|
|
336
|
+
usage: OpenRouterUsage;
|
|
337
|
+
system_fingerprint?: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface OpenRouterCompletionsChoice {
|
|
341
|
+
index: number;
|
|
342
|
+
message: OpenRouterAssistantMessage;
|
|
343
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
344
|
+
logprobs?: OpenRouterLogprobs | null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface OpenRouterLogprobs {
|
|
348
|
+
content?: Array<{
|
|
349
|
+
token: string;
|
|
350
|
+
logprob: number;
|
|
351
|
+
bytes?: number[];
|
|
352
|
+
top_logprobs?: Array<{
|
|
353
|
+
token: string;
|
|
354
|
+
logprob: number;
|
|
355
|
+
bytes?: number[];
|
|
356
|
+
}>;
|
|
357
|
+
}>;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface OpenRouterUsage {
|
|
361
|
+
prompt_tokens: number;
|
|
362
|
+
completion_tokens: number;
|
|
363
|
+
total_tokens: number;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Chat Completions streaming event types
|
|
368
|
+
*/
|
|
369
|
+
export interface OpenRouterCompletionsStreamChunk {
|
|
370
|
+
id: string;
|
|
371
|
+
object: 'chat.completion.chunk';
|
|
372
|
+
created: number;
|
|
373
|
+
model: string;
|
|
374
|
+
choices: OpenRouterCompletionsStreamChoice[];
|
|
375
|
+
usage?: OpenRouterUsage | null;
|
|
376
|
+
system_fingerprint?: string;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface OpenRouterCompletionsStreamChoice {
|
|
380
|
+
index: number;
|
|
381
|
+
delta: OpenRouterCompletionsStreamDelta;
|
|
382
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
383
|
+
logprobs?: OpenRouterLogprobs | null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface OpenRouterCompletionsStreamDelta {
|
|
387
|
+
role?: 'assistant';
|
|
388
|
+
content?: string | null;
|
|
389
|
+
tool_calls?: OpenRouterStreamToolCall[];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface OpenRouterStreamToolCall {
|
|
393
|
+
index: number;
|
|
394
|
+
id?: string;
|
|
395
|
+
type?: 'function';
|
|
396
|
+
function?: {
|
|
397
|
+
name?: string;
|
|
398
|
+
arguments?: string;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ============================================
|
|
403
|
+
// Responses API Types (Beta)
|
|
404
|
+
// ============================================
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Responses API request body
|
|
408
|
+
*/
|
|
409
|
+
export interface OpenRouterResponsesRequest {
|
|
410
|
+
model: string;
|
|
411
|
+
input: string | OpenRouterResponsesInputItem[];
|
|
412
|
+
max_output_tokens?: number;
|
|
413
|
+
temperature?: number;
|
|
414
|
+
top_p?: number;
|
|
415
|
+
stream?: boolean;
|
|
416
|
+
tools?: OpenRouterResponsesTool[];
|
|
417
|
+
tool_choice?: OpenRouterResponsesToolChoice;
|
|
418
|
+
parallel_tool_calls?: boolean;
|
|
419
|
+
text?: OpenRouterResponsesTextConfig;
|
|
420
|
+
reasoning?: {
|
|
421
|
+
effort?: 'low' | 'medium' | 'high';
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Responses API input item
|
|
427
|
+
*/
|
|
428
|
+
export type OpenRouterResponsesInputItem =
|
|
429
|
+
| OpenRouterResponsesSystemItem
|
|
430
|
+
| OpenRouterResponsesUserItem
|
|
431
|
+
| OpenRouterResponsesAssistantItem
|
|
432
|
+
| OpenRouterResponsesFunctionCallInputItem
|
|
433
|
+
| OpenRouterResponsesToolResultItem;
|
|
434
|
+
|
|
435
|
+
export interface OpenRouterResponsesSystemItem {
|
|
436
|
+
type: 'message';
|
|
437
|
+
role: 'system';
|
|
438
|
+
content: string | OpenRouterResponsesContentPart[];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export interface OpenRouterResponsesUserItem {
|
|
442
|
+
type: 'message';
|
|
443
|
+
role: 'user';
|
|
444
|
+
content: string | OpenRouterResponsesContentPart[];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface OpenRouterResponsesAssistantItem {
|
|
448
|
+
type: 'message';
|
|
449
|
+
role: 'assistant';
|
|
450
|
+
id: string;
|
|
451
|
+
status: 'completed' | 'in_progress';
|
|
452
|
+
content: OpenRouterResponsesContentPart[];
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export interface OpenRouterResponsesFunctionCallInputItem {
|
|
456
|
+
type: 'function_call';
|
|
457
|
+
id: string;
|
|
458
|
+
call_id: string;
|
|
459
|
+
name: string;
|
|
460
|
+
arguments: string;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export interface OpenRouterResponsesToolResultItem {
|
|
464
|
+
type: 'function_call_output';
|
|
465
|
+
id: string;
|
|
466
|
+
call_id: string;
|
|
467
|
+
output: string;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Content parts for Responses API
|
|
472
|
+
*/
|
|
473
|
+
export type OpenRouterResponsesContentPart =
|
|
474
|
+
| OpenRouterResponsesInputTextPart
|
|
475
|
+
| OpenRouterResponsesOutputTextPart
|
|
476
|
+
| OpenRouterResponsesImagePart
|
|
477
|
+
| OpenRouterResponsesFunctionCallPart;
|
|
478
|
+
|
|
479
|
+
/** @deprecated Use OpenRouterResponsesInputTextPart or OpenRouterResponsesOutputTextPart */
|
|
480
|
+
export type OpenRouterResponsesTextPart = OpenRouterResponsesInputTextPart | OpenRouterResponsesOutputTextPart;
|
|
481
|
+
|
|
482
|
+
export interface OpenRouterResponsesInputTextPart {
|
|
483
|
+
type: 'input_text';
|
|
484
|
+
text: string;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export interface OpenRouterResponsesOutputTextPart {
|
|
488
|
+
type: 'output_text';
|
|
489
|
+
text: string;
|
|
490
|
+
annotations?: unknown[];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export interface OpenRouterResponsesImagePart {
|
|
494
|
+
type: 'input_image';
|
|
495
|
+
image_url?: string;
|
|
496
|
+
image?: string; // base64
|
|
497
|
+
detail?: 'auto' | 'low' | 'high';
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export interface OpenRouterResponsesFunctionCallPart {
|
|
501
|
+
type: 'function_call';
|
|
502
|
+
id: string;
|
|
503
|
+
call_id: string;
|
|
504
|
+
name: string;
|
|
505
|
+
arguments: string;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Tool definition for Responses API
|
|
510
|
+
*/
|
|
511
|
+
export interface OpenRouterResponsesTool {
|
|
512
|
+
type: 'function';
|
|
513
|
+
name: string;
|
|
514
|
+
description: string;
|
|
515
|
+
parameters: {
|
|
516
|
+
type: 'object';
|
|
517
|
+
properties: Record<string, unknown>;
|
|
518
|
+
required?: string[];
|
|
519
|
+
additionalProperties?: boolean;
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Tool choice for Responses API
|
|
525
|
+
*/
|
|
526
|
+
export type OpenRouterResponsesToolChoice =
|
|
527
|
+
| 'none'
|
|
528
|
+
| 'auto'
|
|
529
|
+
| { type: 'function'; name: string };
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Text configuration for structured output
|
|
533
|
+
*/
|
|
534
|
+
export interface OpenRouterResponsesTextConfig {
|
|
535
|
+
format?:
|
|
536
|
+
| { type: 'text' }
|
|
537
|
+
| { type: 'json_object' }
|
|
538
|
+
| {
|
|
539
|
+
type: 'json_schema';
|
|
540
|
+
name: string;
|
|
541
|
+
description?: string;
|
|
542
|
+
schema: Record<string, unknown>;
|
|
543
|
+
strict?: boolean;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Responses API response format
|
|
549
|
+
*/
|
|
550
|
+
export interface OpenRouterResponsesResponse {
|
|
551
|
+
id: string;
|
|
552
|
+
object: 'response';
|
|
553
|
+
created_at: number;
|
|
554
|
+
model: string;
|
|
555
|
+
output: OpenRouterResponsesOutputItem[];
|
|
556
|
+
usage: OpenRouterResponsesUsage;
|
|
557
|
+
status: 'completed' | 'failed' | 'incomplete' | 'in_progress';
|
|
558
|
+
error?: {
|
|
559
|
+
code: string;
|
|
560
|
+
message: string;
|
|
561
|
+
};
|
|
562
|
+
incomplete_details?: {
|
|
563
|
+
reason: string;
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export type OpenRouterResponsesOutputItem =
|
|
568
|
+
| OpenRouterResponsesMessageOutput
|
|
569
|
+
| OpenRouterResponsesFunctionCallOutput;
|
|
570
|
+
|
|
571
|
+
export interface OpenRouterResponsesMessageOutput {
|
|
572
|
+
type: 'message';
|
|
573
|
+
id: string;
|
|
574
|
+
role: 'assistant';
|
|
575
|
+
content: OpenRouterResponsesOutputContent[];
|
|
576
|
+
status: 'completed' | 'in_progress';
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export interface OpenRouterResponsesFunctionCallOutput {
|
|
580
|
+
type: 'function_call';
|
|
581
|
+
id: string;
|
|
582
|
+
call_id: string;
|
|
583
|
+
name: string;
|
|
584
|
+
arguments: string;
|
|
585
|
+
status: 'completed' | 'in_progress';
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export type OpenRouterResponsesOutputContent =
|
|
589
|
+
| { type: 'output_text'; text: string; annotations?: unknown[] }
|
|
590
|
+
| { type: 'refusal'; refusal: string };
|
|
591
|
+
|
|
592
|
+
export interface OpenRouterResponsesUsage {
|
|
593
|
+
input_tokens: number;
|
|
594
|
+
output_tokens: number;
|
|
595
|
+
total_tokens: number;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Responses API streaming event types
|
|
600
|
+
*/
|
|
601
|
+
export type OpenRouterResponsesStreamEvent =
|
|
602
|
+
| OpenRouterResponseCreatedEvent
|
|
603
|
+
| OpenRouterResponseInProgressEvent
|
|
604
|
+
| OpenRouterResponseCompletedEvent
|
|
605
|
+
| OpenRouterResponseFailedEvent
|
|
606
|
+
| OpenRouterResponseOutputItemAddedEvent
|
|
607
|
+
| OpenRouterResponseOutputItemDoneEvent
|
|
608
|
+
| OpenRouterResponseContentPartAddedEvent
|
|
609
|
+
| OpenRouterResponseContentPartDoneEvent
|
|
610
|
+
| OpenRouterResponseTextDeltaEvent
|
|
611
|
+
| OpenRouterResponseTextDoneEvent
|
|
612
|
+
| OpenRouterResponseRefusalDeltaEvent
|
|
613
|
+
| OpenRouterResponseRefusalDoneEvent
|
|
614
|
+
| OpenRouterResponseFunctionCallArgumentsDeltaEvent
|
|
615
|
+
| OpenRouterResponseFunctionCallArgumentsDoneEvent
|
|
616
|
+
| OpenRouterResponseReasoningDeltaEvent
|
|
617
|
+
| OpenRouterResponseErrorEvent;
|
|
618
|
+
|
|
619
|
+
export interface OpenRouterResponseCreatedEvent {
|
|
620
|
+
type: 'response.created';
|
|
621
|
+
response: OpenRouterResponsesResponse;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export interface OpenRouterResponseInProgressEvent {
|
|
625
|
+
type: 'response.in_progress';
|
|
626
|
+
response: OpenRouterResponsesResponse;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export interface OpenRouterResponseCompletedEvent {
|
|
630
|
+
type: 'response.completed' | 'response.done';
|
|
631
|
+
response: OpenRouterResponsesResponse;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export interface OpenRouterResponseFailedEvent {
|
|
635
|
+
type: 'response.failed';
|
|
636
|
+
response: OpenRouterResponsesResponse;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export interface OpenRouterResponseOutputItemAddedEvent {
|
|
640
|
+
type: 'response.output_item.added';
|
|
641
|
+
output_index: number;
|
|
642
|
+
item: OpenRouterResponsesOutputItem;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export interface OpenRouterResponseOutputItemDoneEvent {
|
|
646
|
+
type: 'response.output_item.done';
|
|
647
|
+
output_index: number;
|
|
648
|
+
item: OpenRouterResponsesOutputItem;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export interface OpenRouterResponseContentPartAddedEvent {
|
|
652
|
+
type: 'response.content_part.added';
|
|
653
|
+
output_index: number;
|
|
654
|
+
content_index: number;
|
|
655
|
+
part: OpenRouterResponsesOutputContent;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export interface OpenRouterResponseContentPartDoneEvent {
|
|
659
|
+
type: 'response.content_part.done';
|
|
660
|
+
output_index: number;
|
|
661
|
+
content_index: number;
|
|
662
|
+
part: OpenRouterResponsesOutputContent;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
export interface OpenRouterResponseTextDeltaEvent {
|
|
666
|
+
type: 'response.content_part.delta' | 'response.output_text.delta';
|
|
667
|
+
response_id?: string;
|
|
668
|
+
output_index: number;
|
|
669
|
+
content_index?: number;
|
|
670
|
+
delta: string;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export interface OpenRouterResponseTextDoneEvent {
|
|
674
|
+
type: 'response.output_text.done' | 'response.content_part.done';
|
|
675
|
+
output_index: number;
|
|
676
|
+
content_index?: number;
|
|
677
|
+
text: string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export interface OpenRouterResponseRefusalDeltaEvent {
|
|
681
|
+
type: 'response.refusal.delta';
|
|
682
|
+
output_index: number;
|
|
683
|
+
content_index: number;
|
|
684
|
+
delta: string;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export interface OpenRouterResponseRefusalDoneEvent {
|
|
688
|
+
type: 'response.refusal.done';
|
|
689
|
+
output_index: number;
|
|
690
|
+
content_index: number;
|
|
691
|
+
refusal: string;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export interface OpenRouterResponseFunctionCallArgumentsDeltaEvent {
|
|
695
|
+
type: 'response.function_call_arguments.delta';
|
|
696
|
+
output_index: number;
|
|
697
|
+
item_id: string;
|
|
698
|
+
delta: string;
|
|
699
|
+
call_id?: string;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export interface OpenRouterResponseFunctionCallArgumentsDoneEvent {
|
|
703
|
+
type: 'response.function_call_arguments.done';
|
|
704
|
+
output_index: number;
|
|
705
|
+
item_id: string;
|
|
706
|
+
name: string;
|
|
707
|
+
arguments: string;
|
|
708
|
+
call_id?: string;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export interface OpenRouterResponseReasoningDeltaEvent {
|
|
712
|
+
type: 'response.reasoning.delta';
|
|
713
|
+
delta: string;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
export interface OpenRouterResponseErrorEvent {
|
|
717
|
+
type: 'error';
|
|
718
|
+
error: {
|
|
719
|
+
type: string;
|
|
720
|
+
code?: string;
|
|
721
|
+
message: string;
|
|
722
|
+
};
|
|
723
|
+
}
|