{"record":{"id":"40564de172562886","repo":"HeyPuter/puter","slug":"unauthorized-40564d","errorCode":"unauthorized","errorMessage":"Authentication required","messagePattern":"Authentication required","errorType":"http","errorClass":"HttpError","httpStatus":401,"severity":"error","filePath":"src/backend/drivers/ai-video/creditCap.ts","lineNumber":68,"sourceCode":" * cost as slop above the budget. This is the video analogue of the `max_tokens`\n * clamp in `ChatCompletionDriver`: shorten the output to fit the wallet, and\n * only reject outright when even the shortest supported clip is unaffordable.\n *\n * Returns the duration the caller must actually request upstream — callers MUST\n * use the returned value both for the upstream call and for metering, or the\n * cap buys nothing.\n */\nexport async function capSecondsToRemainingCredits({\n    metering,\n    actor,\n    perSecondMicroCents,\n    requestedSeconds,\n    allowedSeconds,\n    minSeconds,\n    modelId,\n}: ICapSecondsParams): Promise<number> {\n    if (!actor) {\n        throw new HttpError(401, 'Authentication required', {\n            legacyCode: 'unauthorized',\n        });\n    }\n\n    // Unpriced or free output — nothing to clamp against.\n    if (!Number.isFinite(perSecondMicroCents) || perSecondMicroCents <= 0) {\n        return requestedSeconds;\n    }\n\n    const remaining = await metering.getRemainingUsage(actor);\n    const affordableSeconds = Math.floor(remaining / perSecondMicroCents);\n\n    const ladder = (allowedSeconds ?? [])\n        .filter((s) => Number.isFinite(s) && s > 0)\n        .sort((a, b) => a - b);\n\n    const usd = (microCents: number) => (microCents / 1e8).toFixed(2);\n    const insufficient = (shortest: number) =>","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-video/creditCap.ts#L50-L86","documentation":"Error \"Authentication required\" thrown in HeyPuter/puter.","triggerScenarios":"Thrown at src/backend/drivers/ai-video/creditCap.ts:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Authenticate the request with a valid user or app token.","Ensure the caller is signed in before invoking the video generation driver."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}