How to Install OmniRoute — Complete Setup Guide
OmniRoute is an open-source AI gateway (MIT, 9.8k stars) that routes LLM requests across 231+ providers with built-in token compression (15–95%) and smart fallback. This guide covers everything from cloning the repository to connecting your first application.
What You'll Learn
- →System prerequisites and environment setup
- →Cloning the OmniRoute repository and installing dependencies
- →Configuring AI provider API keys in .env
- →Setting up routing priority and fallback chains
- →Enabling and tuning RTK+Caveman token compression
- →Running OmniRoute in development and production
- →Connecting any OpenAI-compatible SDK to OmniRoute
- →Answers to frequently asked questions
Step-by-Step: Installing OmniRoute
Prerequisites
Before installing OmniRoute, confirm your environment meets these requirements:
Node.js / Docker (Runtime)
OmniRoute runs as a Node.js service or inside a Docker container. Node.js 18+ is recommended for local development. Docker and Docker Compose are the preferred path for production deployments — they handle dependency isolation and restart policies automatically.
AI Provider API Keys
You need at least one AI provider API key (OpenAI, Anthropic, Google, Mistral, or any of the 231+ supported providers). For fallback routing to be effective, keys for two or more providers are recommended. Collect your keys before starting configuration.
Git
You will clone the OmniRoute repository from GitHub. Ensure git is installed and you have network access to github.com.
Clone the Repository
Clone the OmniRoute repository from GitHub and install dependencies:
# Clone the repo
git clone https://github.com/diegosouzapw/omniroute.git
cd omniroute
# Install dependencies
npm install
# Or with pnpm (faster)
pnpm install
OmniRoute has 9.8k GitHub stars and is actively maintained. Check the releases tab for the latest stable version tag before deploying to production.
Configure Your Providers
Copy the example environment file and add your provider API keys. OmniRoute reads all provider credentials from environment variables at startup.
# Copy the example env file
cp .env.example .env
Open .env and add your keys. A minimal two-provider setup looks like this:
# .env — add your provider keys
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...
# Optional: port override (default: 4000)
OMNIROUTE_PORT=4000
OmniRoute supports 231+ providers. Check the .env.example file in the repository for the full list of supported provider environment variable names.
Configure Routing and Fallback
OmniRoute's routing behavior is defined in omniroute.config.js (or omniroute.config.json). Define your primary provider and fallback chain:
// omniroute.config.js
module.exports = {
routing: {
primary: 'openai/gpt-4o',
fallback: [
'anthropic/claude-3-5-sonnet',
'google/gemini-1.5-pro',
],
},
compression: {
enabled: true,
algorithm: 'rtk+caveman',
target_ratio: 0.6, // aim for 40% reduction
},
}
The target_ratio parameter controls compression aggressiveness. A value of 0.6 means OmniRoute will attempt to reduce the prompt to 60% of its original token count. Adjust based on your quality/cost tradeoff requirements.
Enable Token Compression
Token compression is enabled in the config file (Step 4) and requires no additional setup. However, these settings let you tune the compression behavior for your specific workload:
| Config Key | Recommended Value | Notes |
|---|---|---|
| compression.enabled | true | Enable RTK+Caveman compression |
| compression.algorithm | 'rtk+caveman' | Only supported algorithm |
| compression.target_ratio | 0.5–0.8 | 0.5 = max compression, 0.8 = light |
| compression.min_tokens | 200 | Skip compression for short prompts |
| compression.preserve_code | true | Prevent compression inside code blocks |
Set preserve_code: true if your prompts contain code snippets or structured data — this prevents the compressor from mangling syntax-sensitive content.
Run OmniRoute
Start OmniRoute in development mode to verify your configuration:
# Development mode (with hot reload)
npm run dev
# Production mode
npm run start
# Docker Compose (recommended for production)
docker compose up -d
OmniRoute starts on port 4000 by default (override with OMNIROUTE_PORT). You should see startup logs confirming which providers are configured and that compression is active:
[OmniRoute] Starting on port 4000
[OmniRoute] Providers: openai ✓ anthropic ✓ google ✓
[OmniRoute] Compression: RTK+Caveman enabled (target: 0.60)
[OmniRoute] Routing: openai/gpt-4o → anthropic/claude-3-5-sonnet → google/gemini-1.5-pro
[OmniRoute] Ready — listening at http://localhost:4000
Connect Your Application
Point any OpenAI-compatible SDK at your OmniRoute instance by changing the base URL. No other code changes required. Here are examples for the most common clients:
Node.js / TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'any-string', // OmniRoute uses
baseURL: 'http://localhost:4000/v1', // your own keys
});
const res = await client.chat.completions.create({
model: 'gpt-4o', // OmniRoute routes this
messages: [{ role: 'user', content: 'Hello' }],
});Python
from openai import OpenAI
client = OpenAI(
api_key="any-string",
base_url="http://localhost:4000/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)The apiKey value in your client can be any non-empty string — OmniRoute uses the provider API keys from your .env file, not the value your application passes in. This keeps provider keys centralized in OmniRoute rather than distributed across your apps.
Configuration Tips for OmniRoute
A working OmniRoute installation is straightforward. Getting the most out of compression and routing requires a few extra steps. These six tips will help you avoid the most common configuration mistakes and get to optimal performance faster.
Start with Two Providers
Configure a primary and at least one fallback provider from day one. A single-provider setup defeats OmniRoute's key reliability benefit. OpenAI + Anthropic is the most common production pairing.
Test Compression Before Production
Run your real prompt workload through OmniRoute in staging and check the compression logs. Verify that compressed outputs maintain the response quality you need before rolling to production traffic.
Use Docker Compose in Production
The Docker Compose configuration includes automatic restart policies and health checks. Running OmniRoute as a raw Node.js process requires you to manage process supervision separately (PM2, systemd, etc.).
Pin a Config Version with Git Tags
Before deploying a config change, tag the current working config version in git. If a routing or compression change causes issues, you can roll back the config immediately without redeploying code.
Set min_tokens to Skip Tiny Requests
Short prompts (under 200 tokens) benefit less from compression and add unnecessary processing latency. Set compression.min_tokens to skip compression for small requests and focus the savings on your large prompts.
Health-Check the /health Endpoint
OmniRoute exposes a /health endpoint that reports provider availability. Wire this into your load balancer or uptime monitor to get immediate alerts if all fallback providers become unavailable simultaneously.
Production Best Practices
Never Commit .env to Version Control
Your .env file contains provider API keys. Add it to .gitignore immediately after creating it. Use a secrets manager (Vault, AWS Secrets Manager, Doppler) for production deployments.
Deploy OmniRoute Behind a Reverse Proxy
In production, place Nginx or Caddy in front of OmniRoute. The reverse proxy handles TLS termination, request rate limiting, and access control — OmniRoute focuses solely on AI routing.
Monitor Compression Ratios Over Time
Your actual compression ratio depends on your specific prompt patterns. Log ratio metrics from OmniRoute and graph them over time — significant drops in compression ratio may indicate prompt structure changes that warrant tuning.
Set Timeouts on Fallback Providers
Configure per-provider request timeouts in your routing config. Without timeouts, a slow primary provider can hold up the fallback chain for 30+ seconds. A 10-second timeout per provider is a sensible default.
Test Fallback Manually Before Going Live
Before production launch, deliberately invalidate your primary provider API key to verify fallback routing activates correctly. Document the expected failover behavior so on-call engineers understand how the system behaves during an outage.
Frequently Asked Questions
Is OmniRoute free to use?
Yes. OmniRoute is MIT-licensed open-source software. There is no usage fee, no subscription, and no per-request charge from OmniRoute itself. You pay only your AI provider API costs — which OmniRoute reduces through token compression.
Does token compression affect output quality?
RTK+Caveman compression is designed to preserve semantic meaning while reducing token count. In most cases, output quality is indistinguishable from uncompressed prompts. For critical applications, test compression in staging with your real workload and compare outputs before enabling in production.
Can I use OmniRoute with LangChain or LlamaIndex?
Yes. Both LangChain and LlamaIndex support custom base URLs for OpenAI-compatible providers. Set the base_url to your OmniRoute instance and LangChain/LlamaIndex will route all LLM calls through OmniRoute automatically.
How does OmniRoute handle provider rate limits?
When a provider returns a 429 (rate limit) response, OmniRoute immediately retries the request with the next provider in your fallback chain. Your application receives the response without any awareness of the rate limit event.
What is the performance overhead of running OmniRoute?
OmniRoute adds a small amount of latency for compression processing (typically 5–20ms depending on prompt length) and the network hop to your OmniRoute instance. This overhead is more than offset by the latency reduction from smaller compressed prompts reaching the provider, especially for large-context requests.
Can I run OmniRoute on Kubernetes?
Yes. OmniRoute ships with Docker support and is stateless, which makes it straightforward to deploy on Kubernetes with a Deployment and a Service. Configure your provider keys as Kubernetes Secrets and mount them as environment variables.
Does OmniRoute support streaming responses?
Yes. OmniRoute passes streaming SSE responses through from the provider to your application. Token compression is applied to the input prompt only — the streaming response from the provider is forwarded to your client unchanged.
OmniRoute in the AI Gateway Landscape
OmniRoute occupies a specific position among open-source AI gateways. Here is how it compares to the major alternatives:
| Gateway | Primary Strength | Token Compression | License |
|---|---|---|---|
| OmniRoute | Token compression + 231+ providers | Yes (15–95%) | MIT |
| LiteLLM | Python SDK + spend controls | No | MIT |
| OpenRouter | Unified billing, zero infra | No | SaaS |
| Portkey | Observability + guardrails | No | Free + paid |
Token compression is OmniRoute's unique differentiator — no other open-source gateway in this list offers RTK+Caveman compression out of the box.
Start Routing with OmniRoute
OmniRoute is MIT-licensed and free to self-host. Star the repository, follow the install steps above, and start compressing your token costs today.