@llmops/core 0.1.5-beta.1 → 0.1.5

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/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { A as TargetingRulesTable, B as environmentSecretsSchema, C as EnvironmentSecretsTable, D as Selectable, E as SCHEMA_METADATA, F as VariantsTable, G as variantsSchema, H as schemas, I as WorkspaceSettings, K as workspaceSettingsSchema, L as WorkspaceSettingsTable, M as Variant, N as VariantVersion, O as TableName, P as VariantVersionsTable, R as configVariantsSchema, S as EnvironmentSecret, T as Insertable, U as targetingRulesSchema, V as environmentsSchema, W as variantVersionsSchema, _ as ConfigVariant, a as createDatabaseFromConnection, b as Database, c as MigrationResult, d as runAutoMigrations, f as parsePartialTableData, g as Config, h as validateTableData, i as createDatabase, j as Updateable, k as TargetingRule, l as getMigrations, m as validatePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as parseTableData, r as DatabaseType, s as MigrationOptions, t as DatabaseConnection, u as matchType, v as ConfigVariantsTable, w as EnvironmentsTable, x as Environment, y as ConfigsTable, z as configsSchema } from "./index-D3ncxgf2.mjs";
1
+ import { A as TableName, B as configVariantsSchema, C as EnvironmentSecretsTable, D as LLMRequestsTable, E as LLMRequest, F as VariantVersion, G as schemas, H as environmentSecretsSchema, I as VariantVersionsTable, J as variantsSchema, K as targetingRulesSchema, L as VariantsTable, M as TargetingRulesTable, N as Updateable, O as SCHEMA_METADATA, P as Variant, R as WorkspaceSettings, S as EnvironmentSecret, T as Insertable, U as environmentsSchema, V as configsSchema, W as llmRequestsSchema, Y as workspaceSettingsSchema, _ as ConfigVariant, a as createDatabaseFromConnection, b as Database, c as MigrationResult, d as runAutoMigrations, f as parsePartialTableData, g as Config, h as validateTableData, i as createDatabase, j as TargetingRule, k as Selectable, l as getMigrations, m as validatePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as parseTableData, q as variantVersionsSchema, r as DatabaseType, s as MigrationOptions, t as DatabaseConnection, u as matchType, v as ConfigVariantsTable, w as EnvironmentsTable, x as Environment, y as ConfigsTable, z as WorkspaceSettingsTable } from "./index-mUSLoeGU.mjs";
2
2
  import gateway from "@llmops/gateway";
3
3
  import { Kysely } from "kysely";
4
4
  import pino from "pino";
5
5
  import * as zod0 from "zod";
6
- import { z } from "zod";
6
+ import z$1, { z } from "zod";
7
7
  import * as zod_v4_core0 from "zod/v4/core";
8
8
 
9
9
  //#region src/providers/supported-providers.d.ts
@@ -1511,6 +1511,239 @@ declare const logger: pino.Logger<never, boolean>;
1511
1511
  //#region src/utils/id.d.ts
1512
1512
  declare const generateId: (size?: number) => string;
1513
1513
  //#endregion
