Per-Second AI API Billing: How to Break Down Your Real Costs

    As generative AI moves from chatbots to coding, document processing, data analysis, and automated agents, API pricing has grown far more complex. Many services bill separately for input tokens, output tokens, cached input, and even audio duration, video length, or real-time session time. A headline rate of "a few cents per second" can make costs look trivially low—but in production, your bill is rarely determined by duration alone. This article breaks down the true cost of a single model call, shows how to convert per-second pricing into a monthly budget, explains how to estimate token-based bills, and outlines six engineering practices plus key metrics for keeping AI costs under control before scale exposes them.

    Per-Second AI API Billing: How to Break Down Your Real Costs

    As generative AI services expand from simple chat into code generation, document processing, data analysis, and automated task execution, pricing models have become increasingly complex. Many providers charge separately for input tokens, output tokens, and cached input—and some add billing based on audio duration, video length, or real-time session time.

    A quoted rate of “a few cents per second” creates a strong intuitive impression: calling the model seems cheap. But once you move into production, costs are usually not determined by surface-level duration alone.

    To answer “how is the bill actually calculated,” you need to decompose a single model call into independent components: input content, output content, internal reasoning, cache hits, request duration, and concurrency scale. Only by quantifying each factor separately can you arrive at a result that resembles your real invoice.

    1. Per-Second Billing Is Not Just About Call Duration

    “Per-second pricing” typically applies to real-time voice, video understanding, continuous conversations, or streaming agents. The system charges based on session duration, media processing time, or live connection time. But for text models and multimodal models, the underlying cost is still often tied to token counts.

    A token is the smallest semantic unit a model uses to process text. Chinese, English, numbers, code, and punctuation are all tokenized differently, so character counts cannot be directly equated with token counts. The base cost of a request can be abstracted as:

    1. Total cost =
    2. input tokens × input price
    3. + output tokens × output price
    4. + cached tokens × cache price
    5. + other media or real-time processing fees

    For per-second billed real-time applications, you also need to add:

    1. Real-time cost = session duration × per-second price

    However, these two formulas do not replace each other. Some real-time applications generate both continuous connection fees and additional charges for transcription, model generation, or multimodal analysis. So your project budget cannot simply be “per-second price × usage time”—you must first confirm whether billing dimensions stack.

    2. The Cost Anatomy of a Complete Request

    2.1 Input Token Costs

    Input tokens include system instructions, conversation history, the user’s current question, retrieval results, tool call outputs, and text extracted from uploaded files.

    In many applications, the input payload is far larger than what the user visibly types. A Q&A system might appear to receive only a few dozen words, while the backend attaches:

    • A long system prompt;
    • Multiple rounds of conversation history;
    • User profiles and permission data;
    • Multiple retrieved document chunks;
    • Tool call results;
    • Format constraints and output examples.

    The most effective way to reduce input cost is therefore usually not shortening the user’s question, but controlling context bloat. Techniques such as conversation summarization, document chunking, relevance filtering, and dynamic prompt assembly can prevent every request from resending the full background.

    2.2 Output Token Costs

    Output tokens are typically priced higher than input tokens, especially for tasks involving deep reasoning, long-form summaries, or code generation. Output length is driven jointly by prompt requirements, reasoning depth, response format, and task complexity.

    For the same question, asking for “conclusions only” might generate a few dozen tokens; asking for “step-by-step explanations, multiple options, complete code, and error handling” can cause output volume to explode.

    Production systems should define explicit output boundaries, for example:

    1. Return JSON only, containing exactly three fields: summary, risk, and next_step.
    2. Each field must not exceed 200 characters.

    Such constraints not only make parsing easier but also prevent the model from producing redundant content when no clear goal is defined.

    2.3 Cached Input Costs

    For workloads with heavy repetition, caching is a key lever for reducing costs. Typical cacheable content includes fixed system prompts, long-lived knowledge base prefixes, shared business rules, and common documents.

    If the service supports input caching, repeated context is usually billed at a lower rate. But caching is not “permanently free”—you still need to watch cache TTLs, hit conditions, and minimum cache sizes. If the prefix content changes, or dynamic content is inserted in a way that breaks the shared prefix, cache savings can drop sharply.

    When designing prompts, place stable content first and put variable content—user questions, current timestamps, random identifiers—afterward to maximize prefix reuse.

    2.4 Hidden Costs of Reasoning Depth

    Many newer models offer different reasoning or “thinking” tiers. Low tiers suit simple tasks like classification, extraction, and rewriting; high tiers suit complex planning, code analysis, and multi-step decisions.

    Higher reasoning depth consumes more internal compute, resulting in longer response times and higher output-related overhead. In practice, don’t default every request to the highest tier—tier by task difficulty instead:

    • Simple format conversion: low-complexity configuration;
    • Standard Q&A and summarization: medium configuration;
    • Complex code analysis and multi-step planning: higher configuration;
    • High-risk decisions: add human review rather than simply raising the model tier.

    The best strategy is not “the strongest model,” but “the minimum effective capability the task requires.”

    3. Converting Per-Second Pricing into a Monthly Budget

    Suppose a real-time service costs $0.1 per second, and one user spends 10 minutes per day over 30 days:

    1. Monthly duration per user = 10 × 60 × 30 = 18,000 seconds
    2. Monthly cost per user = 18,000 × 0.1 = $1,800

    This shows how a tiny unit price can compound into very high cumulative costs under sustained usage.

    With 100 users, each spending 10 minutes per day:

    1. Total monthly cost = 1,800 × 100 = $180,000

    Of course, a real invoice also involves concurrency, idle connections, peak traffic, failed retries, cache discounts, and different request types. A more robust budget formula is:

    1. Monthly budget =
    2. DAU
    3. × average effective daily usage per user
    4. × billing rate
    5. × days in use
    6. × peak-and-retry adjustment factor

    The adjustment factor covers network retries, timeout retries, test traffic, and admin console calls. Without this buffer, budgets tend to underestimate actual spend.

    4. How to Estimate a Token-Based Bill

    For text or multimodal requests, build a simple per-request cost model:

    1. Request cost =
    2. (input_tokens / 1,000,000) × input_price
    3. + (output_tokens / 1,000,000) × output_price
    4. + (cached_tokens / 1,000,000) × cache_price

    For example, a request with 20,000 input tokens and 3,000 output tokens, where 15,000 input tokens hit the cache, can be priced by plugging each token category into the rate sheet.

    Note that input tokens and cached tokens must not be double-counted. If cached tokens are broken out separately from regular input tokens, the regular input portion is:

    1. Effective regular input tokens = total input tokens − cached tokens

    In engineering practice, log the following fields for every request:

    • Request timestamp;
    • Business scenario;
    • Input token count;
    • Output token count;
    • Cached token count;
    • Response latency;
    • Whether a retry occurred;
    • Model configuration or reasoning tier;
    • User or tenant identifier;
    • Request result status.

    With this data, you can generate cost reports by user, team, API endpoint, feature module, and time period—instead of facing one unexplainable total at the end of the month.

    5. A Bigger Context Window Doesn’t Mean You Should Fill It

    Larger context windows let a model process longer documents and more history in one pass, but “stuffing in more” is not automatically better. Longer context typically creates three problems.

    First, input costs rise. Even if the user only cares about a small section of a document, resending the full text every time keeps driving costs up.

    Second, latency increases. The model must read and process more content, which can degrade real-time interaction.

    Third, information interference grows. The more irrelevant passages present, the more likely the model is to overlook the constraints that actually matter, causing answers to drift off target.

    Large context windows are best suited to long-document analysis, cross-section comparison, and complex multi-task workflows. Routine Q&A should still rely on retrieval, summarization, and chunking. In practice, use low-cost methods to filter for relevant content first, then pass a small set of high-relevance chunks to a high-capability model.

    6. Six Engineering Practices to Cut Costs

    6.1 Tier Your Models

    Classify tasks as simple, standard, or complex, and assign capability levels accordingly. Don’t use expensive models for trivial tasks—and don’t force complex tasks onto weak models with endless retries.

    6.2 Control Output Length

    Specify fields, length limits, and format requirements to avoid meaningless explanatory text. For machine-consumed results, prefer structured output.

    6.3 Optimize Context

    Keep only history and document chunks relevant to the current task. Summarize long conversations periodically rather than appending raw messages indefinitely.

    6.4 Maximize Cache Hit Rates

    Place stable prompts, shared rules, and fixed background content in reusable regions, and keep dynamic content from breaking the shared prefix.

    6.5 Reduce Wasteful Retries

    Distinguish between timeouts, rate limits, service errors, and business errors. Only retry transient failures, using exponential backoff with a maximum retry count.

    6.6 Set Budgets and Alerts

    Define daily budgets, monthly budgets, and per-user quotas for each application. When token consumption, session duration, or error rates spike, trigger alerts and automatically degrade gracefully.

    7. Metrics to Validate Before Launch

    Cost optimization can’t focus on price alone—you must also track quality and experience. At minimum, monitor:

    • Average cost per request;
    • Average monthly cost per user;
    • Input-to-output token ratio;
    • Cache hit rate;
    • Average response time;
    • Time to first byte;
    • Request success rate;
    • Retry rate;
    • User satisfaction;
    • Task completion rate.

    If costs drop because answer quality deteriorates, manual rework increases, or task failure rates climb, that’s not real savings. The right benchmark is: within acceptable quality and latency thresholds, is the cost per unit of business outcome going down?

    Conclusion

    Per-second billing is just one surface expression of AI service pricing. What actually determines cost is the combined effect of call duration, token volume, caching strategy, context organization, model tier, and retry mechanisms. For individual developers, the priority is building the ability to estimate the cost of a single call. For enterprise teams, it means going further: usage analytics, budget controls, tiered routing, and anomaly alerting.

    Break “how much per second” down into “how much per user, per request, and per task,” and you can truly see the economics of your AI application—and catch cost blowups before your product scales.