{"record":{"id":"b6f5ef4a9b9d3168","repo":"paperclipai/paperclip","slug":"estimated-cost-limit-exceeded","errorCode":null,"errorMessage":"estimated cost limit exceeded","messagePattern":"estimated cost limit exceeded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/paperclip-runner/src/cli/eval-session.ts","lineNumber":249,"sourceCode":"  }\n}\n\nexport function boundedEvalSessionUsage(\n  request: EvalSessionRequest,\n  turn: CapabilityLiveTurnResult,\n): EvalSessionUsage | null {\n  if (turn.status !== \"completed\") {\n    return usageIfAvailable(request, turn.snapshot);\n  }\n  const usage = evalSessionUsage(request.model, turn.snapshot);\n  if (usage.agentTurns > request.limits.maxAgentTurns) {\n    throw new Error(\"agent turn limit exceeded\");\n  }\n  if (\n    usage.estimatedCostNanodollars >\n    request.limits.maxEstimatedCostNanodollars\n  ) {\n    throw new Error(\"estimated cost limit exceeded\");\n  }\n  if (\n    usage.providerReportedCostNanodollars >\n    request.limits.maxEstimatedCostNanodollars\n  ) {\n    throw new Error(\"provider-reported cost limit exceeded\");\n  }\n  return usage;\n}\n\nasync function closeSession(\n  session: CapabilityLiveSession | null,\n  reason: string,\n): Promise<void> {\n  if (session === null || session.snapshot().status === \"closed\") return;\n  await session.shutdown(reason);\n}\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/paperclip-runner/src/cli/eval-session.ts#L231-L267","documentation":"runEvalSessionCli enforces a cost ceiling after the provider turn completes. evalSessionUsage derives estimatedCostNanodollars from token usage in the turn snapshot; if it exceeds request.limits.maxEstimatedCostNanodollars the run is aborted so an eval session cannot silently overspend.","triggerScenarios":"usage.estimatedCostNanodollars > request.limits.maxEstimatedCostNanodollars in runEvalSessionCli — i.e. the estimated (token-derived) cost of the completed turn exceeded the configured budget.","commonSituations":"maxEstimatedCostNanodollars set too low for the model's token pricing; long prompts or large tool outputs inflating token counts; switching to a more expensive model without raising the limit; unit mistakes (nanodollars vs dollars) when configuring limits.","solutions":["Raise request.limits.maxEstimatedCostNanodollars to match the model's expected cost","Use a cheaper model/requestedModel for the eval","Reduce prompt/output size (trim context, cap tool outputs)","Verify the nanodollar arithmetic — 1 dollar = 1e9 nanodollars — when setting limits"],"exampleFix":"// before\nlimits: { maxEstimatedCostNanodollars: 1_000_000, ... } // $0.001\n// after\nlimits: { maxEstimatedCostNanodollars: 100_000_000, ... } // $0.10","handlingStrategy":"validation","validationCode":"// Estimate cost before the run and pre-validate the budget\nconst maxPromptTokens = request.prompt.length / 4;\nconst worstCaseTokens = (maxPromptTokens + 10_000) * request.limits.maxAgentTurns;\nconst worstCaseNanodollars = worstCaseTokens * pricePerTokenNanodollars(request.model);\nif (worstCaseNanodollars > request.limits.maxEstimatedCostNanodollars) {\n  throw new Error(`budget ${request.limits.maxEstimatedCostNanodollars} nd too low; worst case ~${worstCaseNanodollars} nd`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runEvalSessionCli(request, cli);\n} catch (error) {\n  if (error instanceof Error && error.message === \"estimated cost limit exceeded\") {\n    console.error(`cost cap hit: estimated=${usage.estimatedCostNanodollars} nd, cap=${request.limits.maxEstimatedCostNanodollars} nd`);\n    // raise cap or downgrade model, then retry\n  }\n  throw error;\n}","preventionTips":["Compute nanodollar limits from the model's published per-token price (1 USD = 1e9 nd)","Set the cost cap above the max-turns worst case, not the expected case","Downgrade the model instead of the cap when a budget is hard"],"tags":["limit","cost","budget"],"backgroundTag":"cost-limit-exceeded","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}