AIF-80Recommended
Price each image or video job before it starts
Estimate the cost of each image or video job from its size, length and count before you send it. Refuse a job over the per-job limit, and count it against the user's budget.
How to do it
One video request can cost more than thousands of text calls, and a retry loop multiplies it. Compute the price from the provider's rates for resolution, seconds and number of outputs, in the gateway's price table. Show the user the cost in credits before a large job. Charge the estimate against the daily budget in price every model call and cap the spend before the call, then settle the actual cost after. Run long video jobs as background jobs with a status, not inside a web request.
Examples
TypeScript example
export function estimateVideoUsd(job: VideoJob, rates: VideoRates): number {
return job.seconds * job.count * rates.usdPerSecond[job.resolution];
}
if (estimateVideoUsd(job, rates) > MAX_JOB_USD) throw new JobTooExpensive();
await budgets.reserve(user.id, estimateVideoUsd(job, rates));
Python example
def estimate_video_usd(job: VideoJob, rates: VideoRates) -> float:
return job.seconds * job.count * rates.usd_per_second[job.resolution]
if estimate_video_usd(job, rates) > MAX_JOB_USD:
raise JobTooExpensive()
budgets.reserve(user.id, estimate_video_usd(job, rates))
How to check
A test submits a job priced above the per-job limit and one that would pass the user's daily budget. Both are refused before any provider call. A job under both limits records its estimated and its actual cost.
Sources
Related rules
- AIF-42 Price every model call and cap the spend in AI features
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/image-and-video-generation/media-job-cost">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.