@openrouter/sdk 0.3.15 → 0.4.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/esm/funcs/modelsListForUser.d.ts +5 -2
- package/esm/funcs/modelsListForUser.js +6 -3
- package/esm/index.d.ts +3 -2
- package/esm/index.js +1 -1
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +2 -2
- package/esm/lib/model-result.d.ts +25 -3
- package/esm/lib/model-result.js +93 -21
- package/esm/lib/stream-transformers.d.ts +12 -0
- package/esm/lib/stream-transformers.js +206 -0
- package/esm/lib/tool-executor.js +37 -13
- package/esm/lib/tool-types.d.ts +28 -2
- package/esm/lib/tool-types.js +6 -0
- package/esm/models/chatgenerationparams.d.ts +22 -22
- package/esm/models/chatgenerationparams.js +24 -21
- package/esm/models/index.d.ts +0 -5
- package/esm/models/index.js +0 -5
- package/esm/models/outputmodality.d.ts +1 -0
- package/esm/models/outputmodality.js +1 -0
- package/esm/models/publicendpoint.d.ts +8 -0
- package/esm/models/publicendpoint.js +4 -0
- package/esm/models/publicpricing.d.ts +4 -0
- package/esm/models/publicpricing.js +2 -0
- package/esm/sdk/models.d.ts +4 -1
- package/esm/sdk/models.js +4 -1
- package/esm/sdk/sdk.d.ts +0 -3
- package/esm/sdk/sdk.js +0 -4
- package/jsr.json +1 -1
- package/package.json +12 -12
- package/esm/funcs/completionsGenerate.d.ts +0 -18
- package/esm/funcs/completionsGenerate.js +0 -83
- package/esm/models/completionchoice.d.ts +0 -25
- package/esm/models/completionchoice.js +0 -34
- package/esm/models/completioncreateparams.d.ts +0 -120
- package/esm/models/completioncreateparams.js +0 -118
- package/esm/models/completionlogprobs.d.ts +0 -15
- package/esm/models/completionlogprobs.js +0 -24
- package/esm/models/completionresponse.d.ts +0 -19
- package/esm/models/completionresponse.js +0 -28
- package/esm/models/completionusage.d.ts +0 -12
- package/esm/models/completionusage.js +0 -23
- package/esm/sdk/completions.d.ts +0 -12
- package/esm/sdk/completions.js +0 -19
package/esm/lib/tool-executor.js
CHANGED
|
@@ -87,6 +87,14 @@ export function validateToolInput(schema, args) {
|
|
|
87
87
|
export function validateToolOutput(schema, result) {
|
|
88
88
|
return z4.parse(schema, result);
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Try to validate a value against a Zod schema without throwing
|
|
92
|
+
* @returns true if validation succeeds, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
function tryValidate(schema, value) {
|
|
95
|
+
const result = z4.safeParse(schema, value);
|
|
96
|
+
return result.success;
|
|
97
|
+
}
|
|
90
98
|
/**
|
|
91
99
|
* Parse tool call arguments from JSON string
|
|
92
100
|
*/
|
|
@@ -150,29 +158,45 @@ export async function executeGeneratorTool(tool, toolCall, context, onPreliminar
|
|
|
150
158
|
// Validate input - the schema validation ensures type safety at runtime
|
|
151
159
|
// The inputSchema's inferred type matches the execute function's parameter type by construction
|
|
152
160
|
const validatedInput = validateToolInput(tool.function.inputSchema, toolCall.arguments);
|
|
153
|
-
//
|
|
161
|
+
// Stream preliminary results in realtime
|
|
162
|
+
// Final result is identified by: matches outputSchema BUT NOT eventSchema
|
|
163
|
+
// All other yields are preliminary results (validated against eventSchema)
|
|
164
|
+
// If no explicit final result is found, the last emitted value is used as the final result
|
|
154
165
|
const preliminaryResults = [];
|
|
155
|
-
let
|
|
166
|
+
let finalResult = undefined;
|
|
167
|
+
let hasFinalResult = false;
|
|
168
|
+
let lastEmittedValue = undefined;
|
|
156
169
|
let hasEmittedValue = false;
|
|
157
170
|
for await (const event of tool.function.execute(validatedInput, context)) {
|
|
171
|
+
lastEmittedValue = event;
|
|
158
172
|
hasEmittedValue = true;
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
// Try to determine if this is the final result:
|
|
174
|
+
// It must match outputSchema but NOT match eventSchema
|
|
175
|
+
const matchesOutputSchema = tryValidate(tool.function.outputSchema, event);
|
|
176
|
+
const matchesEventSchema = tryValidate(tool.function.eventSchema, event);
|
|
177
|
+
if (matchesOutputSchema && !matchesEventSchema && !hasFinalResult) {
|
|
178
|
+
// This is the final result - matches output but not event schema
|
|
179
|
+
finalResult = validateToolOutput(tool.function.outputSchema, event);
|
|
180
|
+
hasFinalResult = true;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// This is a preliminary result - validate against eventSchema and emit in realtime
|
|
184
|
+
const validatedPreliminary = validateToolOutput(tool.function.eventSchema, event);
|
|
185
|
+
preliminaryResults.push(validatedPreliminary);
|
|
186
|
+
if (onPreliminaryResult) {
|
|
187
|
+
onPreliminaryResult(toolCall.id, validatedPreliminary);
|
|
188
|
+
}
|
|
166
189
|
}
|
|
167
190
|
}
|
|
168
191
|
// Generator must emit at least one value
|
|
169
192
|
if (!hasEmittedValue) {
|
|
170
193
|
throw new Error(`Generator tool "${toolCall.name}" completed without emitting any values`);
|
|
171
194
|
}
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
// If no explicit final result was found (no yield matched outputSchema but not eventSchema),
|
|
196
|
+
// use the last emitted value as the final result
|
|
197
|
+
if (!hasFinalResult) {
|
|
198
|
+
finalResult = validateToolOutput(tool.function.outputSchema, lastEmittedValue);
|
|
199
|
+
}
|
|
176
200
|
return {
|
|
177
201
|
toolCallId: toolCall.id,
|
|
178
202
|
toolName: toolCall.name,
|
package/esm/lib/tool-types.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export type NextTurnParamsFunctions<TInput> = {
|
|
|
58
58
|
export type ToolApprovalCheck<TInput> = (params: TInput, context: TurnContext) => boolean | Promise<boolean>;
|
|
59
59
|
/**
|
|
60
60
|
* Base tool function interface with inputSchema
|
|
61
|
+
* @template TInput - Zod schema for tool input
|
|
61
62
|
*/
|
|
62
63
|
export interface BaseToolFunction<TInput extends $ZodObject<$ZodShape>> {
|
|
63
64
|
name: string;
|
|
@@ -175,6 +176,13 @@ export type TypedToolCallUnion<T extends readonly Tool[]> = {
|
|
|
175
176
|
export type ToolExecutionResultUnion<T extends readonly Tool[]> = {
|
|
176
177
|
[K in keyof T]: T[K] extends Tool ? ToolExecutionResult<T[K]> : never;
|
|
177
178
|
}[number];
|
|
179
|
+
/**
|
|
180
|
+
* Union of output types for all tools in a tuple
|
|
181
|
+
* Used for typing tool result events
|
|
182
|
+
*/
|
|
183
|
+
export type InferToolOutputsUnion<T extends readonly Tool[]> = {
|
|
184
|
+
[K in keyof T]: T[K] extends Tool ? InferToolOutput<T[K]> : never;
|
|
185
|
+
}[number];
|
|
178
186
|
/**
|
|
179
187
|
* Extracts the event type from a generator tool definition
|
|
180
188
|
* Returns `never` for non-generator tools
|
|
@@ -300,16 +308,34 @@ export type ToolPreliminaryResultEvent<TEvent = unknown> = {
|
|
|
300
308
|
result: TEvent;
|
|
301
309
|
timestamp: number;
|
|
302
310
|
};
|
|
311
|
+
/**
|
|
312
|
+
* Tool result event emitted when a tool execution completes
|
|
313
|
+
* Contains the final result and any preliminary results that were emitted
|
|
314
|
+
* @template TResult - The result type from the tool's outputSchema
|
|
315
|
+
* @template TPreliminaryResults - The event type from generator tools' eventSchema
|
|
316
|
+
*/
|
|
317
|
+
export type ToolResultEvent<TResult = unknown, TPreliminaryResults = unknown> = {
|
|
318
|
+
type: 'tool.result';
|
|
319
|
+
toolCallId: string;
|
|
320
|
+
result: TResult;
|
|
321
|
+
timestamp: number;
|
|
322
|
+
preliminaryResults?: TPreliminaryResults[];
|
|
323
|
+
};
|
|
303
324
|
/**
|
|
304
325
|
* Enhanced stream event types for getFullResponsesStream
|
|
305
|
-
* Extends OpenResponsesStreamEvent with tool preliminary results
|
|
326
|
+
* Extends OpenResponsesStreamEvent with tool preliminary results and tool results
|
|
306
327
|
* @template TEvent - The event type from generator tools
|
|
328
|
+
* @template TResult - The result type from tool execution
|
|
307
329
|
*/
|
|
308
|
-
export type ResponseStreamEvent<TEvent = unknown> = OpenResponsesStreamEvent | ToolPreliminaryResultEvent<TEvent>;
|
|
330
|
+
export type ResponseStreamEvent<TEvent = unknown, TResult = unknown> = OpenResponsesStreamEvent | ToolPreliminaryResultEvent<TEvent> | ToolResultEvent<TResult, TEvent>;
|
|
309
331
|
/**
|
|
310
332
|
* Type guard to check if an event is a tool preliminary result event
|
|
311
333
|
*/
|
|
312
334
|
export declare function isToolPreliminaryResultEvent<TEvent = unknown>(event: ResponseStreamEvent<TEvent>): event is ToolPreliminaryResultEvent<TEvent>;
|
|
335
|
+
/**
|
|
336
|
+
* Type guard to check if an event is a tool result event
|
|
337
|
+
*/
|
|
338
|
+
export declare function isToolResultEvent<TResult = unknown, TPreliminaryResults = unknown>(event: ResponseStreamEvent<TPreliminaryResults, TResult>): event is ToolResultEvent<TResult, TPreliminaryResults>;
|
|
313
339
|
/**
|
|
314
340
|
* Tool stream event types for getToolStream
|
|
315
341
|
* Includes both argument deltas and preliminary results
|
package/esm/lib/tool-types.js
CHANGED
|
@@ -35,6 +35,12 @@ export function isManualTool(tool) {
|
|
|
35
35
|
export function isToolPreliminaryResultEvent(event) {
|
|
36
36
|
return event.type === 'tool.preliminary_result';
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Type guard to check if an event is a tool result event
|
|
40
|
+
*/
|
|
41
|
+
export function isToolResultEvent(event) {
|
|
42
|
+
return event.type === 'tool.result';
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* Type guard to check if a tool has approval configured at runtime
|
|
40
46
|
*/
|
|
@@ -163,17 +163,17 @@ export type Reasoning = {
|
|
|
163
163
|
effort?: Effort | null | undefined;
|
|
164
164
|
summary?: ReasoningSummaryVerbosity | null | undefined;
|
|
165
165
|
};
|
|
166
|
-
export type
|
|
166
|
+
export type ResponseFormatPython = {
|
|
167
167
|
type: "python";
|
|
168
168
|
};
|
|
169
|
-
export type
|
|
169
|
+
export type ResponseFormatJSONObject = {
|
|
170
170
|
type: "json_object";
|
|
171
171
|
};
|
|
172
|
-
export type
|
|
172
|
+
export type ResponseFormatText = {
|
|
173
173
|
type: "text";
|
|
174
174
|
};
|
|
175
|
-
export type
|
|
176
|
-
export type
|
|
175
|
+
export type ResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatTextGrammar | ResponseFormatPython;
|
|
176
|
+
export type Stop = string | Array<string>;
|
|
177
177
|
export type Debug = {
|
|
178
178
|
echoUpstreamBody?: boolean | undefined;
|
|
179
179
|
};
|
|
@@ -214,7 +214,7 @@ export type ChatGenerationParams = {
|
|
|
214
214
|
} | undefined;
|
|
215
215
|
presencePenalty?: number | null | undefined;
|
|
216
216
|
reasoning?: Reasoning | undefined;
|
|
217
|
-
responseFormat?:
|
|
217
|
+
responseFormat?: ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatTextGrammar | ResponseFormatPython | undefined;
|
|
218
218
|
seed?: number | null | undefined;
|
|
219
219
|
stop?: string | Array<string> | null | undefined;
|
|
220
220
|
stream?: boolean | undefined;
|
|
@@ -366,36 +366,36 @@ export type Reasoning$Outbound = {
|
|
|
366
366
|
export declare const Reasoning$outboundSchema: z.ZodType<Reasoning$Outbound, Reasoning>;
|
|
367
367
|
export declare function reasoningToJSON(reasoning: Reasoning): string;
|
|
368
368
|
/** @internal */
|
|
369
|
-
export type
|
|
369
|
+
export type ResponseFormatPython$Outbound = {
|
|
370
370
|
type: "python";
|
|
371
371
|
};
|
|
372
372
|
/** @internal */
|
|
373
|
-
export declare const
|
|
374
|
-
export declare function
|
|
373
|
+
export declare const ResponseFormatPython$outboundSchema: z.ZodType<ResponseFormatPython$Outbound, ResponseFormatPython>;
|
|
374
|
+
export declare function responseFormatPythonToJSON(responseFormatPython: ResponseFormatPython): string;
|
|
375
375
|
/** @internal */
|
|
376
|
-
export type
|
|
376
|
+
export type ResponseFormatJSONObject$Outbound = {
|
|
377
377
|
type: "json_object";
|
|
378
378
|
};
|
|
379
379
|
/** @internal */
|
|
380
|
-
export declare const
|
|
381
|
-
export declare function
|
|
380
|
+
export declare const ResponseFormatJSONObject$outboundSchema: z.ZodType<ResponseFormatJSONObject$Outbound, ResponseFormatJSONObject>;
|
|
381
|
+
export declare function responseFormatJSONObjectToJSON(responseFormatJSONObject: ResponseFormatJSONObject): string;
|
|
382
382
|
/** @internal */
|
|
383
|
-
export type
|
|
383
|
+
export type ResponseFormatText$Outbound = {
|
|
384
384
|
type: "text";
|
|
385
385
|
};
|
|
386
386
|
/** @internal */
|
|
387
|
-
export declare const
|
|
388
|
-
export declare function
|
|
387
|
+
export declare const ResponseFormatText$outboundSchema: z.ZodType<ResponseFormatText$Outbound, ResponseFormatText>;
|
|
388
|
+
export declare function responseFormatTextToJSON(responseFormatText: ResponseFormatText): string;
|
|
389
389
|
/** @internal */
|
|
390
|
-
export type
|
|
390
|
+
export type ResponseFormat$Outbound = ResponseFormatText$Outbound | ResponseFormatJSONObject$Outbound | ResponseFormatJSONSchema$Outbound | ResponseFormatTextGrammar$Outbound | ResponseFormatPython$Outbound;
|
|
391
391
|
/** @internal */
|
|
392
|
-
export declare const
|
|
393
|
-
export declare function
|
|
392
|
+
export declare const ResponseFormat$outboundSchema: z.ZodType<ResponseFormat$Outbound, ResponseFormat>;
|
|
393
|
+
export declare function responseFormatToJSON(responseFormat: ResponseFormat): string;
|
|
394
394
|
/** @internal */
|
|
395
|
-
export type
|
|
395
|
+
export type Stop$Outbound = string | Array<string>;
|
|
396
396
|
/** @internal */
|
|
397
|
-
export declare const
|
|
398
|
-
export declare function
|
|
397
|
+
export declare const Stop$outboundSchema: z.ZodType<Stop$Outbound, Stop>;
|
|
398
|
+
export declare function stopToJSON(stop: Stop): string;
|
|
399
399
|
/** @internal */
|
|
400
400
|
export type Debug$Outbound = {
|
|
401
401
|
echo_upstream_body?: boolean | undefined;
|
|
@@ -433,7 +433,7 @@ export type ChatGenerationParams$Outbound = {
|
|
|
433
433
|
} | undefined;
|
|
434
434
|
presence_penalty?: number | null | undefined;
|
|
435
435
|
reasoning?: Reasoning$Outbound | undefined;
|
|
436
|
-
response_format?:
|
|
436
|
+
response_format?: ResponseFormatText$Outbound | ResponseFormatJSONObject$Outbound | ResponseFormatJSONSchema$Outbound | ResponseFormatTextGrammar$Outbound | ResponseFormatPython$Outbound | undefined;
|
|
437
437
|
seed?: number | null | undefined;
|
|
438
438
|
stop?: string | Array<string> | null | undefined;
|
|
439
439
|
stream: boolean;
|
|
@@ -233,41 +233,44 @@ export function reasoningToJSON(reasoning) {
|
|
|
233
233
|
return JSON.stringify(Reasoning$outboundSchema.parse(reasoning));
|
|
234
234
|
}
|
|
235
235
|
/** @internal */
|
|
236
|
-
export const
|
|
236
|
+
export const ResponseFormatPython$outboundSchema = z.object({
|
|
237
237
|
type: z.literal("python"),
|
|
238
238
|
});
|
|
239
|
-
export function
|
|
240
|
-
return JSON.stringify(
|
|
239
|
+
export function responseFormatPythonToJSON(responseFormatPython) {
|
|
240
|
+
return JSON.stringify(ResponseFormatPython$outboundSchema.parse(responseFormatPython));
|
|
241
241
|
}
|
|
242
242
|
/** @internal */
|
|
243
|
-
export const
|
|
243
|
+
export const ResponseFormatJSONObject$outboundSchema = z.object({
|
|
244
244
|
type: z.literal("json_object"),
|
|
245
245
|
});
|
|
246
|
-
export function
|
|
247
|
-
return JSON.stringify(
|
|
246
|
+
export function responseFormatJSONObjectToJSON(responseFormatJSONObject) {
|
|
247
|
+
return JSON.stringify(ResponseFormatJSONObject$outboundSchema.parse(responseFormatJSONObject));
|
|
248
248
|
}
|
|
249
249
|
/** @internal */
|
|
250
|
-
export const
|
|
250
|
+
export const ResponseFormatText$outboundSchema = z.object({
|
|
251
251
|
type: z.literal("text"),
|
|
252
252
|
});
|
|
253
|
-
export function
|
|
254
|
-
return JSON.stringify(
|
|
253
|
+
export function responseFormatTextToJSON(responseFormatText) {
|
|
254
|
+
return JSON.stringify(ResponseFormatText$outboundSchema.parse(responseFormatText));
|
|
255
255
|
}
|
|
256
256
|
/** @internal */
|
|
257
|
-
export const
|
|
258
|
-
z.lazy(() =>
|
|
259
|
-
z.lazy(() =>
|
|
257
|
+
export const ResponseFormat$outboundSchema = z.union([
|
|
258
|
+
z.lazy(() => ResponseFormatText$outboundSchema),
|
|
259
|
+
z.lazy(() => ResponseFormatJSONObject$outboundSchema),
|
|
260
260
|
ResponseFormatJSONSchema$outboundSchema,
|
|
261
261
|
ResponseFormatTextGrammar$outboundSchema,
|
|
262
|
-
z.lazy(() =>
|
|
262
|
+
z.lazy(() => ResponseFormatPython$outboundSchema),
|
|
263
263
|
]);
|
|
264
|
-
export function
|
|
265
|
-
return JSON.stringify(
|
|
264
|
+
export function responseFormatToJSON(responseFormat) {
|
|
265
|
+
return JSON.stringify(ResponseFormat$outboundSchema.parse(responseFormat));
|
|
266
266
|
}
|
|
267
267
|
/** @internal */
|
|
268
|
-
export const
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
export const Stop$outboundSchema = z.union([
|
|
269
|
+
z.string(),
|
|
270
|
+
z.array(z.string()),
|
|
271
|
+
]);
|
|
272
|
+
export function stopToJSON(stop) {
|
|
273
|
+
return JSON.stringify(Stop$outboundSchema.parse(stop));
|
|
271
274
|
}
|
|
272
275
|
/** @internal */
|
|
273
276
|
export const Debug$outboundSchema = z.object({
|
|
@@ -314,11 +317,11 @@ export const ChatGenerationParams$outboundSchema = z.object({
|
|
|
314
317
|
presencePenalty: z.nullable(z.number()).optional(),
|
|
315
318
|
reasoning: z.lazy(() => Reasoning$outboundSchema).optional(),
|
|
316
319
|
responseFormat: z.union([
|
|
317
|
-
z.lazy(() =>
|
|
318
|
-
z.lazy(() =>
|
|
320
|
+
z.lazy(() => ResponseFormatText$outboundSchema),
|
|
321
|
+
z.lazy(() => ResponseFormatJSONObject$outboundSchema),
|
|
319
322
|
ResponseFormatJSONSchema$outboundSchema,
|
|
320
323
|
ResponseFormatTextGrammar$outboundSchema,
|
|
321
|
-
z.lazy(() =>
|
|
324
|
+
z.lazy(() => ResponseFormatPython$outboundSchema),
|
|
322
325
|
]).optional(),
|
|
323
326
|
seed: z.nullable(z.int()).optional(),
|
|
324
327
|
stop: z.nullable(z.union([z.string(), z.array(z.string())])).optional(),
|
package/esm/models/index.d.ts
CHANGED
|
@@ -22,11 +22,6 @@ export * from "./chatstreamingmessagechunk.js";
|
|
|
22
22
|
export * from "./chatstreamingmessagetoolcall.js";
|
|
23
23
|
export * from "./chatstreamingresponsechunk.js";
|
|
24
24
|
export * from "./chatstreamoptions.js";
|
|
25
|
-
export * from "./completionchoice.js";
|
|
26
|
-
export * from "./completioncreateparams.js";
|
|
27
|
-
export * from "./completionlogprobs.js";
|
|
28
|
-
export * from "./completionresponse.js";
|
|
29
|
-
export * from "./completionusage.js";
|
|
30
25
|
export * from "./createchargerequest.js";
|
|
31
26
|
export * from "./datacollection.js";
|
|
32
27
|
export * from "./defaultparameters.js";
|
package/esm/models/index.js
CHANGED
|
@@ -26,11 +26,6 @@ export * from "./chatstreamingmessagechunk.js";
|
|
|
26
26
|
export * from "./chatstreamingmessagetoolcall.js";
|
|
27
27
|
export * from "./chatstreamingresponsechunk.js";
|
|
28
28
|
export * from "./chatstreamoptions.js";
|
|
29
|
-
export * from "./completionchoice.js";
|
|
30
|
-
export * from "./completioncreateparams.js";
|
|
31
|
-
export * from "./completionlogprobs.js";
|
|
32
|
-
export * from "./completionresponse.js";
|
|
33
|
-
export * from "./completionusage.js";
|
|
34
29
|
export * from "./createchargerequest.js";
|
|
35
30
|
export * from "./datacollection.js";
|
|
36
31
|
export * from "./defaultparameters.js";
|
|
@@ -35,6 +35,10 @@ export type Pricing = {
|
|
|
35
35
|
* A value in string format that is a large number
|
|
36
36
|
*/
|
|
37
37
|
audio?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* A value in string format that is a large number
|
|
40
|
+
*/
|
|
41
|
+
audioOutput?: string | undefined;
|
|
38
42
|
/**
|
|
39
43
|
* A value in string format that is a large number
|
|
40
44
|
*/
|
|
@@ -74,6 +78,10 @@ export type PublicEndpointQuantization = OpenEnum<typeof PublicEndpointQuantizat
|
|
|
74
78
|
*/
|
|
75
79
|
export type PublicEndpoint = {
|
|
76
80
|
name: string;
|
|
81
|
+
/**
|
|
82
|
+
* The unique identifier for the model (permaslug)
|
|
83
|
+
*/
|
|
84
|
+
modelId: string;
|
|
77
85
|
modelName: string;
|
|
78
86
|
contextLength: number;
|
|
79
87
|
pricing: Pricing;
|
|
@@ -30,6 +30,7 @@ export const Pricing$inboundSchema = z.object({
|
|
|
30
30
|
image_token: z.string().optional(),
|
|
31
31
|
image_output: z.string().optional(),
|
|
32
32
|
audio: z.string().optional(),
|
|
33
|
+
audio_output: z.string().optional(),
|
|
33
34
|
input_audio_cache: z.string().optional(),
|
|
34
35
|
web_search: z.string().optional(),
|
|
35
36
|
internal_reasoning: z.string().optional(),
|
|
@@ -40,6 +41,7 @@ export const Pricing$inboundSchema = z.object({
|
|
|
40
41
|
return remap$(v, {
|
|
41
42
|
"image_token": "imageToken",
|
|
42
43
|
"image_output": "imageOutput",
|
|
44
|
+
"audio_output": "audioOutput",
|
|
43
45
|
"input_audio_cache": "inputAudioCache",
|
|
44
46
|
"web_search": "webSearch",
|
|
45
47
|
"internal_reasoning": "internalReasoning",
|
|
@@ -55,6 +57,7 @@ export const PublicEndpointQuantization$inboundSchema = openEnums.inboundSchema(
|
|
|
55
57
|
/** @internal */
|
|
56
58
|
export const PublicEndpoint$inboundSchema = z.object({
|
|
57
59
|
name: z.string(),
|
|
60
|
+
model_id: z.string(),
|
|
58
61
|
model_name: z.string(),
|
|
59
62
|
context_length: z.number(),
|
|
60
63
|
pricing: z.lazy(() => Pricing$inboundSchema),
|
|
@@ -71,6 +74,7 @@ export const PublicEndpoint$inboundSchema = z.object({
|
|
|
71
74
|
throughput_last_30m: z.nullable(PercentileStats$inboundSchema),
|
|
72
75
|
}).transform((v) => {
|
|
73
76
|
return remap$(v, {
|
|
77
|
+
"model_id": "modelId",
|
|
74
78
|
"model_name": "modelName",
|
|
75
79
|
"context_length": "contextLength",
|
|
76
80
|
"provider_name": "providerName",
|
|
@@ -33,6 +33,10 @@ export type PublicPricing = {
|
|
|
33
33
|
* A value in string format that is a large number
|
|
34
34
|
*/
|
|
35
35
|
audio?: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* A value in string format that is a large number
|
|
38
|
+
*/
|
|
39
|
+
audioOutput?: string | undefined;
|
|
36
40
|
/**
|
|
37
41
|
* A value in string format that is a large number
|
|
38
42
|
*/
|
|
@@ -15,6 +15,7 @@ export const PublicPricing$inboundSchema = z
|
|
|
15
15
|
image_token: z.string().optional(),
|
|
16
16
|
image_output: z.string().optional(),
|
|
17
17
|
audio: z.string().optional(),
|
|
18
|
+
audio_output: z.string().optional(),
|
|
18
19
|
input_audio_cache: z.string().optional(),
|
|
19
20
|
web_search: z.string().optional(),
|
|
20
21
|
internal_reasoning: z.string().optional(),
|
|
@@ -25,6 +26,7 @@ export const PublicPricing$inboundSchema = z
|
|
|
25
26
|
return remap$(v, {
|
|
26
27
|
"image_token": "imageToken",
|
|
27
28
|
"image_output": "imageOutput",
|
|
29
|
+
"audio_output": "audioOutput",
|
|
28
30
|
"input_audio_cache": "inputAudioCache",
|
|
29
31
|
"web_search": "webSearch",
|
|
30
32
|
"internal_reasoning": "internalReasoning",
|
package/esm/sdk/models.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ export declare class Models extends ClientSDK {
|
|
|
11
11
|
*/
|
|
12
12
|
list(request?: operations.GetModelsRequest | undefined, options?: RequestOptions): Promise<models.ModelsListResponse>;
|
|
13
13
|
/**
|
|
14
|
-
* List models filtered by user provider preferences
|
|
14
|
+
* List models filtered by user provider preferences, privacy settings, and guardrails
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing).
|
|
15
18
|
*/
|
|
16
19
|
listForUser(security: operations.ListModelsUserSecurity, options?: RequestOptions): Promise<models.ModelsListResponse>;
|
|
17
20
|
}
|
package/esm/sdk/models.js
CHANGED
|
@@ -21,7 +21,10 @@ export class Models extends ClientSDK {
|
|
|
21
21
|
return unwrapAsync(modelsList(this, request, options));
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* List models filtered by user provider preferences
|
|
24
|
+
* List models filtered by user provider preferences, privacy settings, and guardrails
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing).
|
|
25
28
|
*/
|
|
26
29
|
async listForUser(security, options) {
|
|
27
30
|
return unwrapAsync(modelsListForUser(this, security, options));
|
package/esm/sdk/sdk.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Analytics } from "./analytics.js";
|
|
|
3
3
|
import { APIKeys } from "./apikeys.js";
|
|
4
4
|
import { Beta } from "./beta.js";
|
|
5
5
|
import { Chat } from "./chat.js";
|
|
6
|
-
import { Completions } from "./completions.js";
|
|
7
6
|
import { Credits } from "./credits.js";
|
|
8
7
|
import { Embeddings } from "./embeddings.js";
|
|
9
8
|
import { Endpoints } from "./endpoints.js";
|
|
@@ -42,8 +41,6 @@ export declare class OpenRouter extends ClientSDK {
|
|
|
42
41
|
get oAuth(): OAuth;
|
|
43
42
|
private _chat?;
|
|
44
43
|
get chat(): Chat;
|
|
45
|
-
private _completions?;
|
|
46
|
-
get completions(): Completions;
|
|
47
44
|
callModel<TTools extends readonly Tool[]>(request: CallModelInput<TTools>, options?: RequestOptions): ModelResult<TTools>;
|
|
48
45
|
}
|
|
49
46
|
//# sourceMappingURL=sdk.d.ts.map
|
package/esm/sdk/sdk.js
CHANGED
|
@@ -7,7 +7,6 @@ import { Analytics } from "./analytics.js";
|
|
|
7
7
|
import { APIKeys } from "./apikeys.js";
|
|
8
8
|
import { Beta } from "./beta.js";
|
|
9
9
|
import { Chat } from "./chat.js";
|
|
10
|
-
import { Completions } from "./completions.js";
|
|
11
10
|
import { Credits } from "./credits.js";
|
|
12
11
|
import { Embeddings } from "./embeddings.js";
|
|
13
12
|
import { Endpoints } from "./endpoints.js";
|
|
@@ -58,9 +57,6 @@ export class OpenRouter extends ClientSDK {
|
|
|
58
57
|
get chat() {
|
|
59
58
|
return (this._chat ?? (this._chat = new Chat(this._options)));
|
|
60
59
|
}
|
|
61
|
-
get completions() {
|
|
62
|
-
return (this._completions ?? (this._completions = new Completions(this._options)));
|
|
63
|
-
}
|
|
64
60
|
// #region sdk-class-body
|
|
65
61
|
callModel(request, options) {
|
|
66
62
|
return callModelFunc(this, request, options);
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "OpenRouter",
|
|
5
5
|
"description": "The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.",
|
|
6
6
|
"keywords": [
|
|
@@ -64,16 +64,16 @@
|
|
|
64
64
|
"type": "git",
|
|
65
65
|
"url": "https://github.com/OpenRouterTeam/typescript-sdk.git"
|
|
66
66
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
"scripts": {
|
|
68
|
+
"lint": "eslint --cache --max-warnings=0 src",
|
|
69
|
+
"build": "tsc",
|
|
70
|
+
"typecheck": "tsc --noEmit",
|
|
71
|
+
"prepublishOnly": "npm run build",
|
|
72
|
+
"postinstall": "node scripts/check-types.js || true",
|
|
73
|
+
"test": "vitest --run --project unit",
|
|
74
|
+
"test:e2e": "vitest --run --project e2e",
|
|
75
|
+
"test:watch": "vitest --watch --project unit"
|
|
76
|
+
},
|
|
77
77
|
"peerDependencies": {},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@eslint/js": "^9.19.0",
|
|
@@ -89,4 +89,4 @@
|
|
|
89
89
|
"zod": "^3.25.0 || ^4.0.0"
|
|
90
90
|
},
|
|
91
91
|
"packageManager": "pnpm@10.22.0"
|
|
92
|
-
}
|
|
92
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { OpenRouterCore } from "../core.js";
|
|
2
|
-
import { RequestOptions } from "../lib/sdks.js";
|
|
3
|
-
import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/httpclienterrors.js";
|
|
4
|
-
import * as errors from "../models/errors/index.js";
|
|
5
|
-
import { OpenRouterError } from "../models/errors/openroutererror.js";
|
|
6
|
-
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
7
|
-
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
8
|
-
import * as models from "../models/index.js";
|
|
9
|
-
import { APIPromise } from "../types/async.js";
|
|
10
|
-
import { Result } from "../types/fp.js";
|
|
11
|
-
/**
|
|
12
|
-
* Create a completion
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes.
|
|
16
|
-
*/
|
|
17
|
-
export declare function completionsGenerate(client: OpenRouterCore, request: models.CompletionCreateParams, options?: RequestOptions): APIPromise<Result<models.CompletionResponse, errors.ChatError | OpenRouterError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
|
|
18
|
-
//# sourceMappingURL=completionsGenerate.d.ts.map
|