---
title: "Deploy agentgateway"
description: "LLM, MCP, and A2A gateway with Postgres analytics and a built-in UI."
category: "AI/ML"
url: https://railway.com/deploy/agentgateway
---

# Deploy agentgateway

LLM, MCP, and A2A gateway with Postgres analytics and a built-in UI.

**[Deploy agentgateway on Railway](https://railway.com/template/agentgateway)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/agentgateway/manifest.json

- **Creator:** Rakit
- **Category:** AI/ML

## Template content

### agentgateway https://raw.githubusercontent.com/agentgateway/agentgateway/v1.7.0/ui/src/assets/agw-icon.svg

- **Source:** codestorm-official/agentgateway
- **Public domain:** Yes

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

## Documentation

# Deploy and Host agentgateway on Railway

agentgateway is an open-source agentic proxy for AI agents, MCP servers, and A2A traffic. It routes LLM, MCP, and agent-to-agent traffic through one Rust data plane with a built-in admin UI, per-request cost analytics, virtual keys, and budgets — no agent framework lock-in.

## About Hosting agentgateway on Railway

Hosting runs the gateway as one service next to a managed PostgreSQL database. The configuration file is the read-only baseline; every edit made in the admin UI is stored in hybrid mode inside PostgreSQL, so UI changes and analytics survive redeploys without a volume. Each proxied LLM request is logged to Postgres for the cost dashboard and key budgets. The gateway listens on port `4000`, serves the admin UI at `/ui`, and exposes an unauthenticated `/healthz` route for the Railway health check. The UI is locked by default and unlocks with one environment variable holding an htpasswd credential.

## Common Use Cases

- Route Claude, Codex, Cursor, and OpenAI SDK traffic through one gateway with virtual keys and budgets.
- Publish MCP servers behind one authenticated endpoint instead of exposing each server directly.
- Proxy agent-to-agent (A2A) traffic with the same policies, retries, and timeouts as LLM traffic.
- Track per-model spend in the cost dashboard, backed by per-request analytics in PostgreSQL.
- Gate LLM access with API keys, JWT, or OIDC policies configured from the UI or as code.

## Dependencies for agentgateway Hosting

- Official Docker image `cr.agentgateway.dev/agentgateway:v1.7.0` (multi-architecture, about 107 MB), pulled by the Dockerfile.
- One PostgreSQL database (Railway-managed) for hybrid configuration storage, request analytics, and key budgets.
- One public HTTP service on port `4000`; no Redis, cache, or persistent volume is used.

### Implementation Details

**How to sign in.** The admin UI lives at `/ui` and is **locked by default** — anonymous requests get `401`. The gateway stores its login as a hashed credential (htpasswd format), so the hash is generated once on your own machine and pasted into the service variables. Run **one** of these in a local terminal (Linux/macOS/Windows) — pick any password in place of `YOUR-PASSWORD`:

```bash
# Python (works everywhere, including Windows)
python3 -c "import hashlib,base64;print('admin:{SHA}'+base64.b64encode(hashlib.sha1(b'YOUR-PASSWORD').digest()).decode())"

# OpenSSL (Linux/macOS)
printf 'admin:{SHA}%s\n' "$(printf %s 'YOUR-PASSWORD' | openssl dgst -binary -sha1 | base64)"
```

Both print the same single line, for example `admin:{SHA}G60OCdsG1Axvkkzw82yo1QftKps=`. Set that line as the `AGW_UI_HTPASSWD` variable on the service, redeploy, then open `https://YOUR-DOMAIN/ui` and sign in with username **admin** and your chosen password at the browser prompt. Note that Railway's variable editor cannot run commands — the value pasted there must be the generated line, not the command.

Why a generated hash instead of a plain password: Railway's template functions can generate random strings but cannot compute hashes, and agentgateway accepts only hashed credentials for the UI. The `{SHA}` form is used because hash formats containing `$` characters do not survive agentgateway's environment expansion.

**What the gateway exposes.** An unauthenticated `/healthz` route answers `200` for the Railway health check and returns nothing beyond a fixed `healthy` body. The admin interface on the internal loopback port is never exposed; only the gateway port is public.

**Where your configuration lives.** Storage is hybrid: the declarative file is the read-only baseline, and every edit made in the admin UI — routes, backends, keys, policies — is stored in PostgreSQL, so UI changes survive redeploys. Each proxied LLM request is logged to the database for the cost dashboard, per-key budgets, and the Analytics page.

## Comparison with Alternatives

✅ = built-in part of the workflow, ❌ = not available or requires workarounds.

| Capability | This template (agentgateway) | LiteLLM | IBM ContextForge |
| --- | --- | --- | --- |
| LLM proxying with provider keys held on the gateway | ✅ | ✅ | ✅ |
| Native MCP server proxying and routing | ✅ | ❌ (client bridge, not a registry) | ✅ |
| Native A2A (agent-to-agent) protocol support | ✅ | ❌ | ✅ |
| Rust single-binary data plane (~107 MB image) | ✅ | ❌ (Python) | ❌ (Python/FastAPI) |
| UI edits persisted to PostgreSQL across redeploys | ✅ | ❌ (file-based config) | ✅ |
| Hybrid config: Git baseline plus UI edits in the database | ✅ | ❌ | ❌ |
| Runs without Redis | ✅ | ✅ | ❌ (Redis in the default stack) |

Sources: the [agentgateway repository and docs](https://github.com/agentgateway/agentgateway), the [IBM ContextForge repository](https://github.com/IBM/mcp-context-forge), and the [LiteLLM documentation](https://docs.litellm.ai).

## Security Considerations

- The admin UI is locked by default. Anyone who obtains the `AGW_UI_HTPASSWD` value can edit routes and read analytics, so treat it as a credential and never commit it.
- Traffic policies (API keys, JWT, OIDC) are applied per route or gateway — configure one before exposing internal backends publicly.
- `/healthz` is intentionally unauthenticated and returns no data beyond a fixed `healthy` body.
- Railway terminates TLS at the edge. Use OIDC on the UI (supported via `ui.policies`) for organization-grade login instead of the basic-auth bootstrap.
- Keep one replica: hybrid storage and SQLite are single-instance by design; PostgreSQL makes replicas possible, but start simple.

## Why Deploy agentgateway on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying agentgateway on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Because UI configuration is stored in Railway PostgreSQL, a redeploy never loses your routes, keys, or analytics — no volume to manage, nothing to back up by hand.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/agentgateway
