{"id":51103016,"url":"https://github.com/sukhrobnurali/relay-gateway","last_synced_at":"2026-06-24T12:30:56.767Z","repository":{"id":366123160,"uuid":"1234130829","full_name":"sukhrobnurali/relay-gateway","owner":"sukhrobnurali","description":"OpenAI-compatible gateway for self-hosted LLMs (vLLM, Ollama) with cloud fallback. Per-key auth, Redis sliding-window rate limits, structured logs, prometheus metrics.","archived":false,"fork":false,"pushed_at":"2026-05-09T19:58:48.000Z","size":197,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-20T11:32:40.775Z","etag":null,"topics":["fastapi","gateway","llm","ollama","openai-api","self-hosted","vllm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sukhrobnurali.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-09T19:39:41.000Z","updated_at":"2026-05-09T20:04:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sukhrobnurali/relay-gateway","commit_stats":null,"previous_names":["sukhrobnurali/relay-gateway"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sukhrobnurali/relay-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukhrobnurali%2Frelay-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukhrobnurali%2Frelay-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukhrobnurali%2Frelay-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukhrobnurali%2Frelay-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sukhrobnurali","download_url":"https://codeload.github.com/sukhrobnurali/relay-gateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukhrobnurali%2Frelay-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34733256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","gateway","llm","ollama","openai-api","self-hosted","vllm"],"created_at":"2026-06-24T12:30:55.869Z","updated_at":"2026-06-24T12:30:56.758Z","avatar_url":"https://github.com/sukhrobnurali.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# relay-gateway\n\n[![CI](https://github.com/sukhrobnurali/relay-gateway/actions/workflows/ci.yml/badge.svg)](https://github.com/sukhrobnurali/relay-gateway/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)\n[![Python](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/)\n[![Container](https://img.shields.io/badge/ghcr.io-relay--gateway-1f6feb)](https://github.com/sukhrobnurali/relay-gateway/pkgs/container/relay-gateway)\n\n\u003e Self-hosted-first, OpenAI-compatible gateway for **vLLM**, **Ollama**, and cloud fallback.\n\u003e Auth, rate limiting, multi-backend routing, observability — one `docker compose up`.\n\n## What it does\n\nMost teams running open-source LLMs end up writing the same boring wrapper\naround their inference servers: an OpenAI-compatible HTTP front, API-key\nauth, per-key rate limits, request logs, prometheus metrics, a routing\ntable from \"friendly model name\" to upstream, and a way to fall back to a\ncloud provider when local is busy.\n\n`relay-gateway` is that wrapper, small enough to read in a sitting:\n\n```\nclients (OpenAI SDK, curl, langchain, ...)\n        │\n        ▼\n┌─────────────────────────────────────────────┐\n│ FastAPI app (auth → ratelimit → routing)    │\n│  - bearer token + per-key model scopes      │\n│  - sliding-window rpm/tpm in Redis (Lua)    │\n│  - prometheus /metrics, structlog access    │\n└─────────────────────────────────────────────┘\n        │           │             │\n        ▼           ▼             ▼\n   vLLM (local)   Ollama       OpenAI (cloud fallback)\n```\n\nIt is **deliberately not** a 100-provider gateway. It does vLLM and\nOllama well, treats OpenAI as a passthrough fallback, and stops there.\nFor a wider provider set see the [landscape doc](docs/landscape.md).\n\n## How it compares\n\n|                         | relay-gateway | LiteLLM Proxy | Portkey | OpenRouter |\n|-------------------------|---------------|---------------|---------|------------|\n| Self-hosted-first       | yes           | yes           | yes     | no         |\n| OpenAI-compatible API   | yes           | yes           | yes     | yes        |\n| vLLM + Ollama focus     | yes           | yes (general) | partial | partial    |\n| Single-binary deploy    | yes (docker)  | yes           | yes     | n/a        |\n| Auditable code size     | ~1.5 KLOC     | ~30 KLOC      | closed  | closed     |\n| Per-key rpm + tpm       | yes (Redis)   | yes           | yes     | yes        |\n| Multi-backend routing   | yes           | yes           | yes     | yes        |\n| OSS license             | Apache-2.0    | MIT           | MIT     | n/a        |\n\nThe closest cousin is LiteLLM Proxy. Pick LiteLLM if you need 100+\nproviders and don't mind a heavier dependency surface; pick this if you\nwant something small you can read end-to-end before you trust it in front\nof production.\n\n## Quickstart\n\n```sh\ngit clone https://github.com/sukhrobnurali/relay-gateway \u0026\u0026 cd relay-gateway\n\n# Pull a model into ollama (compose file co-launches it).\ndocker compose -f docker/docker-compose.yml up -d\ndocker compose -f docker/docker-compose.yml exec ollama ollama pull qwen2.5:7b\n\n# Health check\ncurl -s localhost:8080/healthz\n# {\"status\": \"ok\"}\n\n# Make a chat completion call as OpenAI would.\ncurl -s localhost:8080/v1/chat/completions \\\n  -H 'authorization: Bearer dev-key' \\\n  -H 'content-type: application/json' \\\n  -d '{\n    \"model\": \"qwen2.5\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"say hi in five words\"}]\n  }' | jq .\n```\n\nUsing the OpenAI Python SDK is exactly what you'd expect:\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"http://localhost:8080/v1\", api_key=\"dev-key\")\nresp = client.chat.completions.create(\n    model=\"qwen2.5\",\n    messages=[{\"role\": \"user\", \"content\": \"say hi in five words\"}],\n)\nprint(resp.choices[0].message.content)\n```\n\n## Performance\n\nNumbers from a same-host benchmark (Ryzen 7 5800X, 60 s @ 50 connections,\nqwen2.5:7b Q4_K_M served by Ollama). See [docs/benchmarks.md](docs/benchmarks.md)\nfor full methodology.\n\n| latency  | direct ollama | gateway -\u003e ollama | overhead |\n|----------|---------------|-------------------|----------|\n| p50      | 412 ms        | 414 ms            | +2 ms    |\n| p95      | 658 ms        | 661 ms            | +3 ms    |\n| p99      | 821 ms        | 829 ms            | +8 ms    |\n\n## Configuration\n\nYAML for shape, env vars for overrides. See [docs/configuration.md](docs/configuration.md)\nfor every key. Minimal example:\n\n```yaml\n# config.yaml\nbackends:\n  ollama-local:\n    type: ollama\n    base_url: http://ollama:11434\n\nmodels:\n  qwen2.5:\n    backend: ollama-local\n    upstream_model: qwen2.5:7b\n    fallbacks: [openai-fallback]\n\napi_keys:\n  - name: dev\n    # generate with: uv run python -c \"from argon2 import PasswordHasher as P; print(P().hash('your-key'))\"\n    hash: $argon2id$v=19$m=65536,t=3,p=4$...\n    scopes: [qwen2.5]\n    limits:\n      rpm: 60\n      tpm: 30000\n\ndefault_limits:\n  rpm: 30\n  tpm: 10000\n\nredis_url: redis://redis:6379/0\n```\n\n## Deployment\n\n* **Docker compose** (single VM): see `docker/docker-compose.yml`.\n* **Kubernetes**: example manifests in `examples/k8s/`. Full guide in\n  [docs/deployment.md](docs/deployment.md).\n* **Image**: pulled from `ghcr.io/sukhrobnurali/relay-gateway:\u003ctag\u003e`.\n\n## Development\n\n```sh\nuv sync\nuv run pytest -q          # full test suite\nuv run ruff check .\nuv run pyright src\nuv run pytest --cov       # coverage report\n```\n\nArchitecture decisions and the why-this-not-that are in\n[docs/architecture.md](docs/architecture.md). The competitive analysis\n(circa Jan 2026) lives in [docs/landscape.md](docs/landscape.md).\n\n## License\n\nApache-2.0. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukhrobnurali%2Frelay-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsukhrobnurali%2Frelay-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukhrobnurali%2Frelay-gateway/lists"}