{"record":{"id":"0194fb05ae56cc61","repo":"JuliusBrussee/caveman","slug":"cave-provider-cost-mismatch","errorCode":"cave_provider_cost_mismatch","errorMessage":"cave_provider_cost_mismatch","messagePattern":"cave_provider_cost_mismatch","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/execution-kernel.ts","lineNumber":168,"sourceCode":"    throw new Error(\"cave_provider_usage_incomplete\");\n  }\n  const priced = catalogCost({\n    provider: evidence.provider,\n    model: evidence.model,\n    inputTokens: evidence.inputTokens,\n    outputTokens: evidence.outputTokens,\n    cacheReadTokens: evidence.cacheReadTokens,\n    cacheWriteTokens: evidence.cacheWriteTokens,\n    reasoningTokens: evidence.reasoningTokens,\n  });\n  if (!priced.priced && options.requirePriced === true) {\n    throw new Error(\"cave_provider_usage_unpriced\");\n  }\n  if (options.reportedCostUsd !== undefined &&\n      (!priced.priced || !Number.isFinite(options.reportedCostUsd) ||\n        options.reportedCostUsd < 0 ||\n        Math.abs(options.reportedCostUsd - priced.usd) > 1e-12)) {\n    throw new Error(\"cave_provider_cost_mismatch\");\n  }\n  return Object.freeze({\n    ...evidence,\n    priced: priced.priced,\n    catalogCostUsd: priced.priced ? priced.usd : 0,\n  });\n}\n","sourceCodeStart":150,"sourceCodeEnd":176,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/execution-kernel.ts#L150-L176","documentation":"validateProviderUsage throws cave_provider_cost_mismatch when options.reportedCostUsd is provided but is not a finite non-negative number or differs from the catalog-computed cost (priced.usd) by more than 1e-12 — including the case where the usage is unpriced (priced.priced is false) while a cost was reported.","triggerScenarios":"Passing reportedCostUsd from the provider API response that disagrees with the kernel's catalog price (rounding, tiered pricing, catalog drift); passing reportedCostUsd for an unpriced model; passing NaN/undefined-coerced values.","commonSituations":"Provider changed its prices but the local cost catalog is stale; provider cost includes features (e.g. cached-token discounts) priced differently by the catalog; reporting cost for a model with no catalog entry.","solutions":["Omit options.reportedCostUsd if you don't need to assert the reported cost","Update the library's cost catalog so priced.usd matches current provider pricing","Compare your reported cost to priced.usd locally and reconcile rounding before calling","If the cost is genuinely provider-computed, stop enforcing the catalog comparison and record it separately"],"exampleFix":"// before\nkernel.priced(evidence, { reportedCostUsd: 0.0045 }); // catalog says 0.0030\n// after\nkernel.priced(evidence, { reportedCostUsd: priced.usd }); // or omit reportedCostUsd","handlingStrategy":"try-catch","validationCode":"if (reportedCostUsd !== undefined && (!Number.isFinite(reportedCostUsd) || reportedCostUsd < 0)) throw new Error(\"bad reportedCostUsd\");","typeGuard":"const isValidReportedCost = (c) => typeof c === \"number\" && Number.isFinite(c) && c >= 0;","tryCatchPattern":"try { return kernel.priced(evidence, { reportedCostUsd }); } catch (err) { if (err.message === \"cave_provider_cost_mismatch\") { return kernel.priced(evidence); } throw err; }","preventionTips":["Only pass reportedCostUsd when it should exactly equal catalog pricing","Refresh the cost catalog when provider prices change","Beware float formatting: compare with a tolerance, never string round-trips","Don't report costs for unpriced models"],"tags":["pricing","cost-mismatch","provider-usage"],"backgroundTag":"value-out-of-range","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}