n4nAI

Self-hosting Mixtral 8x7B: latency vs a pay-per-token API

Practical head-to-head: self-hosted Mixtral 8x7B latency vs API across cost, throughput, ergonomics, and scaling limits, with a use-case verdict.

n4n Team3 min read747 words

Audio narration

Coming soon — every post will get a voice note here.

When you evaluate self-hosted Mixtral 8x7B latency vs API offerings, the tradeoffs are not just about raw milliseconds—they span cost structure, operational burden, and scaling ceilings. This post breaks down both paths with concrete deployment numbers and shows where each wins for production traffic.

Comparison at a Glance

Dimension Self-hosted Mixtral 8x7B Pay-per-token API
Capabilities Full weight control, custom quant, fine-tune Fixed weights, provider-updated snapshots
Cost model CAPEX/rental + ops, ~$0 marginal at high util Per-token, no upfront, predictable linear
Single-request latency 50–120 ms TTFT on 2×A100, 20–30 tok/s 200–500 ms TTFT + network, similar decode
Throughput High with continuous batching, limited by VRAM Elastic, but shared fleet tail latency varies
Ergonomics Docker/vLLM, autoscaling, monitoring to build One OpenAI-compatible endpoint, metering built-in
Ecosystem LangChain local, your own fallback logic Multi-model routing, cache hints, fallback
Limits VRAM ceiling, single-region Rate limits, provider downtime risk

Capabilities

Both paths run the same sparse MoE weights (46.7B total, 12.9B active per token). Self-hosting lets you swap to GGUF q4_K_M for 24GB GPUs or run fp16 on 2×A100. You can apply your own LoRA or extend context to 64K with rope scaling.

APIs expose a frozen model version. You get the provider’s prompt template and possibly safety filtering. If you need deterministic weights for eval suites, self-host is the only guarantee.

Cost Model

Self-hosting means renting or buying GPUs. A cloud 2×A100-80GB instance runs ~$3–4/hr. At sustained batch load you might push 2–3M tokens/hr through vLLM. That puts your effective cost around $1–2 per million tokens—before engineering time.

APIs charge per token. Public gateways list Mixtral 8x7B near $0.24/M input and output, though rates move. The break-even is roughly 5–10M tokens/month depending on rental region.

# Illustrative break-even (assumes cloud rental, not amortized HW)
rental_per_hr = 3.50
tokens_per_hr = 2_500_000  # generated + context, batched
self_cost_per_M = rental_per_hr * 1000 / (tokens_per_hr / 1e6)
api_cost_per_M = 0.24
print(f"Self-host $/M @ full util: {self_cost_per_M:.2f}")
print(f"API $/M: {api_cost_per_M:.2f}")
# Below full util, self-host cost rises linearly with idle GPU time.

Latency and Throughput

The self-hosted Mixtral 8x7B latency vs API gap is smallest at low concurrency. On 2×A100 with vLLM, a single 128-token prompt returns first token in ~80 ms; decode holds 25 tok/s. Under load, continuous batching lifts aggregate throughput to 400+ tok/s but per-request TTFT can creep to 300 ms.

APIs add network RTT (20–50 ms) and queue time. A typical gateway returns TTFT in 250–450 ms for the same prompt. Decode speed is comparable because the model is identical; the difference is scheduling fairness on shared hardware.

import time, openai
client = openai.OpenAI(base_url="https://api.openrouter.ai/v1", api_key="sk-...")
t0 = time.time()
stream = client.chat.completions.create(
    model="mistralai/mixtral-8x7b-instruct",
    messages=[{"role": "user", "content": "Explain MoE in one sentence."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print("TTFT:", time.time() - t0)
        break

Self-host launch is equally terse but moves the burden elsewhere:

docker run --gpus all -p 8000:8000 \
  vllm/vllm-openai:latest \
  --model mistralai/Mixtral-8x7B-Instruct-v0.1 \
  --tensor-parallel-size 2 --max-model-len 32768

Ergonomics

Self-host gives you a process to watch. You wire Prometheus to vLLM’s /metrics, set up HPA on GPU util, and write your own retry when a node dies. Gateways such as n4n.ai collapse 240+ models behind one OpenAI-compatible endpoint with automatic fallback when a provider is rate-limited or degraded, which removes that operational surface entirely.

With an API you get per-token usage metering and provider cache-control hints forwarded automatically. You still need to handle 429s, but the retry logic is ten lines, not a pager duty roster.

Ecosystem and Tooling

Self-hosted clusters plug into LangChain or LlamaIndex as a local endpoint. You own routing: if Mixtral fails, you fall back to a smaller model in your own code. APIs often support client routing directives—send router: {prefer: "latency"} and the gateway picks a healthy provider. That is powerful when you span Mixtral, Llama-3, and Claude in one app.

Limits and Scaling

A single self-hosted box tops out at its VRAM. Adding a second node means a load balancer and replicated weights; you pay double rent before traffic justifies it. APIs scale horizontally on the provider’s fleet, but you inherit their rate limits and occasional regional outages.

The self-hosted Mixtral 8x7B latency vs API question also touches data residency. Self-host keeps payloads on your VPC; API means trusting the gateway’s transport and subprocessors.

Which to Choose

Prototyping or <5M tokens/month: Use the API. Zero ops, instant model swaps, and the per-token cost is trivial against engineering salary.

Steady >20M tokens/month, predictable load: Self-host on 2×A100 or 4×3090. At that volume the GPU rental pays for itself, and you control tail latency.

Strict data privacy or regulated workloads: Self-host in your own VPC. No amount of API convenience offsets a compliance failure.

Bursty multi-model product: API. Let the gateway handle fallback across 240+ models; building that redundancy in-house is a project, not a config flag.

Latency-critical synchronous UX (e.g., autocomplete): Self-host close to your app region. Cut the network hop and pin TTFT under 100 ms.

If you are deciding between self-hosted Mixtral 8x7B latency vs API, default to API until a token-volume or privacy line is crossed—then buy GPUs with eyes open about the ops tax.

Tagsmixtralself-hosted-llmapi-latencypay-per-token

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All self-hosted vs api performance posts →