@opengeni/config 0.10.1 → 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/config",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "OpenGeni runtime configuration: settings resolution, deployment knobs, and config validation shared across the server packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "prepublishOnly": "bash ../../scripts/prepublish-guard"
34
34
  },
35
35
  "dependencies": {
36
- "@opengeni/codex": "^0.2.9",
37
- "@opengeni/contracts": "^0.31.1",
36
+ "@opengeni/codex": "^0.2.10",
37
+ "@opengeni/contracts": "^0.32.0",
38
38
  "zod": "^4.2.1"
39
39
  },
40
40
  "engines": {
package/src/index.ts CHANGED
@@ -432,7 +432,7 @@ const SettingsSchema = z.object({
432
432
  // match the UI danger flip (UsageBar danger at pct >= 90). OPENGENI_CODEX_ROTATION_NEAR_EXHAUSTION_PCT.
433
433
  codexRotationNearExhaustionPct: z.coerce.number().int().min(1).max(100).default(90),
434
434
  openaiReasoningEffort: ReasoningEffort.default("low"),
435
- openaiAllowedReasoningEfforts: z.string().default("low,medium,high,xhigh"),
435
+ openaiAllowedReasoningEfforts: z.string().default("low,medium,high,xhigh,max"),
436
436
  openaiResponsesTransport: z.enum(["http", "websocket"]).default("http"),
437
437
  // Provider-assigned item ids (rs_/msg_/fc_…) in Responses API input are
438
438
  // resolved against the provider's server-side response store. That store is
@@ -1415,7 +1415,7 @@ export interface ConfiguredModel {
1415
1415
  capabilities: ModelCapabilitiesV1;
1416
1416
  requestPolicy?: {
1417
1417
  gateway: {
1418
- only: [string];
1418
+ only: [string, ...string[]];
1419
1419
  caching: "auto" | "none";
1420
1420
  };
1421
1421
  };
@@ -1430,27 +1430,74 @@ export interface ConfiguredModel {
1430
1430
  }
1431
1431
 
1432
1432
  export const VERCEL_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh/v1" as const;
1433
+ export const VERCEL_AI_GATEWAY_AI_SDK_BASE_URL = "https://ai-gateway.vercel.sh/v4/ai" as const;
1433
1434
  export const OPENGENI_GATEWAY_PROVIDER_ID = "opengeni-gateway" as const;
1434
1435
  export const WORKSPACE_GATEWAY_PROVIDER_ID = "workspace-gateway" as const;
1435
1436
  export const WORKSPACE_GATEWAY_MODEL_ID_PREFIX = "workspace-gateway/" as const;
1436
1437
  export const VERCEL_AI_GATEWAY_CONNECTION_DOMAIN = "ai-gateway.vercel.sh" as const;
1437
1438
  export const VERCEL_AI_GATEWAY_CONNECTION_ROLE = "vercel_ai_gateway" as const;
1438
1439
 
1440
+ export const CODEX_REALTIME_MODEL_ID = "gpt-live-1-boulder-alpha" as const;
1441
+ export const OPENGENI_REALTIME_MODEL_ID_PREFIX = "opengeni-gateway/" as const;
1442
+ export const WORKSPACE_REALTIME_MODEL_ID_PREFIX = "workspace-gateway/" as const;
1443
+
1444
+ /** Curated voice models exposed through AI Gateway's normalized realtime API. */
1445
+ export const AI_GATEWAY_REALTIME_MODELS = {
1446
+ openaiRealtime21: {
1447
+ upstreamModelId: "openai/gpt-realtime-2.1",
1448
+ managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-2.1`,
1449
+ workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-2.1`,
1450
+ label: "GPT Realtime 2.1",
1451
+ description: "Best overall voice intelligence",
1452
+ },
1453
+ openaiRealtimeMini: {
1454
+ upstreamModelId: "openai/gpt-realtime-mini",
1455
+ managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-mini`,
1456
+ workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}openai/gpt-realtime-mini`,
1457
+ label: "GPT Realtime Mini",
1458
+ description: "Faster, lighter live voice",
1459
+ },
1460
+ grokVoiceThinkFast20: {
1461
+ upstreamModelId: "xai/grok-voice-think-fast-2.0",
1462
+ managedModelId: `${OPENGENI_REALTIME_MODEL_ID_PREFIX}xai/grok-voice-think-fast-2.0`,
1463
+ workspaceModelId: `${WORKSPACE_REALTIME_MODEL_ID_PREFIX}xai/grok-voice-think-fast-2.0`,
1464
+ label: "Grok Voice Think Fast 2.0",
1465
+ description: "Fast, natural xAI voice",
1466
+ },
1467
+ } as const;
1468
+
1469
+ export type AiGatewayRealtimeModel =
1470
+ (typeof AI_GATEWAY_REALTIME_MODELS)[keyof typeof AI_GATEWAY_REALTIME_MODELS];
1471
+
1472
+ export function resolveAiGatewayRealtimeModel(
1473
+ modelId: string,
1474
+ ): { source: "managed" | "workspace"; upstreamModelId: string } | null {
1475
+ for (const model of Object.values(AI_GATEWAY_REALTIME_MODELS)) {
1476
+ if (model.managedModelId === modelId) {
1477
+ return { source: "managed", upstreamModelId: model.upstreamModelId };
1478
+ }
1479
+ if (model.workspaceModelId === modelId) {
1480
+ return { source: "workspace", upstreamModelId: model.upstreamModelId };
1481
+ }
1482
+ }
1483
+ return null;
1484
+ }
1485
+
1439
1486
  export const OPENGENI_GATEWAY_MODELS = {
1440
1487
  deepseek: {
1441
1488
  productId: "deepseek-v4-flash-0731",
1442
1489
  workspaceProductId: `${WORKSPACE_GATEWAY_MODEL_ID_PREFIX}deepseek-v4-flash-0731`,
1443
1490
  upstreamModelId: "deepseek/deepseek-v4-flash-0731",
1444
1491
  label: "DeepSeek V4 Flash 0731",
1445
- provider: "deepinfra",
1492
+ providers: ["baseten", "novita", "deepinfra"],
1446
1493
  implicitCaching: true,
1447
1494
  },
1448
1495
  kimi: {
1449
- productId: "kimi-k3-fast",
1450
- workspaceProductId: `${WORKSPACE_GATEWAY_MODEL_ID_PREFIX}kimi-k3-fast`,
1451
- upstreamModelId: "moonshotai/kimi-k3-fast",
1452
- label: "Kimi K3 Fast",
1453
- provider: "wafer",
1496
+ productId: "kimi-k3",
1497
+ workspaceProductId: `${WORKSPACE_GATEWAY_MODEL_ID_PREFIX}kimi-k3`,
1498
+ upstreamModelId: "moonshotai/kimi-k3",
1499
+ label: "Kimi K3",
1500
+ providers: ["baseten", "fireworks"],
1454
1501
  implicitCaching: true,
1455
1502
  },
1456
1503
  } as const;
@@ -1529,24 +1576,24 @@ export const defaultModelPricing: Record<string, ModelPricingScheduleV1> = {
1529
1576
  },
1530
1577
  ],
1531
1578
  },
1532
- // Vercel AI Gateway endpoint prices, provider-pinned in the runtime.
1533
- // Snapshot: 2026-08-02. Both pinned routes returned discounted implicit
1534
- // cache reads in live Gateway responses. Wafer/Kimi reported $0.45/M even
1535
- // though the provider-discovery flag currently says otherwise; bill from
1536
- // the response-backed rate, not that inconsistent boolean.
1579
+ // Conservative Vercel AI Gateway fallback prices. Normal managed Gateway
1580
+ // billing uses the exact response Gateway `cost` / `inferenceCost` and applies
1581
+ // the same margin. These token rates are used only if that
1582
+ // metadata is absent. DeepSeek therefore carries the highest approved route
1583
+ // (Novita); both approved Kimi routes have the same list price.
1537
1584
  [OPENGENI_GATEWAY_MODELS.deepseek.productId]: {
1538
1585
  default: {
1539
- inputMicrosPerMillionTokens: 90_000,
1540
- cachedInputMicrosPerMillionTokens: 18_000,
1541
- outputMicrosPerMillionTokens: 180_000,
1586
+ inputMicrosPerMillionTokens: 140_000,
1587
+ cachedInputMicrosPerMillionTokens: 28_000,
1588
+ outputMicrosPerMillionTokens: 280_000,
1542
1589
  marginBps: 2_500,
1543
1590
  },
1544
1591
  },
1545
1592
  [OPENGENI_GATEWAY_MODELS.kimi.productId]: {
1546
1593
  default: {
1547
- inputMicrosPerMillionTokens: 4_500_000,
1548
- cachedInputMicrosPerMillionTokens: 450_000,
1549
- outputMicrosPerMillionTokens: 22_500_000,
1594
+ inputMicrosPerMillionTokens: 3_000_000,
1595
+ cachedInputMicrosPerMillionTokens: 300_000,
1596
+ outputMicrosPerMillionTokens: 15_000_000,
1550
1597
  marginBps: 2_500,
1551
1598
  },
1552
1599
  },
@@ -2279,7 +2326,7 @@ export function gatewayRequestPolicyForUpstreamModel(
2279
2326
  }
2280
2327
  return {
2281
2328
  gateway: {
2282
- only: [model.provider],
2329
+ only: [...model.providers] as [string, ...string[]],
2283
2330
  caching: model.implicitCaching ? "auto" : "none",
2284
2331
  },
2285
2332
  };
@@ -2304,8 +2351,8 @@ function gatewayModelCapabilities(
2304
2351
  promptCaching: input.implicitCaching
2305
2352
  ? { upstream: "supported", runnable: true, mode: "implicit" }
2306
2353
  : { upstream: "unsupported", runnable: false, mode: "none" },
2307
- // "Fast" is part of Kimi's product name, not OpenGeni's separately billed
2308
- // latency mode. Both Gateway products expose only standard here.
2354
+ // Both Gateway products expose one reviewed route policy and no separately
2355
+ // billed latency mode.
2309
2356
  latencyModes: [{ id: "standard", upstream: "supported", runnable: true }],
2310
2357
  });
2311
2358
  }
