The AI ExchangePractical AI community
Menu

Lesson 7 / 14

API Versus Self-Hosting Costs

Compare total costs rather than only the advertised price per token or GPU hour.

By the end of this lesson, you will be able to:

  • Calculate API spend from request volume and token counts.
  • Build a comparable monthly self-hosting cost estimate.
  • Recognize where utilization, reliability and hidden costs change the result.

1. Decide what counts as one completed task

A token is a unit of text or other model input/output metering; it is not the same as a word. API services often meter input and output separately, and rates may vary by model, context size, caching or service features. Compare providers using their current official terms and the same real workload. Do not divide an advertised rate by a guess at average usage and call it a complete budget.

Choose a unit the business understands: correctly categorized ticket, validated extracted invoice or approved draft. Some requests fail and must be retried. A single finished task may require several requests, retrieval calls or human review. Price per million tokens tells you something about infrastructure; cost per accepted task tells you whether the workflow makes financial sense.

2. Calculate the monthly API estimate

A starting formula is: requests per month × ((average input tokens × input price per million) + (average output tokens × output price per million)) ÷ 1,000,000. Treat the result as a baseline. Add additional requests caused by retries, cached-versus-uncached usage, embeddings, retrieval, tool execution, storage, data transfer and any minimum charges that your provider applies.

Measure actual token distributions when possible. Median usage can hide a few huge documents or long reasoning traces that dominate the bill. Consider a normal month and a heavy month, and make sure the model remains within rate limits during peaks. Provider billing dashboards and a request log with sensitive content removed are more reliable than estimates based on one prompt.

3. Calculate self-hosting with utilization

A starting self-hosting estimate is GPU hourly charge × reserved hours + engineering/operations + network, storage, monitoring and other expenses. If you reserve a GPU continuously, the charge can continue while the model is idle. If you turn it off between jobs, add startup delay and the operational design needed to queue work. Do not assume one GPU can serve unlimited requests; run throughput tests with the target context length and concurrent users.

Self-hosting also transfers responsibility for patches, security incidents, backup configuration, failure recovery, scaling and model regressions. A lower raw inference cost may be cancelled by maintenance time or lower availability. If your workload has large peaks, compare elasticity as well as average monthly totals. A realistic decision should include a break-even calculation and a quality gate.

4. Stress-test the assumptions

Change one variable at a time: requests, average tokens, retry rate, GPU hours or hourly price. The calculator below accepts your own rates; its starting zero prices are placeholders, not current vendor quotes. Record the date and source of each price you enter. A result showing one option as cheaper does not imply it meets quality, latency or privacy requirements.

Worked example

Worked example: a simple monthly estimate

The following prices are hypothetical teaching inputs, not quotes: 10,000 requests/month, 1,500 input tokens and 500 output tokens each, $2/million input and $8/million output. A dedicated GPU is hypothetically $1.50/hour for 730 hours, plus $300/month in operations.

  1. API input = 10,000 × 1,500 × $2 ÷ 1,000,000 = $30; output = 10,000 × 500 × $8 ÷ 1,000,000 = $40.
  2. Baseline API total is $70/month. If 5% extra full requests are needed, illustrative API usage becomes $73.50, excluding other fees.
  3. Self-hosting reservation = 730 × $1.50 + $300 = $1,395/month, before other costs. This assumes one GPU actually handles the workload.

At these hypothetical inputs, API usage is cheaper. That does not prove the same result at 100 times the traffic or for a different model; GPU capacity and API costs would both need to be remeasured.

Calculator: API or self-hosting

Enter verified provider rates. Initial price values are zero and do not represent actual offers.

Estimated monthly API cost

$0.00

Estimated monthly self-hosted cost

$0.00

Simplified model. Excludes retries, storage, tools, data transfer, hardware purchases, taxes, and usage variation unless entered under other costs. Compare quality and availability as well as price.

Check your understanding

Why could a low advertised GPU hourly price still lead to a high monthly bill?

Apply what you learned

Cost experiment

  1. Estimate monthly requests, average tokens, retries, and peak demand.

Discuss this lesson

Read discussions freely. A free account is needed only to post or reply.

Open forum →