LiteLLM is an open-source AI gateway. It puts one OpenAI-compatible API in front of many model providers, and adds virtual keys, budgets and an admin UI. Self-hosting it on Google Cloud comes down to one container on Cloud Run, a PostgreSQL database, three secrets and some networking, with Vertex AI behind it for the models.
None of it is hard. Most of it has one way that works and two that nearly do. This covers what LiteLLM is, the shape of a setup that held up when we built and tested one end to end, and the things that caught us out. It was run against LiteLLM v1.112.2.
What is LiteLLM?
LiteLLM comes in two forms. The Python library lets code call many model providers through one function. The LiteLLM proxy, sometimes called the LiteLLM gateway, is a server you deploy: applications send it OpenAI-style requests, and it forwards them to whichever provider and model you have configured. The proxy is what people mean when they talk about LiteLLM as an AI gateway, and it is what this article is about.
On top of forwarding requests, the proxy gives you:
- Virtual keys. A key per application or team, so provider credentials stay in the gateway.
- Budgets and expiry on each key, with spend tracked per key.
- Model aliases. Applications ask for a name you choose, and you decide which model sits behind it.
- Guardrail integrations, including Google Model Armor.
- An admin UI for keys, teams and usage.
Is LiteLLM free?
The open-source edition is free and MIT licensed, and everything in the list above is in it. There is also a paid Enterprise edition, sold by the LiteLLM vendor, which adds features aimed at larger organisations: different guardrail policies per key or team, admin audit logs, single sign-on for more than five admin users, and controls on routes and request size inside the proxy. The same container image serves both, and a licence key switches the Enterprise features on.
You can run a complete, guarded gateway on the free edition. That is what the rest of this article does.
What you need to self-host LiteLLM on Google Cloud
| Piece | What it is for |
|---|---|
| Cloud Run service | The LiteLLM proxy and admin UI |
| Cloud SQL for PostgreSQL | Virtual keys, budgets, teams and spend |
| Secret Manager | The master key, the salt key and the database password |
| A service account | The identity the proxy runs as, and how it reaches Vertex AI |
| A VPC with private services access | So the proxy can reach the database on a private address |
| Cloud Storage bucket | Holds config.yaml, mounted into the container |
| Cloud Run job | Runs database migrations once per version |
For production, add a global HTTPS load balancer with Cloud Armor in front, and close the service's direct URL.
The order that works on Cloud Run
1. Pin the image by digest. Use ghcr.io/berriai/litellm@sha256:..., not a tag you expect to stay put. The gateway then changes only when you change the digest. Upstream signs its images, so you can verify the one you pinned.
2. Create the service account and grant it Vertex AI. roles/aiplatform.user on the project is enough to call models. The proxy authenticates as this account, so there are no provider API keys anywhere.
3. Build the network before the database. Cloud SQL on a private address needs a VPC with a private services connection. Cloud Run reaches it through Direct VPC egress, which needs a subnet of at least /26.
4. Create the database with no public address. Require TLS. The smallest tier is fine to start.
5. Generate the secrets without putting them in Terraform state. The master key, the salt key and the database password all end up in Secret Manager. With Terraform 1.11 or later, ephemeral values and write-only arguments let you generate and store them without the values ever landing in state. One trap: set the database user's password from the stored secret, not from a second generated value, or an apply that fails part-way and is run again will leave the two out of step.
6. Run migrations as a job. The LiteLLM image has a migrations mode that applies the schema and exits. Run it as a Cloud Run job before the service starts, and set DISABLE_SCHEMA_UPDATE=true on the service so instances do not race each other to migrate at start-up.
7. Deploy the service. Mount the config from the bucket, pass the database host, name and user as environment variables, and reference the secrets rather than copying their values.
A minimal LiteLLM config entry for a Vertex AI model looks like this:
model_list:
- model_name: default
litellm_params:
model: vertex_ai/<model-id>
vertex_project: <project-id>
vertex_location: <region-or-global>
Applications then ask for default, and you decide what sits behind it.
Things that caught us out
Some models are only served from global. A newer Gemini model returned 404 "Publisher model was not found" from a regional location and worked from global. Check where your model is served before you choose a region, and remember that global means prompts may be processed outside it.
The default service URL is public. Cloud Run gives every service a run.app address. For anything beyond evaluation, set ingress to internal and load balancer only, so the only way in is through the load balancer and its rules.
Every proxy endpoint is reachable unless you filter. The proxy exposes far more than chat completions, including its management API. At the load balancer, allow the paths you use and deny the rest. Put the admin UI on a separate host name restricted by source address, and by Google sign-in if you can.
Managed certificates take a while. Google issues the certificate only after your DNS records point at the load balancer. Allow about 40 minutes, and expect HTTPS to fail until then.
Tearing down takes two passes. Cloud Run holds an address in your subnet for up to a couple of hours after a service is deleted, so the subnet cannot be removed straight away. Everything billable is gone by then. Run the destroy again later.
Some settings do nothing on the open-source edition. A request size limit in the proxy config is an Enterprise feature. On the free edition it is ignored and logs a warning. Rely on the platform's own limits instead.
Add LiteLLM guardrails while you are there
A gateway is the natural place to screen prompts and responses, because every request passes through it. On Google Cloud that means Model Armor, and the open-source LiteLLM proxy can call it on every request. The settings, and why failing closed matters, are in LiteLLM guardrails with Model Armor.
What self-hosting LiteLLM costs
The software is free. From Google's list prices on 5 December 2026, in us-central1 and before model inference:
- Evaluation setup (scales to zero, smallest database): about $10 a month idle.
- Production setup (two warm instances, load balancer, Cloud Armor, backups): about $249 a month idle.
The main variable cost is the guardrail, not the proxy. Model inference is usually larger than all of it. These are estimates from list prices, not measured bills.
LiteLLM with Terraform: skip the assembly
Everything above is packaged as a free, open-source Terraform module: the AI gateway for Google Cloud. One terraform apply builds the evaluation setup in about 15 minutes, and a production profile adds the load balancer, the path filtering and the separate admin host. It runs in your own project, and no Agent Ping account is needed. The source is at github.com/agent-ping/terraform-google-ai-gateway.
If you are still deciding whether you need a gateway at all, start with what an AI gateway is.