Deploy MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy
Self-hosted Go LLM reverse proxy with Stripe margin & loop guard.
Redis
Just deployed
/data
marginswitch
Just deployed
Deploy and Host MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy on Railway
MarginSwitch is a self-hosted, stateless Go reverse proxy built from scratch for flat-rate AI SaaS teams. Point OPENAI_BASE_URL or ANTHROPIC_BASE_URL at your own container and connect a read-only Stripe Restricted Key to link Stripe revenue directly to per-customer OpenAI, Anthropic, and Gemini token spend.
About Hosting MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy
This template deploys the MarginSwitch Go proxy alongside an official Redis instance for fast shared state. MarginSwitch tracks real-time per-customer LLM margin in a 56.9ns 64-shard ledger, blocks past-due or canceled zombie accounts with HTTP 402, auto-downgrades over-budget heavy users (Opus to Haiku, GPT-5 to GPT-5 Mini) without HTTP 400 errors, and terminates runaway tool-calling agent loops via a 0-alloc 64-bit SimHash breaker. It starts free in Shadow Mode (MS_SHADOW_MODE=1) so you can observe per-customer margins safely before enforcing limits, and supports offline Ed25519 license keys with zero phone-home.
Common Use Cases
- Track real-time per-customer OpenAI, Anthropic, and Gemini token spend against Stripe subscription revenue
- Automatically downgrade over-budget heavy AI users to lighter models without breaking client requests
- Detect and break runaway tool-calling agent loops before they drain API credits, and block zombie/past-due accounts
Dependencies for MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy Hosting
- Redis (included in this template via
REDIS_URL) - Upstream LLM provider API keys/endpoints (OpenAI, Anthropic, Gemini) and an optional read-only Stripe Restricted Key
Why Deploy MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy 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 MarginSwitch — Self-Hosted LLM Cost & Loop Guard Proxy 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.
Template Content
Redis
redis:8.2marginswitch
marginswitch/marginswitch