1514
+ //#region src/datalayer/llmRequests.d.ts
1515
+ /**
1516
+ * Schema for inserting a new LLM request log
1517
+ */
1518
+ declare const insertLLMRequestSchema: z$1.ZodObject<{
1519
+ requestId: z$1.ZodString;
1520
+ configId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
1521
+ variantId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
1522
+ provider: z$1.ZodString;
1523
+ model: z$1.ZodString;
1524
+ promptTokens: z$1.ZodDefault<z$1.ZodNumber>;
1525
+ completionTokens: z$1.ZodDefault<z$1.ZodNumber>;
1526
+ totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
1527
+ cachedTokens: z$1.ZodDefault<z$1.ZodNumber>;
1528
+ cost: z$1.ZodDefault<z$1.ZodNumber>;
1529
+ inputCost: z$1.ZodDefault<z$1.ZodNumber>;
1530
+ outputCost: z$1.ZodDefault<z$1.ZodNumber>;
1531
+ endpoint: z$1.ZodString;
1532
+ statusCode: z$1.ZodNumber;
1533
+ latencyMs: z$1.ZodDefault<z$1.ZodNumber>;
1534
+ isStreaming: z$1.ZodDefault<z$1.ZodBoolean>;
1535
+ userId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
1536
+ tags: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
1537
+ }, z$1.core.$strip>;
1538
+ type LLMRequestInsert = z$1.infer<typeof insertLLMRequestSchema>;
1539
+ /**
1540
+ * Schema for listing LLM requests
1541
+ */
1542
+ declare const listRequestsSchema: z$1.ZodObject<{
1543
+ limit: z$1.ZodDefault<z$1.ZodNumber>;
1544
+ offset: z$1.ZodDefault<z$1.ZodNumber>;
1545
+ configId: z$1.ZodOptional<z$1.ZodString>;
1546
+ provider: z$1.ZodOptional<z$1.ZodString>;
1547
+ model: z$1.ZodOptional<z$1.ZodString>;
1548
+ startDate: z$1.ZodOptional<z$1.ZodDate>;
1549
+ endDate: z$1.ZodOptional<z$1.ZodDate>;
1550
+ }, z$1.core.$strip>;
1551
+ /**
1552
+ * Schema for date range queries
1553
+ */
1554
+ declare const dateRangeSchema: z$1.ZodObject<{
1555
+ startDate: z$1.ZodDate;
1556
+ endDate: z$1.ZodDate;
1557
+ }, z$1.core.$strip>;
1558
+ /**
1559
+ * Schema for cost summary with grouping
1560
+ */
1561
+ declare const costSummarySchema: z$1.ZodObject<{
1562
+ startDate: z$1.ZodDate;
1563
+ endDate: z$1.ZodDate;
1564
+ groupBy: z$1.ZodOptional<z$1.ZodEnum<{
1565
+ provider: "provider";
1566
+ model: "model";
1567
+ day: "day";
1568
+ hour: "hour";
1569
+ config: "config";
1570
+ }>>;
1571
+ }, z$1.core.$strip>;
1572
+ declare const createLLMRequestsDataLayer: (db: Kysely<Database>) => {
1573
+ /**
1574
+ * Batch insert LLM request logs
1575
+ * Used by the BatchWriter service for efficient writes
1576
+ */
1577
+ batchInsertRequests: (requests: LLMRequestInsert[]) => Promise<{
1578
+ count: number;
1579
+ }>;
1580
+ /**
1581
+ * Insert a single LLM request log
1582
+ */
1583
+ insertRequest: (request: LLMRequestInsert) => Promise<{
1584
+ configId: string | null;
1585
+ variantId: string | null;
1586
+ id: string;
1587
+ provider: string;
1588
+ requestId: string;
1589
+ model: string;
1590
+ promptTokens: number;
1591
+ completionTokens: number;
1592
+ totalTokens: number;
1593
+ cachedTokens: number;
1594
+ cost: number;
1595
+ inputCost: number;
1596
+ outputCost: number;
1597
+ endpoint: string;
1598
+ statusCode: number;
1599
+ latencyMs: number;
1600
+ isStreaming: boolean;
1601
+ userId: string | null;
1602
+ tags: Record<string, string>;
1603
+ createdAt: Date;
1604
+ updatedAt: Date;
1605
+ } | undefined>;
1606
+ /**
1607
+ * List LLM requests with filtering and pagination
1608
+ * Returns data and total count for pagination
1609
+ */
1610
+ listRequests: (params?: z$1.infer<typeof listRequestsSchema>) => Promise<{
1611
+ data: {
1612
+ configId: string | null;
1613
+ variantId: string | null;
1614
+ id: string;
1615
+ provider: string;
1616
+ requestId: string;
1617
+ model: string;
1618
+ promptTokens: number;
1619
+ completionTokens: number;
1620
+ totalTokens: number;
1621
+ cachedTokens: number;
1622
+ cost: number;
1623
+ inputCost: number;
1624
+ outputCost: number;
1625
+ endpoint: string;
1626
+ statusCode: number;
1627
+ latencyMs: number;
1628
+ isStreaming: boolean;
1629
+ userId: string | null;
1630
+ tags: Record<string, string>;
1631
+ createdAt: Date;
1632
+ updatedAt: Date;
1633
+ }[];
1634
+ total: number;
1635
+ limit: number;
1636
+ offset: number;
1637
+ }>;
1638
+ /**
1639
+ * Get a single request by requestId
1640
+ */
1641
+ getRequestByRequestId: (requestId: string) => Promise<{
1642
+ configId: string | null;
1643
+ variantId: string | null;
1644
+ id: string;
1645
+ provider: string;
1646
+ requestId: string;
1647
+ model: string;
1648
+ promptTokens: number;
1649
+ completionTokens: number;
1650
+ totalTokens: number;
1651
+ cachedTokens: number;
1652
+ cost: number;
1653
+ inputCost: number;
1654
+ outputCost: number;
1655
+ endpoint: string;
1656
+ statusCode: number;
1657
+ latencyMs: number;
1658
+ isStreaming: boolean;
1659
+ userId: string | null;
1660
+ tags: Record<string, string>;
1661
+ createdAt: Date;
1662
+ updatedAt: Date;
1663
+ } | undefined>;
1664
+ /**
1665
+ * Get total cost for a date range
1666
+ */
1667
+ getTotalCost: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1668
+ totalCost: number;
1669
+ totalInputCost: number;
1670
+ totalOutputCost: number;
1671
+ totalPromptTokens: number;
1672
+ totalCompletionTokens: number;
1673
+ totalTokens: number;
1674
+ requestCount: number;
1675
+ } | undefined>;
1676
+ /**
1677
+ * Get cost breakdown by model
1678
+ */
1679
+ getCostByModel: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1680
+ provider: string;
1681
+ model: string;
1682
+ totalCost: number;
1683
+ totalInputCost: number;
1684
+ totalOutputCost: number;
1685
+ totalTokens: number;
1686
+ requestCount: number;
1687
+ avgLatencyMs: number;
1688
+ }[]>;
1689
+ /**
1690
+ * Get cost breakdown by provider
1691
+ */
1692
+ getCostByProvider: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1693
+ provider: string;
1694
+ totalCost: number;
1695
+ totalInputCost: number;
1696
+ totalOutputCost: number;
1697
+ totalTokens: number;
1698
+ requestCount: number;
1699
+ avgLatencyMs: number;
1700
+ }[]>;
1701
+ /**
1702
+ * Get cost breakdown by config
1703
+ */
1704
+ getCostByConfig: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1705
+ configId: string | null;
1706
+ totalCost: number;
1707
+ totalInputCost: number;
1708
+ totalOutputCost: number;
1709
+ totalTokens: number;
1710
+ requestCount: number;
1711
+ configName: string | null | undefined;
1712
+ configSlug: string | null;
1713
+ }[]>;
1714
+ /**
1715
+ * Get daily cost summary
1716
+ */
1717
+ getDailyCosts: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1718
+ totalCost: number;
1719
+ totalInputCost: number;
1720
+ totalOutputCost: number;
1721
+ totalTokens: number;
1722
+ requestCount: number;
1723
+ date: string;
1724
+ }[]>;
1725
+ /**
1726
+ * Get cost summary with flexible grouping
1727
+ */
1728
+ getCostSummary: (params: z$1.infer<typeof costSummarySchema>) => Promise<{
1729
+ totalCost: number;
1730
+ requestCount: number;
1731
+ groupKey: string;
1732
+ }[]>;
1733
+ /**
1734
+ * Get request count and stats for a time range
1735
+ */
1736
+ getRequestStats: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
1737
+ avgLatencyMs: number;
1738
+ totalRequests: number;
1739
+ successfulRequests: number;
1740
+ failedRequests: number;
1741
+ streamingRequests: number;
1742
+ maxLatencyMs: number;
1743
+ minLatencyMs: number;
1744
+ } | undefined>;
1745
+ };
1746
+ //#endregion
1514
1747
  //#region src/datalayer/index.d.ts
