@standardagents/openrouter 0.10.0-dev.ffffff
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.txt +48 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +1379 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 FormKit Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
UNLICENSED - DO NOT USE
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the sole
|
|
8
|
+
and exclusive property of FormKit Inc. ("FormKit").
|
|
9
|
+
|
|
10
|
+
USE RESTRICTIONS
|
|
11
|
+
|
|
12
|
+
The Software is UNLICENSED and proprietary. NO PERMISSION is granted to use,
|
|
13
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
the Software, or to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
under any circumstances, without prior written authorization from FormKit Inc.
|
|
16
|
+
|
|
17
|
+
UNAUTHORIZED USE PROHIBITED
|
|
18
|
+
|
|
19
|
+
Any use of this Software without a valid, written license agreement signed by
|
|
20
|
+
authorized officers of FormKit Inc. is strictly prohibited and constitutes
|
|
21
|
+
unauthorized use and infringement of FormKit's intellectual property rights.
|
|
22
|
+
|
|
23
|
+
LICENSING INQUIRIES
|
|
24
|
+
|
|
25
|
+
Organizations interested in licensing this Software should contact:
|
|
26
|
+
enterprise@formkit.com
|
|
27
|
+
|
|
28
|
+
A written license agreement must be executed before any use of this Software
|
|
29
|
+
is authorized.
|
|
30
|
+
|
|
31
|
+
NO WARRANTY
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
36
|
+
FORMKIT INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
37
|
+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
38
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
|
|
40
|
+
GOVERNING LAW
|
|
41
|
+
|
|
42
|
+
This license shall be governed by and construed in accordance with the laws
|
|
43
|
+
of the jurisdiction in which FormKit Inc. is incorporated, without regard to
|
|
44
|
+
its conflict of law provisions.
|
|
45
|
+
|
|
46
|
+
FormKit Inc.
|
|
47
|
+
https://formkit.com
|
|
48
|
+
enterprise@formkit.com
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { LLMProviderInterface, ProviderFactoryConfig, ModelCapabilities, ProviderModelInfo, ProviderRequest, ProviderResponse, ProviderStreamChunk, ResponseSummary, InspectedRequest, ProviderFactoryWithOptions } from '@standardagents/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenRouter provider options schema.
|
|
6
|
+
*
|
|
7
|
+
* Defines typed providerOptions for OpenRouter models, providing
|
|
8
|
+
* TypeScript autocompletion and runtime validation.
|
|
9
|
+
*
|
|
10
|
+
* @see https://openrouter.ai/docs/guides/routing/provider-selection
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* OpenRouter provider options schema.
|
|
16
|
+
*
|
|
17
|
+
* Routing options are nested under the `provider` key to match
|
|
18
|
+
* OpenRouter's API structure.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* providerOptions: {
|
|
23
|
+
* provider: {
|
|
24
|
+
* zdr: true,
|
|
25
|
+
* max_price: { prompt: 1, completion: 5 },
|
|
26
|
+
* order: ['anthropic', 'openai'],
|
|
27
|
+
* },
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare const openrouterProviderOptions: z.ZodObject<{
|
|
32
|
+
provider: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
order: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
34
|
+
allow_fallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
require_parameters: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
data_collection: z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
allow: "allow";
|
|
38
|
+
deny: "deny";
|
|
39
|
+
}>>;
|
|
40
|
+
zdr: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
only: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
42
|
+
ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
43
|
+
sort: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
44
|
+
price: "price";
|
|
45
|
+
throughput: "throughput";
|
|
46
|
+
latency: "latency";
|
|
47
|
+
}>, z.ZodObject<{
|
|
48
|
+
by: z.ZodEnum<{
|
|
49
|
+
price: "price";
|
|
50
|
+
throughput: "throughput";
|
|
51
|
+
latency: "latency";
|
|
52
|
+
}>;
|
|
53
|
+
partition: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
model: "model";
|
|
55
|
+
none: "none";
|
|
56
|
+
}>>;
|
|
57
|
+
}, z.core.$strip>]>>;
|
|
58
|
+
max_price: z.ZodOptional<z.ZodObject<{
|
|
59
|
+
prompt: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
completion: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
request: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
image: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
quantizations: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
65
|
+
unknown: "unknown";
|
|
66
|
+
int4: "int4";
|
|
67
|
+
int8: "int8";
|
|
68
|
+
fp4: "fp4";
|
|
69
|
+
fp6: "fp6";
|
|
70
|
+
fp8: "fp8";
|
|
71
|
+
fp16: "fp16";
|
|
72
|
+
bf16: "bf16";
|
|
73
|
+
fp32: "fp32";
|
|
74
|
+
}>>>;
|
|
75
|
+
preferred_min_throughput: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
76
|
+
p50: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
p75: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
p90: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
p99: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
}, z.core.$strip>]>>;
|
|
81
|
+
preferred_max_latency: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
|
|
82
|
+
p50: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
p75: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
p90: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
p99: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
}, z.core.$strip>]>>;
|
|
87
|
+
enforce_distillable_text: z.ZodOptional<z.ZodBoolean>;
|
|
88
|
+
}, z.core.$loose>>;
|
|
89
|
+
}, z.core.$loose>;
|
|
90
|
+
/**
|
|
91
|
+
* TypeScript type for OpenRouter provider options.
|
|
92
|
+
* Inferred from the Zod schema for type-safe usage.
|
|
93
|
+
*/
|
|
94
|
+
type OpenRouterProviderOptions = z.infer<typeof openrouterProviderOptions>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Extended provider config for OpenRouter
|
|
98
|
+
*/
|
|
99
|
+
interface OpenRouterConfig extends ProviderFactoryConfig {
|
|
100
|
+
/** List of providers to route to (e.g., ['openai', 'anthropic']) */
|
|
101
|
+
providers?: string[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* OpenRouter provider implementation for Standard Agents
|
|
105
|
+
*
|
|
106
|
+
* Uses the official @openrouter/sdk Responses API for API calls.
|
|
107
|
+
* OpenRouter is a multi-provider gateway that routes requests to various LLM providers.
|
|
108
|
+
*/
|
|
109
|
+
declare class OpenRouterProvider implements LLMProviderInterface {
|
|
110
|
+
readonly name = "openrouter";
|
|
111
|
+
readonly specificationVersion: "1";
|
|
112
|
+
private client;
|
|
113
|
+
private config;
|
|
114
|
+
constructor(config: OpenRouterConfig);
|
|
115
|
+
private getClient;
|
|
116
|
+
supportsModel(_modelId: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Get the icon for a model as a data URI.
|
|
119
|
+
* Extracts the AI lab/organization from the model ID prefix and returns
|
|
120
|
+
* the corresponding SVG icon as a data URI.
|
|
121
|
+
* For example, 'anthropic/claude-3-opus' returns the Anthropic icon.
|
|
122
|
+
* Falls back to the OpenRouter icon for unknown labs.
|
|
123
|
+
*/
|
|
124
|
+
getIcon(modelId?: string): string;
|
|
125
|
+
/** Cache for model capabilities to avoid repeated API calls */
|
|
126
|
+
private static modelsCache;
|
|
127
|
+
private static modelsCacheTime;
|
|
128
|
+
private static readonly CACHE_TTL;
|
|
129
|
+
/**
|
|
130
|
+
* Get capabilities for a specific model.
|
|
131
|
+
* Fetches from OpenRouter's models API which provides rich metadata.
|
|
132
|
+
*/
|
|
133
|
+
getModelCapabilities(modelId: string): Promise<ModelCapabilities | null>;
|
|
134
|
+
private fetchModelsWithCache;
|
|
135
|
+
private mapOpenRouterCapabilities;
|
|
136
|
+
/**
|
|
137
|
+
* Get list of available models from OpenRouter.
|
|
138
|
+
* Fetches from OpenRouter's public models API with caching.
|
|
139
|
+
*
|
|
140
|
+
* @param filter - Optional search string to filter models by name/id
|
|
141
|
+
*/
|
|
142
|
+
getModels(filter?: string): Promise<ProviderModelInfo[]>;
|
|
143
|
+
private mapToProviderModelInfo;
|
|
144
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
145
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
146
|
+
/**
|
|
147
|
+
* Fetch additional metadata about a completed response.
|
|
148
|
+
* Called asynchronously after the response is received.
|
|
149
|
+
*
|
|
150
|
+
* Uses OpenRouter's /generation endpoint to fetch accurate provider info,
|
|
151
|
+
* token counts, and cost data.
|
|
152
|
+
*/
|
|
153
|
+
getResponseMetadata(summary: ResponseSummary, signal?: AbortSignal): Promise<Record<string, unknown> | null>;
|
|
154
|
+
private toProviderError;
|
|
155
|
+
/**
|
|
156
|
+
* Transform a ProviderRequest to OpenRouter Responses API format for inspection.
|
|
157
|
+
* Returns the exact request body that would be sent to OpenRouter, with base64 data truncated.
|
|
158
|
+
*/
|
|
159
|
+
inspectRequest(request: ProviderRequest): Promise<InspectedRequest>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Generation metadata returned by OpenRouter's /api/v1/generation endpoint.
|
|
164
|
+
* Contains accurate usage, cost, and provider information.
|
|
165
|
+
*/
|
|
166
|
+
interface GenerationMetadata {
|
|
167
|
+
/** Unique generation ID */
|
|
168
|
+
id: string;
|
|
169
|
+
/** Total cost in USD */
|
|
170
|
+
totalCost: number;
|
|
171
|
+
/** Input/prompt tokens */
|
|
172
|
+
promptTokens: number;
|
|
173
|
+
/** Output/completion tokens */
|
|
174
|
+
completionTokens: number;
|
|
175
|
+
/** Native input tokens (provider-specific) */
|
|
176
|
+
nativePromptTokens?: number;
|
|
177
|
+
/** Native output tokens (provider-specific) */
|
|
178
|
+
nativeCompletionTokens?: number;
|
|
179
|
+
/** Actual provider that served the request */
|
|
180
|
+
providerName: string;
|
|
181
|
+
/** Request latency in milliseconds */
|
|
182
|
+
latency?: number;
|
|
183
|
+
/** Model used */
|
|
184
|
+
model?: string;
|
|
185
|
+
/** Finish reason */
|
|
186
|
+
finishReason?: string;
|
|
187
|
+
/** Created timestamp */
|
|
188
|
+
createdAt?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Fetch generation metadata from OpenRouter after a stream completes.
|
|
192
|
+
*
|
|
193
|
+
* This is the recommended way to get accurate token usage, cost, and provider
|
|
194
|
+
* information. Should be called with the responseId from the finish chunk.
|
|
195
|
+
*
|
|
196
|
+
* @param apiKey - OpenRouter API key
|
|
197
|
+
* @param generationId - The response/generation ID from the stream finish chunk
|
|
198
|
+
* @param baseUrl - Optional base URL (defaults to https://openrouter.ai/api/v1)
|
|
199
|
+
* @param signal - Optional abort signal for cancellation
|
|
200
|
+
* @returns Generation metadata or null if not available
|
|
201
|
+
*/
|
|
202
|
+
declare function fetchGenerationMetadata(apiKey: string, generationId: string, baseUrl?: string, signal?: AbortSignal): Promise<GenerationMetadata | null>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* OpenRouter provider factory for Standard Agents
|
|
206
|
+
*
|
|
207
|
+
* OpenRouter is a multi-provider gateway that routes requests to various LLM providers.
|
|
208
|
+
* Includes typed providerOptions for routing configuration.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* import { defineModel } from '@standardagents/builder';
|
|
213
|
+
* import { openrouter } from '@standardagents/openrouter';
|
|
214
|
+
*
|
|
215
|
+
* export default defineModel({
|
|
216
|
+
* name: 'claude-3-opus',
|
|
217
|
+
* provider: openrouter,
|
|
218
|
+
* model: 'anthropic/claude-3-opus',
|
|
219
|
+
* inputPrice: 15,
|
|
220
|
+
* outputPrice: 75,
|
|
221
|
+
* capabilities: {
|
|
222
|
+
* supportsImages: true,
|
|
223
|
+
* supportsToolCalls: true,
|
|
224
|
+
* maxContextTokens: 200000,
|
|
225
|
+
* },
|
|
226
|
+
* providerOptions: {
|
|
227
|
+
* provider: {
|
|
228
|
+
* zdr: true,
|
|
229
|
+
* only: ['anthropic'],
|
|
230
|
+
* },
|
|
231
|
+
* },
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare const openrouter: ProviderFactoryWithOptions<typeof openrouterProviderOptions>;
|
|
236
|
+
|
|
237
|
+
export { type GenerationMetadata, type OpenRouterConfig, OpenRouterProvider, type OpenRouterProviderOptions, fetchGenerationMetadata, openrouter, openrouterProviderOptions };
|