@modelcost/sdk 0.1.0 → 0.2.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/dist/index.d.mts CHANGED
@@ -871,8 +871,7 @@ type ModelPricing = z.infer<typeof ModelPricingSchema>;
871
871
 
872
872
  /**
873
873
  * Known model pricing table (cost per 1,000 tokens in USD).
874
- * Loaded from sdk/common/model_pricing.json at import time,
875
- * refreshed at runtime via syncPricingFromApi().
874
+ * Starts empty, populated from server API on init.
876
875
  */
877
876
  declare const MODEL_PRICING: ReadonlyMap<string, ModelPricing>;
878
877
  /**
@@ -1146,7 +1145,7 @@ declare class ModelCost {
1146
1145
  * Initialize the ModelCost SDK. Must be called before any other method.
1147
1146
  * Subsequent calls will re-initialize (shutting down the previous instance).
1148
1147
  */
1149
- static init(options: ModelCostInitOptions): void;
1148
+ static init(options: ModelCostInitOptions): Promise<void>;
1150
1149
  /**
1151
1150
  * Wrap an AI provider client with cost tracking, budget enforcement,
1152
1151
  * and PII scanning. Returns a proxied version of the same client.
package/dist/index.d.ts CHANGED
@@ -871,8 +871,7 @@ type ModelPricing = z.infer<typeof ModelPricingSchema>;
871
871
 
872
872
  /**
873
873
  * Known model pricing table (cost per 1,000 tokens in USD).
874
- * Loaded from sdk/common/model_pricing.json at import time,
875
- * refreshed at runtime via syncPricingFromApi().
874
+ * Starts empty, populated from server API on init.
876
875
  */
877
876
  declare const MODEL_PRICING: ReadonlyMap<string, ModelPricing>;
878
877
  /**
@@ -1146,7 +1145,7 @@ declare class ModelCost {
1146
1145
  * Initialize the ModelCost SDK. Must be called before any other method.
1147
1146
  * Subsequent calls will re-initialize (shutting down the previous instance).
1148
1147
  */
1149
- static init(options: ModelCostInitOptions): void;
1148
+ static init(options: ModelCostInitOptions): Promise<void>;
1150
1149
  /**
1151
1150
  * Wrap an AI provider client with cost tracking, budget enforcement,
1152
1151
  * and PII scanning. Returns a proxied version of the same client.
package/dist/index.js CHANGED
@@ -620,22 +620,7 @@ var BudgetManager = class {
620
620
  };
621
621
 
622
622
  // src/tracking.ts
623
- function _loadBundledPricing() {
624
- return /* @__PURE__ */ new Map([
625
- ["gpt-4", { provider: "openai", model: "gpt-4", inputCostPer1k: 0.03, outputCostPer1k: 0.06 }],
626
- ["gpt-4-turbo", { provider: "openai", model: "gpt-4-turbo", inputCostPer1k: 0.01, outputCostPer1k: 0.03 }],
627
- ["gpt-4o", { provider: "openai", model: "gpt-4o", inputCostPer1k: 5e-3, outputCostPer1k: 0.015 }],
628
- ["gpt-4o-mini", { provider: "openai", model: "gpt-4o-mini", inputCostPer1k: 15e-5, outputCostPer1k: 6e-4 }],
629
- ["gpt-3.5-turbo", { provider: "openai", model: "gpt-3.5-turbo", inputCostPer1k: 15e-4, outputCostPer1k: 2e-3 }],
630
- ["claude-opus-4", { provider: "anthropic", model: "claude-opus-4", inputCostPer1k: 0.015, outputCostPer1k: 0.075 }],
631
- ["claude-sonnet-4", { provider: "anthropic", model: "claude-sonnet-4", inputCostPer1k: 3e-3, outputCostPer1k: 0.015 }],
632
- ["claude-haiku-4", { provider: "anthropic", model: "claude-haiku-4", inputCostPer1k: 25e-5, outputCostPer1k: 125e-5 }],
633
- ["gemini-1.5-pro", { provider: "google", model: "gemini-1.5-pro", inputCostPer1k: 125e-5, outputCostPer1k: 5e-3 }],
634
- ["gemini-1.5-flash", { provider: "google", model: "gemini-1.5-flash", inputCostPer1k: 75e-6, outputCostPer1k: 3e-4 }],
635
- ["gemini-2.0-flash", { provider: "google", model: "gemini-2.0-flash", inputCostPer1k: 1e-4, outputCostPer1k: 4e-4 }]
636
- ]);
637
- }
638
- var _modelPricing = _loadBundledPricing();
623
+ var _modelPricing = /* @__PURE__ */ new Map();
639
624
  var MODEL_PRICING = _modelPricing;
640
625
  async function syncPricingFromApi(baseUrl, apiKey) {
641
626
  try {
@@ -1840,7 +1825,7 @@ var ModelCost = class _ModelCost {
1840
1825
  * Initialize the ModelCost SDK. Must be called before any other method.
1841
1826
  * Subsequent calls will re-initialize (shutting down the previous instance).
1842
1827
  */
1843
- static init(options) {
1828
+ static async init(options) {
1844
1829
  if (_ModelCost._instance) {
1845
1830
  _ModelCost._instance.costTracker.stopAutoFlush();
1846
1831
  _ModelCost._instance.costTracker.stopPricingSync();
@@ -1848,6 +1833,11 @@ var ModelCost = class _ModelCost {
1848
1833
  }
1849
1834
  const config = new ModelCostConfig(options);
1850
1835
  const client = new ModelCostClient(config);
1836
+ try {
1837
+ await syncPricingFromApi(config.baseUrl, config.apiKey);
1838
+ } catch {
1839
+ console.warn("[ModelCost] Failed to sync pricing on init; cost estimates unavailable until next sync");
1840
+ }
1851
1841
  const budgetManager = new BudgetManager(config.syncIntervalMs);
1852
1842
  const costTracker = new CostTracker(config.flushBatchSize);
1853
1843
  const piiScanner = new PiiScanner();