Self-hosting a gateway vs buying a relay service: cost and where each fits
What self-hosting solves
With an open-source gateway such as One API, New API or LiteLLM, running your own relay service gets you three things:
- You hold the data - no third party in the request path
- No rate markup - you pay the official price
- Full control - auth, quotas and logs are all yours to define
All three are genuine value. But the price of them is routinely underestimated.
Visible costs
| Item | Rough order of magnitude |
|---|---|
| Server | A lightweight cloud instance, a few hundred CNY a year |
| Domain and certificate | Tens to hundreds of CNY a year |
| Upstream API spend | At the official price; this is where you save the rate markup |
Looks modest. The real cost comes next.
Hidden costs (this is the important part)
One: obtaining upstream keys
Self-hosting means registering with each vendor's platform yourself, completing identity checks and attaching a payment method.
How hard that is varies by vendor: some want an overseas credit card, some want company credentials. If the reason you went to a relay service in the first place was "I have no way to pay overseas", self-hosting stalls right here.
Two: the cost of designing for high availability
A single-instance gateway that dies takes everything down. High availability means dealing with:
- Multiple instances plus load balancing
- High availability for the database (keys, quotas, logs)
- Health checks and failover across several upstream channels
This is not the complexity of "run one Docker container and you are done".
Three: ongoing maintenance
Upstream interfaces change. Vendors ship new models, adjust protocols, change parameters - and the gateway has to follow. Open-source projects do not always keep pace.
This is a recurring commitment, not a one-off job.
Four: troubleshooting
When something breaks you have to work out yourself whether it is:
- The gateway
- The network on your server
- The upstream
With a relay service there is at least a support desk to ask. When you self-host, there is only you.
The cost boundary
Converting the above into time (at a developer's hourly rate):
Self-hosted cost / month ~ server cost + upstream API spend + maintenance hours x hourly rate
Relay service cost / month ~ usage x official price x rate
A rough guide:
| Monthly API spend | Recommendation |
|---|---|
| Below 1,000 CNY | Use a relay service. Self-hosting costs far more in maintenance than the rate markup saves |
| 1,000 - 5,000 CNY | Depends on the team. If someone can maintain it, self-host; otherwise stay on a relay service |
| Above 5,000 CNY | Self-hosting starts to have a clear edge; the absolute size of the markup is now large |
The decisive variable is whether anyone can maintain it. Without a dedicated person, the hidden costs of self-hosting overtake the benefit quickly.
A middle path
A self-hosted gateway on top of official upstreams, doing only unified auth and quotas - no complex routing:
your app -> self-hosted gateway (One API etc.) -> vendor official APIs
Benefits:
- Data and billing stay in your hands (no third-party relay in between)
- Complexity stays manageable (single instance plus regular backups is acceptable)
- The team shares one key-management setup
Costs:
- No alternative channel when an upstream wobbles (if the official side rate-limits you, you wait)
- You have to track interface changes yourself
This suits teams with moderate data sensitivity and some technical capacity.
When not to self-host
- Nobody on the team can maintain it over time
- Obtaining upstream keys is itself blocked (no way to pay overseas, for example)
- Usage is small enough that the savings do not cover the investment
- What you need is to validate an idea quickly, not long-term infrastructure
That last one is very common: self-hosting a gateway before the product is validated puts your time in the wrong place.
Related reading
- Official API vs relay service: where the difference really lies
- Who handles your request: the data boundaries inside a relay chain
- Specialist vs aggregator relay services: when a specialist is the better deal
Was this useful? If you have run into something the article does not cover, tell us and we will verify it and update the text.
Related articles
Video generation behind a relay: three API shapes, four billing traps, one acceptance checklist
MCP through a relay: what works, what never will, and how to test it in ten minutes
A relay selection decision tree: working back from your scenario to a site
Logging and reconciliation: attributing token spend to the project level
Migrating suppliers gradually: replacing an API site without interrupting service
Build your own probe: twenty lines of script to monitor your API suppliers
Read on: a few of the services we list
This article does not point at a specific model family, so here are a few of the highest-scoring services we list, in case you want to read on. They are ordered by score and uptime and are not a recommendation.
See the full list in the directory, or browse by model family.