API Pricing and Cost Optimization
AI API cost estimation starts with the billing unit
Understand single token rates, separate input/output rates, images and audio units without mixing upstream pricing with gateway billing.
Estimate AI API cost from the price and the exact unit that your gateway bills. A price without a unit is incomplete. A gateway’s single rate per million billed tokens must not be silently relabeled as an upstream provider’s separate input or output rate.
AIx publishes configured prices in its public billing catalog. The website’s static values are snapshots verified on October 21, 2026. Always check current prices before purchase. This article explains arithmetic rather than promising a particular monthly bill.
Identify the pricing contract first
The inspected AIx implementation applies a single configured chat rate to billed tokens. Other APIs can use separate input and output rates, cache rates or additional charges. Those are different contracts even when both websites display a figure followed by “per million tokens.”
| Billing contract | Calculation |
|---|---|
| One rate per million billed tokens | billed tokens × rate ÷ 1,000,000 |
| Separate input and output rates | input tokens × input rate ÷ 1,000,000 + output tokens × output rate ÷ 1,000,000 |
| Per image | billable images × per-image rate |
| Per minute | billable minutes × per-minute rate |
These formulas do not establish how an unknown service counts units or rounds money. Read its contract. For AIx-specific settlement behavior, use the billing model reference.
A transparent hypothetical calculation
Suppose a service bills 2,000 total tokens at a hypothetical rate of $3 per million billed tokens. The arithmetic is 2000 × 3 / 1000000 = $0.006. These are illustrative inputs, not an AIx price quote or a measured request.
Now suppose another service charges $1 per million input tokens and $5 per million output tokens. A request with 1,500 input tokens and 500 output tokens costs $0.0015 + $0.0025 = $0.004 before any other charges. Comparing $3 to $1 alone would have hidden the output rate.
You can check arithmetic locally with the following JavaScript function. It accepts explicit units and rejects negative or non-finite numbers instead of guessing what the caller meant.
export function tokenCost(tokens, usdPerMillion) {
if (![tokens, usdPerMillion].every(Number.isFinite) || tokens < 0 || usdPerMillion < 0) {
throw new TypeError('Expected non-negative finite token count and USD rate');
}
return (tokens * usdPerMillion) / 1_000_000;
}
The function is an estimator. It does not reproduce a service’s reservation logic, minimum charge, currency conversion or rounding rules. For financial reconciliation, use actual billed records and the service’s documented precision.
Estimate distributions, not one average prompt
Separate short interactive questions, long document requests and background jobs. Record input size, output size, repeated attempts and model selection for each workload using privacy-conscious aggregate data. A small number of long requests may dominate the bill even when the median request is short.
Report assumptions: requests per day, expected token range, retry behavior and the verification date of each price. Use low, typical and high scenarios. Avoid presenting a single monthly estimate as a guarantee.
A context window is a capacity limit rather than a per-request cost. Sending less than the maximum still consumes billable work, and an output limit is not the same as a verified output size. Treat unverified context figures as unknown rather than building a budget around them.
Keep billing listings separate from model verification
A catalog can establish a configured model name, modality, price and unit. It does not establish the identity of the upstream deployment, its context window or successful inference. The verification guide explains this boundary.
For comparisons, record both APIs’ units and dates, use comparable request shapes, and disclose missing data. Do not claim one service is cheaper merely because one headline number is smaller. Do not use a static snapshot to assert a permanent price advantage.
Prevent price drift in your application
Keep commercial facts in one registry and derive tables, model pages and machine-readable summaries from it. Fail validation when a model identifier is missing or a numeric price has changed unexpectedly. Review snapshot refreshes as content changes rather than quietly substituting fallback prices.
At runtime, preserve a clearly labeled snapshot if a live catalog is unavailable. Never display zero merely because parsing failed. A missing price is unknown; it is not free.
References and verification
- AIx public billing catalog — checked
- Kong AI Gateway model cost management — checked
Reviewed 2026-10-21: Repository contract inspection and editorial review; executable examples use controlled mocks. No authenticated inference, billing benchmark or independent upstream verification.