@@ -2317,19 +2364,22 @@ function gatewayRegistryProvider(
2317
2364
  | { kind: "vercel-gateway-workspace"; apiKey?: string },
2318
2365
  ): RegistryProvider {
2319
2366
  const workspace = input.kind === "vercel-gateway-workspace";
2320
- const models = [OPENGENI_GATEWAY_MODELS.deepseek, OPENGENI_GATEWAY_MODELS.kimi].map((model) => ({
2321
- id: workspace ? model.workspaceProductId : model.productId,
2322
- upstreamModelId: model.upstreamModelId,
2323
- label: model.label,
2324
- capabilities: gatewayModelCapabilities(settings, {
2325
- implicitCaching: model.implicitCaching,
2326
- vision: model === OPENGENI_GATEWAY_MODELS.kimi,
2327
- }),
2328
- contextWindowTokens: 1_000_000,
2329
- effectiveContextWindowTokens: 900_000,
2330
- autoCompactTokenLimit: 850_000,
2331
- toolOutputTruncationTokens: settings.modelToolOutputTruncationTokens,
2332
- }));
2367
+ const models = [OPENGENI_GATEWAY_MODELS.deepseek, OPENGENI_GATEWAY_MODELS.kimi].map((model) => {
2368
+ const kimi = model === OPENGENI_GATEWAY_MODELS.kimi;
2369
+ return {
2370
+ id: workspace ? model.workspaceProductId : model.productId,
2371
+ upstreamModelId: model.upstreamModelId,
2372
+ label: model.label,
2373
+ capabilities: gatewayModelCapabilities(settings, {
2374
+ implicitCaching: model.implicitCaching,
2375
+ vision: kimi,
2376
+ }),
2377
+ contextWindowTokens: 1_000_000,
2378
+ effectiveContextWindowTokens: 900_000,
2379
+ autoCompactTokenLimit: 850_000,
2380
+ toolOutputTruncationTokens: settings.modelToolOutputTruncationTokens,
2381
+ };
2382
+ });
2333
2383
  return {
2334
2384
  kind: input.kind,
2335
2385
  id: workspace ? WORKSPACE_GATEWAY_PROVIDER_ID : OPENGENI_GATEWAY_PROVIDER_ID,
@@ -3316,6 +3366,39 @@ export function calculateModelUsageCostMicros(
3316
3366
  return total;
3317
3367
  }
3318
3368
 
3369
+ /**
3370
+ * Convert AI Gateway's exact USD inference cost to OpenGeni credit micros and
3371
+ * apply the configured model margin. Decimal arithmetic is integer-only so a
3372
+ * sub-micro provider charge cannot be lost to floating-point rounding.
3373
+ */
3374
+ export function calculateGatewayReportedCostMicros(
3375
+ settings: Settings,
3376
+ model: string,
3377
+ inferenceCostUsd: string,
3378
+ options?: { inputTokens?: number },
3379
+ ): number {
3380
+ const schedule = configuredModelPricingSchedules(settings)[model];
3381
+ if (!schedule) {
3382
+ throw new Error(`Missing model pricing for ${model}`);
3383
+ }
3384
+ const pricing = selectModelPricing(schedule, positiveInt(options?.inputTokens));
3385
+ const match = /^(0|[1-9]\d*)(?:\.(\d{1,18}))?$/.exec(inferenceCostUsd);
3386
+ if (!match) {
3387
+ throw new Error("Invalid AI Gateway inference cost");
3388
+ }
3389
+ const fraction = match[2] ?? "";
3390
+ const decimalDigits = BigInt(`${match[1]}${fraction}`);
3391
+ const decimalScale = 10n ** BigInt(fraction.length);
3392
+ const marginBps = BigInt(10_000 + (pricing.marginBps ?? 0));
3393
+ const numerator = decimalDigits * 1_000_000n * marginBps;
3394
+ const denominator = decimalScale * 10_000n;
3395
+ const micros = (numerator + denominator - 1n) / denominator;
3396
+ if (micros > BigInt(Number.MAX_SAFE_INTEGER)) {
3397
+ throw new Error("AI Gateway inference cost exceeds the supported billing range");
3398
+ }
3399
+ return Number(micros);
3400
+ }
3401
+
3319
3402
  export function configuredAllowedReasoningEfforts(
3320
3403
  settings: Settings,
3321
3404
  ): Array<z.infer<typeof ReasoningEffort>> {