{"slug": "your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big", "title": "Your LLM gateway takes a cut. Seventeen lines of Python tell you how big.", "summary": "A developer from altrouter.ai released a 17-line Python script that reveals how much AI gateway services mark up or discount token prices compared to vendor list prices. The script reads a gateway's models endpoint and calculates the effective cost for a user's token mix, showing that some gateways undercut vendor prices by 15% or more. The developer emphasizes that gateway pricing varies per model and urges users to check their own token mix rather than benchmarks.", "body_md": "You wanted to try three models from three vendors, so you did the sensible thing: pointed one client at a gateway, put one key in the environment, and stopped thinking about it. A **gateway** here is a service that speaks the OpenAI API and forwards your requests to Anthropic, Google, OpenAI, xAI and the rest, so switching models is a string change instead of a new SDK.\n\nWhat almost nobody checks after that: what the gateway charges for the exact same tokens the vendor would have sold you directly.\n\nThree things, and they are worth very different amounts.\n\n**One key and one invoice.** Real, and boring. It saves you three signups and three billing pages.\n\n**Routing and fallback.** If a provider returns 529 or a region goes dark, the gateway retries elsewhere. Worth something on production traffic, nothing on a weekend project.\n\n**A price per token.** This is the one that varies by an order of magnitude between services, and the one nobody puts in a comparison table — because there is no single \"gateway price\". There is a price per model, and a service can sit below vendor list on one model and far above it on another.\n\nVocabulary, in case it is new: models are billed per **million tokens** (a token is roughly ¾ of a word), input and output priced separately, with output typically 3–10× more expensive. The **list price** is what the vendor publishes on its own pricing page. That list price is your baseline — a gateway is either below it, at it, or taking a markup on top.\n\nMany gateways publish per-model pricing in their models endpoint. If yours does, this reads it and prices out *your* token mix, not a benchmark's:\n\n``` python\nimport json, urllib.request\n\nGATEWAY = \"https://api.altrouter.ai/v1/models/public\"   # your gateway's models endpoint\nLIST = {\"claude-sonnet-5\": (2.00, 10.00), \"gpt-5.6\": (2.50, 15.00)}  # vendor list $/1M in, out\nMIX = (200, 40)  # your monthly millions of tokens: input, output\n\nreq = urllib.request.Request(GATEWAY, headers={\"User-Agent\": \"price-check\"})\nmodels = json.load(urllib.request.urlopen(req))[\"data\"]\n\nfor m in models:\n    inp, out = m[\"pricing\"].get(\"prompt_per_1m_usd\"), m[\"pricing\"].get(\"completion_per_1m_usd\")\n    if m[\"id\"] not in LIST or inp is None:\n        continue\n    li, lo = LIST[m[\"id\"]]\n    mine = MIX[0] * inp + MIX[1] * out\n    vendor = MIX[0] * li + MIX[1] * lo\n    print(f\"{m['id']:<18} gateway ${mine:>8.2f}  list ${vendor:>8.2f}  {mine / vendor - 1:+.1%}\")\n```\n\nRun on 2026-08-14 against the endpoint in the snippet, it prints:\n\n``` bash\ngpt-5.6            gateway $  935.09  list $ 1100.00  -15.0%\nclaude-sonnet-5    gateway $  677.91  list $  800.00  -15.3%\n```\n\nIf your gateway does not publish prices in that endpoint — plenty don't — use the invoice method instead: take last month's charge, divide by the input and output tokens the gateway logged, and you have your real effective $/1M. That number is the only one that matters, and it is the one you compare to the vendor's page.\n\nThe obvious objection: *the mix is made up*. It is — replace `MIX`\n\nwith your own two numbers before you believe any of the output. The ratio between input and output tokens is workload-specific, and since output costs several times more, a chat workload and a document-summarizing workload rank gateways differently.\n\n`base_url`\n\nis genuinely the only change.`usage`\n\nobject in the response. Those are where compatibility usually breaks.Disclosure, since the URL in the snippet is mine: I work on [altrouter.ai](https://altrouter.ai), which is why I could hardcode an endpoint that publishes its prices. It resells vendor models below list — Claude Sonnet 5 at $1.69 / $8.50 per 1M against the official $2.00 / $10.00, Opus 4.5 at $3.74 / $18.75 against $5.00 / $25.00, discounts running 10–25% by model, prices as of August 2026. Point the script at whatever you use now; the arithmetic does not care.\n\nPrice, and only price. The script says nothing about latency, uptime, rate limits, or whether prompt caching is passed through at the vendor's discount — check that separately, it can outweigh a 15% price gap. And the honest gaps on my side: no embedding models, no data residency options, no SLA of our own beyond the upstream vendor's. If you are on one vendor and never plan to leave, buy direct — you save exactly the middleman's margin.\n\nRun the seventeen lines on your own gateway this week. Whatever the number is, it is better to know it than to assume the convenience was free.", "url": "https://wpnews.pro/news/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big", "canonical_source": "https://dev.to/altrouter/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big-45jc", "published_at": "2026-08-14 05:18:57+00:00", "updated_at": "2026-08-14 05:45:57.553251+00:00", "lang": "en", "topics": ["ai-infrastructure", "developer-tools", "artificial-intelligence"], "entities": ["altrouter.ai", "Anthropic", "Google", "OpenAI", "xAI", "Claude Sonnet 5", "Opus 4.5"], "alternates": {"html": "https://wpnews.pro/news/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big", "markdown": "https://wpnews.pro/news/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big.md", "text": "https://wpnews.pro/news/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big.txt", "jsonld": "https://wpnews.pro/news/your-llm-gateway-takes-a-cut-seventeen-lines-of-python-tell-you-how-big.jsonld"}}