@starci/ai-router 0.2.1 → 0.3.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.
@@ -0,0 +1,527 @@
1
+ import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import { createServer } from "node:http";
3
+ import { AiRouterError } from "../errors.js";
4
+ import { dayOf, KeyAdmin, KeyAdminError } from "./keys.js";
5
+ /** A refusal the gateway answers as an OpenAI error object. */
6
+ class GatewayError extends Error {
7
+ status;
8
+ type;
9
+ code;
10
+ retryAfter;
11
+ constructor(status, code, message, options = {}) {
12
+ super(message);
13
+ this.status = status;
14
+ this.code = code;
15
+ this.type = options.type ?? (status === 401 ? "authentication_error" : status === 403 ? "permission_error" : status === 429 ? "rate_limit_error" : status >= 500 ? "api_error" : "invalid_request_error");
16
+ this.retryAfter = options.retryAfter;
17
+ }
18
+ /** The outcome a usage row records for this refusal. */
19
+ get outcome() {
20
+ return `rejected:${this.code}`;
21
+ }
22
+ }
23
+ const DEFAULT_MAX_BODY = 4 * 1024 * 1024;
24
+ const MINUTE = 60_000;
25
+ function isRecord(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27
+ }
28
+ function errorBody(error) {
29
+ return { error: { message: error.message, type: error.type, param: null, code: error.code } };
30
+ }
31
+ function send(response, status, body, headers = {}) {
32
+ const text = JSON.stringify(body);
33
+ response.writeHead(status, { "content-type": "application/json", "content-length": String(Buffer.byteLength(text)), ...headers });
34
+ response.end(text);
35
+ }
36
+ function sendError(response, error, headers = {}) {
37
+ send(response, error.status, errorBody(error), error.retryAfter === undefined ? headers : { ...headers, "retry-after": String(error.retryAfter) });
38
+ }
39
+ function secondsUntil(at, now) {
40
+ return Math.max(1, Math.ceil((at - now) / 1000));
41
+ }
42
+ /** Maps a router failure to the status a client can act on; the message is the router's, which never holds a key value. */
43
+ function fromRouterError(error, now) {
44
+ if (!(error instanceof AiRouterError))
45
+ return new GatewayError(502, "upstream_error", "the pool failed to answer");
46
+ const retry = error.retryAt === undefined ? {} : { retryAfter: secondsUntil(error.retryAt, now) };
47
+ switch (error.errorClass) {
48
+ case "invalid_request": {
49
+ const status = error.status !== undefined && error.status >= 400 && error.status < 500 && error.status !== 401 && error.status !== 403 && error.status !== 429 ? error.status : 400;
50
+ return new GatewayError(status, "upstream_invalid_request", error.message);
51
+ }
52
+ case "config":
53
+ return new GatewayError(400, "invalid_request", error.message);
54
+ case "no_candidate":
55
+ return new GatewayError(503, "pool_unavailable", `no model of the pool can serve this request: ${error.message}`, retry);
56
+ case "rate_limit":
57
+ return new GatewayError(503, "pool_rate_limited", `every key of the pool is rate limited: ${error.message}`, retry);
58
+ case "deadline":
59
+ return new GatewayError(504, "pool_timeout", error.message);
60
+ case "cancelled":
61
+ return new GatewayError(499, "cancelled", error.message);
62
+ case "auth":
63
+ return new GatewayError(502, "pool_auth_failed", "no upstream key of the pool was accepted");
64
+ case "transient":
65
+ case "timeout":
66
+ case "network":
67
+ case "stream":
68
+ return new GatewayError(502, "upstream_error", `the pool failed to answer: ${error.message}`, retry);
69
+ }
70
+ }
71
+ function bearer(request) {
72
+ const header = request.headers.authorization;
73
+ if (header === undefined)
74
+ return undefined;
75
+ const match = /^Bearer\s+(\S+)\s*$/i.exec(header);
76
+ return match?.[1];
77
+ }
78
+ function sameSecret(given, expected) {
79
+ const a = createHash("sha256").update(given).digest();
80
+ const b = createHash("sha256").update(expected).digest();
81
+ return timingSafeEqual(a, b);
82
+ }
83
+ async function readBody(request, limit) {
84
+ // A framework that parsed the body already (express.json, a Nest controller) leaves it on the request.
85
+ const parsed = request.body;
86
+ if (parsed !== undefined)
87
+ return typeof parsed === "string" || Buffer.isBuffer(parsed) ? parseJson(parsed.toString()) : parsed;
88
+ const chunks = [];
89
+ let size = 0;
90
+ for await (const chunk of request) {
91
+ size += chunk.length;
92
+ if (size > limit)
93
+ throw new GatewayError(413, "request_too_large", `the request body is larger than ${String(limit)} bytes`);
94
+ chunks.push(chunk);
95
+ }
96
+ return parseJson(Buffer.concat(chunks).toString("utf8"));
97
+ }
98
+ function parseJson(text) {
99
+ try {
100
+ return JSON.parse(text);
101
+ }
102
+ catch {
103
+ throw new GatewayError(400, "invalid_json", "the request body is not JSON");
104
+ }
105
+ }
106
+ function allows(list, name) {
107
+ return list.includes("*") || list.includes(name);
108
+ }
109
+ function modelNamed(catalog, name) {
110
+ return catalog.models.find((model) => model.id === name || model.aliases.includes(name));
111
+ }
112
+ function modelAllowed(key, model) {
113
+ return [model.id, ...model.aliases].some((name) => allows(key.models, name));
114
+ }
115
+ /** Writes and waits for the socket to take it, so a slow client holds the upstream stream back. */
116
+ function write(response, text) {
117
+ if (response.write(text))
118
+ return Promise.resolve();
119
+ return new Promise((resolve) => {
120
+ const done = () => {
121
+ response.off("drain", done);
122
+ response.off("close", done);
123
+ resolve();
124
+ };
125
+ response.on("drain", done);
126
+ response.on("close", done);
127
+ });
128
+ }
129
+ /** Creates the gateway over a router; nothing listens until `listen`. */
130
+ export function createGateway(router, options) {
131
+ const clock = options.clock ?? Date.now;
132
+ const catalog = router.catalog();
133
+ const admin = new KeyAdmin(options.keys, { catalog, clock });
134
+ const maxBody = options.maxBodyBytes ?? DEFAULT_MAX_BODY;
135
+ const servers = new Set();
136
+ // A stream's usage reaches the gateway through the attempt event of its request id.
137
+ const captured = new Map();
138
+ const unsubscribe = router.on("attempt", (event) => {
139
+ const slot = captured.get(event.requestId);
140
+ if (slot === undefined || event.outcome !== "success")
141
+ return;
142
+ if (event.usage !== undefined)
143
+ slot.usage = event.usage;
144
+ if (event.cost !== undefined)
145
+ slot.cost = event.cost;
146
+ });
147
+ function report(error) {
148
+ try {
149
+ options.onError?.(error);
150
+ }
151
+ catch {
152
+ // The observer's failure is the observer's.
153
+ }
154
+ }
155
+ async function record(key, started, outcome, usage, cost) {
156
+ try {
157
+ await options.keys.record(key.id, dayOf(started), {
158
+ outcome,
159
+ promptTokens: usage?.prompt_tokens ?? 0,
160
+ completionTokens: usage?.completion_tokens ?? 0,
161
+ cost: cost ?? 0,
162
+ latencyMs: clock() - started,
163
+ });
164
+ }
165
+ catch (error) {
166
+ report(error);
167
+ }
168
+ }
169
+ async function authenticate(request) {
170
+ const secret = bearer(request);
171
+ if (secret === undefined)
172
+ throw new GatewayError(401, "missing_api_key", "send the key as Authorization: Bearer sk-starci-...");
173
+ const key = await admin.authenticate(secret);
174
+ if (key === undefined)
175
+ throw new GatewayError(401, "invalid_api_key", "the API key is not valid");
176
+ if (key.revokedAt !== null)
177
+ throw new GatewayError(401, "invalid_api_key", "the API key was revoked");
178
+ if (!key.enabled)
179
+ throw new GatewayError(401, "invalid_api_key", "the API key is disabled");
180
+ return key;
181
+ }
182
+ function target(key, name, operation) {
183
+ if (typeof name !== "string" || name === "")
184
+ throw new GatewayError(400, "missing_model", "model is required: a profile name or a model id");
185
+ const pinned = key.allowFallback ? {} : { allowFallback: false };
186
+ if (catalog.profiles.some((profile) => profile.name === name)) {
187
+ if (!allows(key.profiles, name))
188
+ throw new GatewayError(403, "model_not_allowed", `this key may not call profile "${name}"`);
189
+ return { options: { profile: name, ...(key.allowFallback ? {} : { policy: pinned }) }, dropModel: true };
190
+ }
191
+ const model = modelNamed(catalog, name);
192
+ if (model === undefined)
193
+ throw new GatewayError(404, "model_not_found", `the model "${name}" does not exist`);
194
+ if (!modelAllowed(key, model))
195
+ throw new GatewayError(403, "model_not_allowed", `this key may not call model "${name}"`);
196
+ const needs = operation === "embeddings" ? "embeddings" : "chat";
197
+ if (!model.capabilities.includes(needs))
198
+ throw new GatewayError(400, "model_not_supported", `the model "${name}" does not serve ${operation}`);
199
+ // A direct call falls back only to the pool's default fallbacks this key may call itself.
200
+ const fallbacks = catalog.defaults.fallbacks.filter((fallback) => {
201
+ const entry = modelNamed(catalog, fallback);
202
+ return entry !== undefined && entry.id !== model.id && modelAllowed(key, entry);
203
+ });
204
+ return { options: { policy: { model: name, fallbacks, ...pinned } }, dropModel: false };
205
+ }
206
+ async function admit(key, now) {
207
+ const quota = key.quota;
208
+ if (quota.tokensPerDay !== undefined || quota.costPerDay !== undefined || quota.costPerMonth !== undefined) {
209
+ const today = dayOf(now);
210
+ const rows = await options.keys.usage(key.id, `${today.slice(0, 8)}01`, today);
211
+ const day = rows.find((row) => row.day === today);
212
+ const date = new Date(now);
213
+ const midnight = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + 1);
214
+ if (quota.tokensPerDay !== undefined && (day?.promptTokens ?? 0) + (day?.completionTokens ?? 0) >= quota.tokensPerDay) {
215
+ throw new GatewayError(429, "tokens_per_day_exceeded", `this key used its ${String(quota.tokensPerDay)} tokens for today (UTC)`, { retryAfter: secondsUntil(midnight, now) });
216
+ }
217
+ if (quota.costPerDay !== undefined && (day?.cost ?? 0) >= quota.costPerDay) {
218
+ throw new GatewayError(429, "cost_per_day_exceeded", `this key spent its ${String(quota.costPerDay)} for today (UTC)`, { retryAfter: secondsUntil(midnight, now) });
219
+ }
220
+ const month = rows.reduce((sum, row) => sum + row.cost, 0);
221
+ if (quota.costPerMonth !== undefined && month >= quota.costPerMonth) {
222
+ const next = Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);
223
+ throw new GatewayError(429, "cost_per_month_exceeded", `this key spent its ${String(quota.costPerMonth)} for this month (UTC)`, { retryAfter: secondsUntil(next, now) });
224
+ }
225
+ }
226
+ if (quota.requestsPerMinute !== undefined) {
227
+ const minute = Math.floor(now / MINUTE);
228
+ const count = await options.keys.hit(key.id, minute);
229
+ if (count > quota.requestsPerMinute) {
230
+ throw new GatewayError(429, "requests_per_minute_exceeded", `this key is limited to ${String(quota.requestsPerMinute)} requests a minute`, { retryAfter: secondsUntil((minute + 1) * MINUTE, now) });
231
+ }
232
+ }
233
+ }
234
+ /** Reads the body and applies the key's bindings and quotas; a refusal is recorded against the key. */
235
+ async function prepare(key, request, operation) {
236
+ const started = clock();
237
+ try {
238
+ const body = await readBody(request, maxBody);
239
+ if (!isRecord(body))
240
+ throw new GatewayError(400, "invalid_request", "the request body must be a JSON object");
241
+ if (operation === "chat" && !Array.isArray(body.messages))
242
+ throw new GatewayError(400, "invalid_request", "messages is required");
243
+ if (operation === "embeddings" && typeof body.input !== "string" && !Array.isArray(body.input))
244
+ throw new GatewayError(400, "invalid_request", "input is required");
245
+ const resolved = target(key, body.model, operation);
246
+ await admit(key, started);
247
+ return { key, body, target: resolved, started };
248
+ }
249
+ catch (error) {
250
+ if (error instanceof GatewayError)
251
+ await record(key, started, error.outcome, undefined, undefined);
252
+ throw error;
253
+ }
254
+ }
255
+ function callBody(body, routed) {
256
+ const out = { ...body };
257
+ delete out.stream;
258
+ if (routed.dropModel)
259
+ delete out.model;
260
+ return out;
261
+ }
262
+ function controllerFor(response) {
263
+ const controller = new AbortController();
264
+ response.on("close", () => {
265
+ if (!response.writableFinished)
266
+ controller.abort();
267
+ });
268
+ return controller;
269
+ }
270
+ async function unary(response, operation, { key, body, target: routed, started }) {
271
+ const requestId = randomUUID();
272
+ const headers = { "x-request-id": requestId };
273
+ const options = { ...routed.options, requestId, signal: controllerFor(response).signal };
274
+ try {
275
+ const result = operation === "chat" ? await router.chat(callBody(body, routed), options) : await router.embeddings(callBody(body, routed), options);
276
+ const { routing, ...answer } = result;
277
+ send(response, 200, answer, { ...headers, "x-ai-router-model": routing.model, "x-ai-router-attempts": String(routing.attempts) });
278
+ await record(key, started, "success", result.usage, routing.cost);
279
+ }
280
+ catch (error) {
281
+ const refusal = fromRouterError(error, clock());
282
+ await record(key, started, `error:${error instanceof AiRouterError ? error.errorClass : "unknown"}`, undefined, undefined);
283
+ sendError(response, refusal, headers);
284
+ }
285
+ }
286
+ async function stream(response, { key, body, target: routed, started }) {
287
+ const requestId = randomUUID();
288
+ const headers = { "x-request-id": requestId };
289
+ const controller = controllerFor(response);
290
+ // Usage is always asked of the provider, for the key's accounting; the client gets the usage chunk only if it asked.
291
+ const asked = isRecord(body.stream_options) ? body.stream_options : {};
292
+ const wantsUsage = asked.include_usage === true;
293
+ const call = { ...callBody(body, routed), stream_options: { ...asked, include_usage: true } };
294
+ const slot = {};
295
+ captured.set(requestId, slot);
296
+ let outcome = "success";
297
+ let iterator;
298
+ try {
299
+ iterator = router.stream(call, { ...routed.options, requestId, signal: controller.signal })[Symbol.asyncIterator]();
300
+ // Nothing is sent before the first chunk, so a pool failure before the first token is an ordinary error response.
301
+ let next = await iterator.next();
302
+ response.writeHead(200, { "content-type": "text/event-stream; charset=utf-8", "cache-control": "no-cache", connection: "keep-alive", "x-accel-buffering": "no", ...headers });
303
+ try {
304
+ while (next.done !== true) {
305
+ const chunk = next.value;
306
+ if (wantsUsage || chunk.usage === undefined || chunk.usage === null)
307
+ await write(response, `data: ${JSON.stringify(chunk)}\n\n`);
308
+ else if (chunk.choices.length > 0) {
309
+ const rest = { ...chunk };
310
+ delete rest.usage;
311
+ await write(response, `data: ${JSON.stringify(rest)}\n\n`);
312
+ }
313
+ if (response.destroyed) {
314
+ outcome = "cancelled";
315
+ break;
316
+ }
317
+ next = await iterator.next();
318
+ }
319
+ if (outcome === "success")
320
+ response.end("data: [DONE]\n\n");
321
+ }
322
+ catch (error) {
323
+ // After the first token the status is sent; the failure goes down the stream as an OpenAI error object.
324
+ outcome = `error:${error instanceof AiRouterError ? error.errorClass : "unknown"}`;
325
+ if (!response.destroyed)
326
+ response.end(`data: ${JSON.stringify(errorBody(fromRouterError(error, clock())))}\n\n`);
327
+ }
328
+ }
329
+ catch (error) {
330
+ outcome = `error:${error instanceof AiRouterError ? error.errorClass : "unknown"}`;
331
+ sendError(response, fromRouterError(error, clock()), headers);
332
+ }
333
+ finally {
334
+ await iterator?.return?.();
335
+ captured.delete(requestId);
336
+ await record(key, started, outcome, slot.usage, slot.cost);
337
+ }
338
+ }
339
+ function listed(key) {
340
+ const out = new Map();
341
+ for (const profile of catalog.profiles) {
342
+ if (allows(key.profiles, profile.name))
343
+ out.set(profile.name, { id: profile.name, object: "model", created: 0, owned_by: "profile" });
344
+ }
345
+ for (const model of catalog.models) {
346
+ if (!modelAllowed(key, model))
347
+ continue;
348
+ for (const name of [model.id, ...model.aliases]) {
349
+ if (!out.has(name))
350
+ out.set(name, { id: name, object: "model", created: 0, owned_by: model.providers.join(",") });
351
+ }
352
+ }
353
+ return [...out.values()];
354
+ }
355
+ async function models(request, response, id) {
356
+ const key = await authenticate(request);
357
+ const data = listed(key);
358
+ if (id === null) {
359
+ send(response, 200, { object: "list", data });
360
+ return;
361
+ }
362
+ const found = data.find((entry) => entry.id === id);
363
+ if (found === undefined)
364
+ throw new GatewayError(404, "model_not_found", `the model "${id}" does not exist`);
365
+ send(response, 200, found);
366
+ }
367
+ async function isAdmin(request) {
368
+ const token = await options.adminToken?.();
369
+ if (token === undefined || token.trim() === "")
370
+ return null;
371
+ const given = bearer(request);
372
+ return given !== undefined && sameSecret(given, token.trim());
373
+ }
374
+ async function health(request, response) {
375
+ const snapshot = await router.health();
376
+ const up = snapshot.providers.some((provider) => provider.breaker !== "open" && provider.keys.some((key) => key.breaker !== "open" && !key.disabled));
377
+ const body = { status: up ? "ok" : "degraded" };
378
+ // The pool's detail (provider ids, key aliases, breakers) is the operator's: it needs the admin token.
379
+ send(response, 200, (await isAdmin(request)) === true ? { ...body, pool: snapshot } : body);
380
+ }
381
+ function adminFailure(error) {
382
+ if (!(error instanceof KeyAdminError))
383
+ throw error;
384
+ if (error.code === "not_found")
385
+ return new GatewayError(404, "key_not_found", error.message);
386
+ if (error.code === "revoked")
387
+ return new GatewayError(409, "key_revoked", error.message);
388
+ return new GatewayError(400, "invalid_key_spec", error.message);
389
+ }
390
+ async function adminApi(request, response, path, url) {
391
+ const allowed = await isAdmin(request);
392
+ if (allowed === null)
393
+ throw new GatewayError(403, "admin_disabled", "the admin API is off: no admin token is configured");
394
+ if (!allowed)
395
+ throw new GatewayError(401, "invalid_admin_token", "send the admin token as Authorization: Bearer <token>");
396
+ const method = request.method ?? "GET";
397
+ const parts = path.split("/").slice(3);
398
+ try {
399
+ if (parts.length === 0) {
400
+ if (method === "GET") {
401
+ send(response, 200, { object: "list", data: await admin.list() });
402
+ return;
403
+ }
404
+ if (method === "POST") {
405
+ send(response, 201, await admin.create((await readBody(request, maxBody))));
406
+ return;
407
+ }
408
+ }
409
+ const [id, action] = parts;
410
+ if (id !== undefined && parts.length === 1) {
411
+ if (method === "GET") {
412
+ send(response, 200, await admin.get(id));
413
+ return;
414
+ }
415
+ if (method === "PATCH") {
416
+ const patch = await readBody(request, maxBody);
417
+ if (!isRecord(patch))
418
+ throw new GatewayError(400, "invalid_key_spec", "the update must be a JSON object");
419
+ send(response, 200, await admin.update(id, patch));
420
+ return;
421
+ }
422
+ }
423
+ if (id !== undefined && parts.length === 2) {
424
+ if (action === "revoke" && method === "POST") {
425
+ send(response, 200, await admin.revoke(id));
426
+ return;
427
+ }
428
+ if (action === "rotate" && method === "POST") {
429
+ send(response, 200, await admin.rotate(id));
430
+ return;
431
+ }
432
+ if (action === "usage" && method === "GET") {
433
+ const from = url.searchParams.get("from");
434
+ const to = url.searchParams.get("to");
435
+ send(response, 200, await admin.usage(id, { ...(from === null ? {} : { from }), ...(to === null ? {} : { to }) }));
436
+ return;
437
+ }
438
+ }
439
+ }
440
+ catch (error) {
441
+ throw error instanceof GatewayError ? error : adminFailure(error);
442
+ }
443
+ throw new GatewayError(404, "not_found", `no admin route ${method} ${path}`);
444
+ }
445
+ async function route(request, response) {
446
+ const url = new URL(request.url ?? "/", "http://gateway.local");
447
+ const path = url.pathname.replace(/\/+$/, "") || "/";
448
+ const method = request.method ?? "GET";
449
+ const only = (wanted) => {
450
+ if (method !== wanted)
451
+ throw new GatewayError(405, "method_not_allowed", `${path} answers ${wanted} only`);
452
+ };
453
+ if (path === "/health") {
454
+ only("GET");
455
+ await health(request, response);
456
+ return;
457
+ }
458
+ if (path === "/admin/keys" || path.startsWith("/admin/keys/")) {
459
+ await adminApi(request, response, path, url);
460
+ return;
461
+ }
462
+ if (path === "/v1/models" || path.startsWith("/v1/models/")) {
463
+ only("GET");
464
+ await models(request, response, path === "/v1/models" ? null : decodeURIComponent(path.slice("/v1/models/".length)));
465
+ return;
466
+ }
467
+ if (path === "/v1/chat/completions" || path === "/v1/embeddings") {
468
+ only("POST");
469
+ const operation = path === "/v1/embeddings" ? "embeddings" : "chat";
470
+ const prepared = await prepare(await authenticate(request), request, operation);
471
+ if (operation === "chat" && prepared.body.stream === true)
472
+ await stream(response, prepared);
473
+ else
474
+ await unary(response, operation, prepared);
475
+ return;
476
+ }
477
+ throw new GatewayError(404, "not_found", `no route ${method} ${path}`);
478
+ }
479
+ async function handle(request, response) {
480
+ try {
481
+ await route(request, response);
482
+ }
483
+ catch (error) {
484
+ if (response.headersSent) {
485
+ response.destroy();
486
+ report(error);
487
+ return;
488
+ }
489
+ if (error instanceof GatewayError)
490
+ sendError(response, error);
491
+ else {
492
+ report(error);
493
+ sendError(response, new GatewayError(500, "internal_error", "the gateway failed"));
494
+ }
495
+ }
496
+ }
497
+ return {
498
+ admin,
499
+ handle,
500
+ async listen(port, host = "127.0.0.1") {
501
+ const server = createServer((request, response) => {
502
+ void handle(request, response);
503
+ });
504
+ servers.add(server);
505
+ await new Promise((resolve, reject) => {
506
+ server.once("error", reject);
507
+ server.listen(port, host, () => {
508
+ server.off("error", reject);
509
+ resolve();
510
+ });
511
+ });
512
+ const address = server.address();
513
+ const shown = address.family === "IPv6" ? `[${address.address}]` : address.address;
514
+ return { port: address.port, host: address.address, url: `http://${shown}:${String(address.port)}` };
515
+ },
516
+ async close() {
517
+ unsubscribe();
518
+ await Promise.all([...servers].map((server) => new Promise((resolve) => {
519
+ server.close(() => {
520
+ resolve();
521
+ });
522
+ server.closeAllConnections();
523
+ })));
524
+ servers.clear();
525
+ },
526
+ };
527
+ }
@@ -0,0 +1,14 @@
1
+ export { AiRouterError } from "../errors.js";
2
+ export type { AttemptFailure } from "../errors.js";
3
+ export { createRouter } from "../router.js";
4
+ export type { HealthRecord, StateStore } from "../store.js";
5
+ export type * from "../types.js";
6
+ export { loadGatewayConfig, parseGatewayConfig } from "./config-file.js";
7
+ export type { GatewayFileConfig, GatewaySettings, KeyStoreConfig, SecretRef } from "./config-file.js";
8
+ export { createGateway } from "./gateway.js";
9
+ export type { AiRouterGateway, GatewayOptions } from "./gateway.js";
10
+ export { KeyAdmin, KeyAdminError, MemoryKeyStore } from "./keys.js";
11
+ export type { IssuedKey, KeyPatch, KeyQuota, KeySpec, KeyStore, KeyUsage, StoredKey, UsageDelta, UsageRow, VirtualKey } from "./keys.js";
12
+ export { openKeyStore, serveGateway } from "./serve.js";
13
+ export type { ServeOptions, ServingGateway } from "./serve.js";
14
+ export { KEY_STORE_SCHEMA, openSqliteKeyStore } from "./sqlite-key-store.js";
@@ -0,0 +1,7 @@
1
+ export { AiRouterError } from "../errors.js";
2
+ export { createRouter } from "../router.js";
3
+ export { loadGatewayConfig, parseGatewayConfig } from "./config-file.js";
4
+ export { createGateway } from "./gateway.js";
5
+ export { KeyAdmin, KeyAdminError, MemoryKeyStore } from "./keys.js";
6
+ export { openKeyStore, serveGateway } from "./serve.js";
7
+ export { KEY_STORE_SCHEMA, openSqliteKeyStore } from "./sqlite-key-store.js";