Skip to Content

TGI cost per token

Self-hosted Text Generation Inference does not bill per token on an invoice — you pay GPU-hours, power, and engineer time. To compare fairly against cloud APIs, convert both sides to cost per outcome or cost per million tokens at your actual utilization.

This page answers the queries behind high-impression TGI landing pages: “text generation inference cost,” “TGI vs OpenAI pricing,” and “when does self-hosting break even.”

Two cost models

ModelWhat you payRisk
Cloud APIInput + output tokens × list priceSpiky traffic; frontier model drift
TGI on GPUGPU $/hr × wall-clock utilizationIdle GPUs; ops incidents; upgrade churn

Cloud APIs win at low volume and high model churn. TGI wins when QPS is steady, model choice is stable, and GPU utilization stays high.

Worked example: 8B instruct tier

Assume Llama 3.1 8B on one A100 80 GB at $2.50/hr (typical cloud GPU rental — adjust to your contract).

Rough throughput for chat at batch size 8: ~3,000–6,000 output tokens/minute depending on context length and batching (measure on your stack — do not trust generic benchmarks).

MetricCalculationResult (illustrative)
Output tokens per hour4,000 tok/min × 60~240M tok/hr at peak
Cost per 1M output tokens$2.50 / 240~$0.01/M out
At 50% GPU utilizationDouble effective $/M~$0.02/M out

Compare to cloud list (check current rates on Narev  or provider dashboards):

Provider / model (indicative)Output $/M tokens
GPT-4o mini~$0.60
Claude Haiku 3.5~$1.25
Llama 3.1 8B on major APIs~$0.08–0.20

At high utilization, TGI on rented A100 often beats frontier APIs by an order of magnitude on output tokens. At 10% utilization (one dev GPU running two hours a day), the same math yields ~$0.10/M out — cloud mid-tier APIs can be cheaper because you are not amortizing idle silicon.

Break-even checklist

TGI is likely cheaper when all of these are true:

  1. Steady QPS — not just occasional IDE experiments (Ollama fits spiky dev better)
  2. Utilization > 40% on the GPU serving TGI — measure with nvidia-smi and Observability
  3. Stable model — re-tuning VRAM and redeploying every week erases savings
  4. Quality bar met — failed local attempts that escalate to cloud add hidden API cost (Article II)
  5. Ops cost included — on-call, image upgrades, HF token rotation (Support)

If any item fails, run the hybrid pattern: local draft on Ollama, production on TGI or cloud.

Input vs output on self-hosted stacks

Cloud APIs often charge input tokens heavily. TGI cost is mostly wall-clock on GPU — long prompts still cost compute during prefill, but there is no separate input list price.

PatternCloud API impactTGI impact
Bloated RAG context every turnHigh input $Longer prefill, lower max concurrency
Agent loops (20+ turns)Input + output stackSame GPU hour, worse queue depth
Short prompts, long completionsOutput-weightedFavorable for batching

Trim retrieval before inference per Output and RAG. Cap max_tokens in clients and on the TGI server.

Managed TGI vs self-managed

OptionCost shapeWhen it wins
HF Inference Endpoints Per-GPU-hour + HF markupFast prod without K8s team
Self-managed TGI on K8sGPU + cluster + engineerHigh scale, custom networking
Cloud APIPer tokenLow volume, frontier models

Meter managed endpoints like cloud APIs. Meter self-managed TGI like owned or rented GPU capacity.

Hidden costs teams forget

CostWhy it matters
Idle GPU24/7 node that serves 2 hrs/day multiplies $/token
Weight pull timeHub downloads on every cold start — use PVC cache (K8s)
Failed quant deployTrial FP8 on A100 → rollback → engineer time
Quality regressionCloud escalation after bad local merges
PowerOn-prem: add ~$0.10–0.30/kWh × GPU TDP to hourly math

Compare engines fairly

Before standardizing on TGI, benchmark measured $/M tokens at your QPS against vLLM on the same GPU and model. Throughput differences of 20–40% directly change break-even. Hugging Face now positions vLLM  and SGLang for many new deployments; TGI remains valid for Hub-native K8s stacks already in production — pick on numbers, not logo preference.

Instrumentation

Tag every client call:

span.setAttribute("inference.backend", "tgi"); span.setAttribute("inference.gpu_hour_rate", 2.5); span.setAttribute("llm.usage.output_tokens", usage.completion_tokens);

Divide allocated GPU cost by summed output tokens weekly per feature tag. That is your real cost per outcome input for routing decisions.

See Observability for Prometheus metrics (tgi_batch_current_size, queue depth) that explain utilization swings.

Last updated on