1515
1748
  declare const createDataLayer: (db: Kysely<Database>) => Promise<{
1516
1749
  getWorkspaceSettings: () => Promise<{
@@ -1935,6 +2168,179 @@ declare const createDataLayer: (db: Kysely<Database>) => Promise<{
1935
2168
  createdAt: Date;
1936
2169
  updatedAt: Date;
1937
2170
  } | undefined>;
2171
+ batchInsertRequests: (requests: LLMRequestInsert[]) => Promise<{
2172
+ count: number;
2173
+ }>;
2174
+ insertRequest: (request: LLMRequestInsert) => Promise<{
2175
+ configId: string | null;
2176
+ variantId: string | null;
2177
+ id: string;
2178
+ provider: string;
2179
+ requestId: string;
2180
+ model: string;
2181
+ promptTokens: number;
2182
+ completionTokens: number;
2183
+ totalTokens: number;
2184
+ cachedTokens: number;
2185
+ cost: number;
2186
+ inputCost: number;
2187
+ outputCost: number;
2188
+ endpoint: string;
2189
+ statusCode: number;
2190
+ latencyMs: number;
2191
+ isStreaming: boolean;
2192
+ userId: string | null;
2193
+ tags: Record<string, string>;
2194
+ createdAt: Date;
2195
+ updatedAt: Date;
2196
+ } | undefined>;
2197
+ listRequests: (params?: zod0.infer<zod0.ZodObject<{
2198
+ limit: zod0.ZodDefault<zod0.ZodNumber>;
2199
+ offset: zod0.ZodDefault<zod0.ZodNumber>;
2200
+ configId: zod0.ZodOptional<zod0.ZodString>;
2201
+ provider: zod0.ZodOptional<zod0.ZodString>;
2202
+ model: zod0.ZodOptional<zod0.ZodString>;
2203
+ startDate: zod0.ZodOptional<zod0.ZodDate>;
2204
+ endDate: zod0.ZodOptional<zod0.ZodDate>;
2205
+ }, zod_v4_core0.$strip>>) => Promise<{
2206
+ data: {
2207
+ configId: string | null;
2208
+ variantId: string | null;
2209
+ id: string;
2210
+ provider: string;
2211
+ requestId: string;
2212
+ model: string;
2213
+ promptTokens: number;
2214
+ completionTokens: number;
2215
+ totalTokens: number;
2216
+ cachedTokens: number;
2217
+ cost: number;
2218
+ inputCost: number;
2219
+ outputCost: number;
2220
+ endpoint: string;
2221
+ statusCode: number;
2222
+ latencyMs: number;
2223
+ isStreaming: boolean;
2224
+ userId: string | null;
2225
+ tags: Record<string, string>;
2226
+ createdAt: Date;
2227
+ updatedAt: Date;
2228
+ }[];
2229
+ total: number;
2230
+ limit: number;
2231
+ offset: number;
2232
+ }>;
2233
+ getRequestByRequestId: (requestId: string) => Promise<{
2234
+ configId: string | null;
2235
+ variantId: string | null;
2236
+ id: string;
2237
+ provider: string;
2238
+ requestId: string;
2239
+ model: string;
2240
+ promptTokens: number;
2241
+ completionTokens: number;
2242
+ totalTokens: number;
2243
+ cachedTokens: number;
2244
+ cost: number;
2245
+ inputCost: number;
2246
+ outputCost: number;
2247
+ endpoint: string;
2248
+ statusCode: number;
2249
+ latencyMs: number;
2250
+ isStreaming: boolean;
2251
+ userId: string | null;
2252
+ tags: Record<string, string>;
2253
+ createdAt: Date;
2254
+ updatedAt: Date;
2255
+ } | undefined>;
2256
+ getTotalCost: (params: zod0.infer<zod0.ZodObject<{
2257
+ startDate: zod0.ZodDate;
2258
+ endDate: zod0.ZodDate;
2259
+ }, zod_v4_core0.$strip>>) => Promise<{
2260
+ totalCost: number;
2261
+ totalInputCost: number;
2262
+ totalOutputCost: number;
2263
+ totalPromptTokens: number;
2264
+ totalCompletionTokens: number;
2265
+ totalTokens: number;
2266
+ requestCount: number;
2267
+ } | undefined>;
2268
+ getCostByModel: (params: zod0.infer<zod0.ZodObject<{
2269
+ startDate: zod0.ZodDate;
2270
+ endDate: zod0.ZodDate;
2271
+ }, zod_v4_core0.$strip>>) => Promise<{
2272
+ provider: string;
2273
+ model: string;
2274
+ totalCost: number;
2275
+ totalInputCost: number;
2276
+ totalOutputCost: number;
2277
+ totalTokens: number;
2278
+ requestCount: number;
2279
+ avgLatencyMs: number;
2280
+ }[]>;
2281
+ getCostByProvider: (params: zod0.infer<zod0.ZodObject<{
2282
+ startDate: zod0.ZodDate;
2283
+ endDate: zod0.ZodDate;
2284
+ }, zod_v4_core0.$strip>>) => Promise<{
2285
+ provider: string;
2286
+ totalCost: number;
2287
+ totalInputCost: number;
2288
+ totalOutputCost: number;
2289
+ totalTokens: number;
2290
+ requestCount: number;
2291
+ avgLatencyMs: number;
2292
+ }[]>;
2293
+ getCostByConfig: (params: zod0.infer<zod0.ZodObject<{
2294
+ startDate: zod0.ZodDate;
2295
+ endDate: zod0.ZodDate;
2296
+ }, zod_v4_core0.$strip>>) => Promise<{
2297
+ configId: string | null;
2298
+ totalCost: number;
2299
+ totalInputCost: number;
2300
+ totalOutputCost: number;
2301
+ totalTokens: number;
2302
+ requestCount: number;
2303
+ configName: string | null | undefined;
2304
+ configSlug: string | null;
2305
+ }[]>;
2306
+ getDailyCosts: (params: zod0.infer<zod0.ZodObject<{
2307
+ startDate: zod0.ZodDate;
2308
+ endDate: zod0.ZodDate;
2309
+ }, zod_v4_core0.$strip>>) => Promise<{
2310
+ totalCost: number;
2311
+ totalInputCost: number;
2312
+ totalOutputCost: number;
2313
+ totalTokens: number;
2314
+ requestCount: number;
2315
+ date: string;
2316
+ }[]>;
2317
+ getCostSummary: (params: zod0.infer<zod0.ZodObject<{
2318
+ startDate: zod0.ZodDate;
2319
+ endDate: zod0.ZodDate;
2320
+ groupBy: zod0.ZodOptional<zod0.ZodEnum<{
2321
+ provider: "provider";
2322
+ model: "model";
2323
+ day: "day";
2324
+ hour: "hour";
2325
+ config: "config";
2326
+ }>>;
2327
+ }, zod_v4_core0.$strip>>) => Promise<{
2328
+ totalCost: number;
2329
+ requestCount: number;
2330
+ groupKey: string;
2331
+ }[]>;
2332
+ getRequestStats: (params: zod0.infer<zod0.ZodObject<{
2333
+ startDate: zod0.ZodDate;
2334
+ endDate: zod0.ZodDate;
2335
+ }, zod_v4_core0.$strip>>) => Promise<{
2336
+ avgLatencyMs: number;
2337
+ totalRequests: number;
2338
+ successfulRequests: number;
2339
+ failedRequests: number;
2340
+ streamingRequests: number;
2341
+ maxLatencyMs: number;
2342
+ minLatencyMs: number;
2343
+ } | undefined>;
1938
2344
  createEnvironmentSecret: (params: zod0.infer<zod0.ZodObject<{
1939
2345
  environmentId: zod0.ZodUUID;
1940
2346
  keyName: zod0.ZodString;
@@ -2228,6 +2634,8 @@ declare const createDataLayer: (db: Kysely<Database>) => Promise<{
2228
2634
  configId: zod0.ZodString;
2229
2635
  envSecret: zod0.ZodOptional<zod0.ZodString>;
2230
2636
  }, zod_v4_core0.$strip>>) => Promise<{
2637
+ configId: string;
2638
+ variantId: string;
2231
2639
  version: number;
2232
2640
  provider: string;
2233
2641
  modelName: string;
@@ -2296,4 +2704,193 @@ declare const createDataLayer: (db: Kysely<Database>) => Promise<{
2296
2704
  }[]>;
2297
2705
  }>;
2298
2706
  //#endregion
2299
- export { type AnthropicProviderConfig, type AnyProviderConfig, type AuthConfig, AutoMigrateConfig, type AzureAIProviderConfig, type AzureOpenAIProviderConfig, BaseCacheConfig, type BaseProviderConfig, type BasicAuthConfig, type BedrockProviderConfig, CacheBackend, CacheBackendType, CacheConfig, CacheEntry, CacheOptions, CacheService, CacheStats, ChatCompletionCreateParamsBase, Config, ConfigVariant, type ConfigVariantsTable, type ConfigsTable, type CortexProviderConfig, type Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, type EnvironmentSecretsTable, type EnvironmentsTable, FileCacheBackend, FileCacheConfig, type FireworksAIProviderConfig, type GoogleProviderConfig, type HuggingFaceProviderConfig, Insertable, LLMOpsClient, LLMOpsConfig, type LLMOpsConfigInput, MS, MemoryCacheBackend, MemoryCacheConfig, MigrationOptions, MigrationResult, type MistralAIProviderConfig, type OpenAIProviderConfig, type OracleProviderConfig, Prettify, type ProviderConfigMap, type ProvidersConfig, SCHEMA_METADATA, type SagemakerProviderConfig, Selectable, type StabilityAIProviderConfig, SupportedProviders, type TableName, TargetingRule, type TargetingRulesTable, Updateable, type ValidatedLLMOpsConfig, Variant, VariantJsonData, VariantVersion, VariantVersionsTable, type VariantsTable, type VertexAIProviderConfig, type WorkersAIProviderConfig, WorkspaceSettings, WorkspaceSettingsTable, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, detectDatabaseType, environmentSecretsSchema, environmentsSchema, gateway, generateId, getMigrations, llmopsConfigSchema, logger, matchType, parsePartialTableData, parseTableData, runAutoMigrations, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
2707
+ //#region src/pricing/types.d.ts
2708
+ /**
2709
+ * Pricing types for cost tracking
2710
+ */
2711
+ /**
2712
+ * Model pricing information
2713
+ * All costs are in dollars per 1 million tokens
2714
+ */
2715
+ interface ModelPricing {
2716
+ /** Cost per 1M input/prompt tokens in dollars */
2717
+ inputCostPer1M: number;
2718
+ /** Cost per 1M output/completion tokens in dollars */
2719
+ outputCostPer1M: number;
2720
+ /** Cost per 1M cached read tokens in dollars (optional) */
2721
+ cacheReadCostPer1M?: number;
2722
+ /** Cost per 1M cached write tokens in dollars (optional) */
2723
+ cacheWriteCostPer1M?: number;
2724
+ /** Cost per 1M reasoning tokens in dollars (optional, for models like o1) */
2725
+ reasoningCostPer1M?: number;
2726
+ }
2727
+ /**
2728
+ * Token usage data from LLM response
2729
+ */
2730
+ interface UsageData {
2731
+ /** Number of tokens in the prompt/input */
2732
+ promptTokens: number;
2733
+ /** Number of tokens in the completion/output */
2734
+ completionTokens: number;
2735
+ /** Total tokens (prompt + completion) */
2736
+ totalTokens?: number;
2737
+ /** Number of cached tokens (optional) */
2738
+ cachedTokens?: number;
2739
+ /** Number of reasoning tokens (optional, for models like o1) */
2740
+ reasoningTokens?: number;
2741
+ }
2742
+ /**
2743
+ * Cost calculation result
2744
+ * All costs are in micro-dollars (1 dollar = 1,000,000 micro-dollars)
2745
+ * This avoids floating-point precision issues
2746
+ */
2747
+ interface CostResult {
2748
+ /** Total cost in micro-dollars */
2749
+ totalCost: number;
2750
+ /** Input/prompt cost in micro-dollars */
2751
+ inputCost: number;
2752
+ /** Output/completion cost in micro-dollars */
2753
+ outputCost: number;
2754
+ }
2755
+ /**
2756
+ * Provider for fetching model pricing data
2757
+ * Abstracted to allow swapping data sources (models.dev, local JSON, etc.)
2758
+ */
2759
+ interface PricingProvider {
2760
+ /**
2761
+ * Get pricing for a specific model
2762
+ * @param provider - Provider name (e.g., "openai", "anthropic")
2763
+ * @param model - Model identifier (e.g., "gpt-4o", "claude-3-sonnet")
2764
+ * @returns Model pricing or null if not found
2765
+ */
2766
+ getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
2767
+ /**
2768
+ * Force refresh the pricing cache
2769
+ */
2770
+ refreshCache(): Promise<void>;
2771
+ /**
2772
+ * Check if the provider is ready (cache is populated)
2773
+ */
2774
+ isReady(): boolean;
2775
+ }
2776
+ //#endregion
2777
+ //#region src/pricing/calculator.d.ts
2778
+ /**
2779
+ * Calculate the cost of an LLM request in micro-dollars
2780
+ *
2781
+ * Micro-dollars are used to avoid floating-point precision issues:
2782
+ * - 1 dollar = 1,000,000 micro-dollars
2783
+ * - $0.001 = 1,000 micro-dollars
2784
+ * - $0.000001 = 1 micro-dollar
2785
+ *
2786
+ * @param usage - Token usage data from the LLM response
2787
+ * @param pricing - Model pricing information
2788
+ * @returns Cost breakdown in micro-dollars
2789
+ *
2790
+ * @example
2791
+ * ```typescript
2792
+ * const usage = { promptTokens: 1000, completionTokens: 500 };
2793
+ * const pricing = { inputCostPer1M: 2.5, outputCostPer1M: 10.0 };
2794
+ * const cost = calculateCost(usage, pricing);
2795
+ * // cost = { inputCost: 2500, outputCost: 5000, totalCost: 7500 }
2796
+ * // In dollars: $0.0025 input + $0.005 output = $0.0075 total
2797
+ * ```
2798
+ */
2799
+ declare function calculateCost(usage: UsageData, pricing: ModelPricing): CostResult;
2800
+ /**
2801
+ * Convert micro-dollars to dollars
2802
+ *
2803
+ * @param microDollars - Amount in micro-dollars
2804
+ * @returns Amount in dollars
2805
+ *
2806
+ * @example
2807
+ * ```typescript
2808
+ * microDollarsToDollars(7500); // 0.0075
2809
+ * microDollarsToDollars(1000000); // 1.0
2810
+ * ```
2811
+ */
2812
+ declare function microDollarsToDollars(microDollars: number): number;
2813
+ /**
2814
+ * Convert dollars to micro-dollars
2815
+ *
2816
+ * @param dollars - Amount in dollars
2817
+ * @returns Amount in micro-dollars (rounded to nearest integer)
2818
+ *
2819
+ * @example
2820
+ * ```typescript
2821
+ * dollarsToMicroDollars(0.0075); // 7500
2822
+ * dollarsToMicroDollars(1.0); // 1000000
2823
+ * ```
2824
+ */
2825
+ declare function dollarsToMicroDollars(dollars: number): number;
2826
+ /**
2827
+ * Format micro-dollars as a human-readable dollar string
2828
+ *
2829
+ * @param microDollars - Amount in micro-dollars
2830
+ * @param decimals - Number of decimal places (default: 6)
2831
+ * @returns Formatted dollar string
2832
+ *
2833
+ * @example
2834
+ * ```typescript
2835
+ * formatCost(7500); // "$0.007500"
2836
+ * formatCost(1234567, 2); // "$1.23"
2837
+ * ```
2838
+ */
2839
+ declare function formatCost(microDollars: number, decimals?: number): string;
2840
+ //#endregion
2841
+ //#region src/pricing/provider.d.ts
2842
+ /**
2843
+ * Pricing provider that fetches data from models.dev API
2844
+ *
2845
+ * Features:
2846
+ * - Caches pricing data with configurable TTL (default 5 minutes)
2847
+ * - Supports fallback to local cache on fetch failure
2848
+ * - Thread-safe cache refresh
2849
+ */
2850
+ declare class ModelsDevPricingProvider implements PricingProvider {
2851
+ private cache;
2852
+ private lastFetch;
2853
+ private cacheTTL;
2854
+ private fetchPromise;
2855
+ private ready;
2856
+ /**
2857
+ * Create a new ModelsDevPricingProvider
2858
+ *
2859
+ * @param cacheTTL - Cache TTL in milliseconds (default: 5 minutes)
2860
+ */
2861
+ constructor(cacheTTL?: number);
2862
+ /**
2863
+ * Generate a cache key for a provider/model combination
2864
+ */
2865
+ private getCacheKey;
2866
+ /**
2867
+ * Fetch pricing data from models.dev API
2868
+ */
2869
+ private fetchPricingData;
2870
+ /**
2871
+ * Ensure cache is fresh, fetching if necessary
2872
+ */
2873
+ private ensureFreshCache;
2874
+ /**
2875
+ * Get pricing for a specific model
2876
+ */
2877
+ getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
2878
+ /**
2879
+ * Force refresh the pricing cache
2880
+ */
2881
+ refreshCache(): Promise<void>;
2882
+ /**
2883
+ * Check if the provider is ready
2884
+ */
2885
+ isReady(): boolean;
2886
+ /**
2887
+ * Get the number of cached models (for debugging)
2888
+ */
2889
+ getCacheSize(): number;
2890
+ }
2891
+ /**
2892
+ * Get the default pricing provider instance
2893
+ */
2894
+ declare function getDefaultPricingProvider(): ModelsDevPricingProvider;
2895
+ //#endregion
2896
+ export { type AnthropicProviderConfig, type AnyProviderConfig, type AuthConfig, AutoMigrateConfig, type AzureAIProviderConfig, type AzureOpenAIProviderConfig, BaseCacheConfig, type BaseProviderConfig, type BasicAuthConfig, type BedrockProviderConfig, CacheBackend, CacheBackendType, CacheConfig, CacheEntry, CacheOptions, CacheService, CacheStats, ChatCompletionCreateParamsBase, Config, ConfigVariant, type ConfigVariantsTable, type ConfigsTable, type CortexProviderConfig, CostResult, type Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, type EnvironmentSecretsTable, type EnvironmentsTable, FileCacheBackend, FileCacheConfig, type FireworksAIProviderConfig, type GoogleProviderConfig, type HuggingFaceProviderConfig, Insertable, LLMOpsClient, LLMOpsConfig, type LLMOpsConfigInput, LLMRequest, type LLMRequestInsert, LLMRequestsTable, MS, MemoryCacheBackend, MemoryCacheConfig, MigrationOptions, MigrationResult, type MistralAIProviderConfig, ModelPricing, ModelsDevPricingProvider, type OpenAIProviderConfig, type OracleProviderConfig, Prettify, PricingProvider, type ProviderConfigMap, type ProvidersConfig, SCHEMA_METADATA, type SagemakerProviderConfig, Selectable, type StabilityAIProviderConfig, SupportedProviders, type TableName, TargetingRule, type TargetingRulesTable, Updateable, UsageData, type ValidatedLLMOpsConfig, Variant, VariantJsonData, VariantVersion, VariantVersionsTable, type VariantsTable, type VertexAIProviderConfig, type WorkersAIProviderConfig, WorkspaceSettings, WorkspaceSettingsTable, calculateCost, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, createLLMRequestsDataLayer, detectDatabaseType, dollarsToMicroDollars, environmentSecretsSchema, environmentsSchema, formatCost, gateway, generateId, getDefaultPricingProvider, getMigrations, llmRequestsSchema, llmopsConfigSchema, logger, matchType, microDollarsToDollars, parsePartialTableData, parseTableData, runAutoMigrations, schemas, targetingRulesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };