Skip to content

A unified gateway for OpenRouter, Anthropic, OpenAI, Google, xAI and more. Switch providers without losing context, use the tools and interfaces you already rely on, and track all usage and costs in one place.

License

Notifications You must be signed in to change notification settings

ekailabs/ekai-gateway

Repository files navigation

Ekai Gateway

License GitHub stars Discord

Multi-provider AI proxy with usage dashboard supporting Anthropic, OpenAI, Google Gemini, xAI, and OpenRouter models through OpenAI-compatible and Anthropic-compatible APIs.

Designed for self-hosted personal use - run your own instance to securely proxy AI requests using your API keys.

Features

  • πŸ€– Multi-provider: Anthropic + OpenAI + Google (Gemini) + xAI + OpenRouter models
  • πŸ”„ Dual APIs: OpenAI-compatible + Anthropic-compatible endpoints
  • πŸ”€ Cost-optimized routing: Automatic selection of cheapest provider for each model
  • πŸ’° Usage tracking: Track token usage and costs with visual dashboard
  • πŸ—„οΈ Database storage: SQLite database for persistent usage tracking
  • πŸ“Š Analytics dashboard: Real-time cost analysis and usage breakdowns

πŸŽ₯ Demo Video

Demo Video

Quick Start (Beta)

Option 1: Using npm

# 1. Install dependencies
npm install

# 2. Setup environment variables
cp .env.example .env
# Edit .env and add at least one API key (see .env.example for details)

# 3. Build and start the application
npm run build
npm start

Option 2: Using Docker (published image)

# 1. Setup environment variables
cp .env.example .env
# Edit .env and add at least one API key (see .env.example for details)

# 2. Pull + start the latest GHCR image
docker compose up -d

# Optional: run without Compose
docker pull ghcr.io/ekailabs/ekai-gateway:latest
docker run --env-file .env -p 3001:3001 -p 3000:3000 ghcr.io/ekailabs/ekai-gateway:latest

Important: The dashboard is initially empty. After setup, send a query using your own client/tool (IDE, app, or API) through the gateway; usage appears once at least one request is processed.

Access Points:

  • Gateway API: http://localhost:3001
  • Dashboard UI: http://localhost:3000
  • Detailed setup steps live in docs/getting-started.md; check docs/ for additional guides.

Build the Image Yourself (optional)

If you’re contributing changes or need a custom build:

docker build --target ekai-gateway-runtime -t ekai-gateway .
docker run --env-file .env -p 3001:3001 -p 3000:3000 ekai-gateway

Populate the Dashboard

  • Point your client/tool to the gateway (http://localhost:3001 or http://localhost:3001/v1), see integration guides below.
  • Send a query using your usual workflow; both OpenAI-compatible and Anthropic-compatible endpoints are tracked.
  • Open http://localhost:3000 to view usage and costs after your first request.

Required: At least one API key from Anthropic, OpenAI, Google Gemini, xAI, or OpenRouter (see .env.example for configuration details).

Integration Guides

πŸ€– Claude Code Integration

Use the gateway with Claude Code for multi-provider AI assistance:

# Point Claude Code to the gateway
export ANTHROPIC_BASE_URL="http://localhost:3001"
export ANTHROPIC_MODEL="grok-code-fast-1"  # or "gpt-4o","claude-sonnet-4-20250514"

# Start Claude Code as usual
claude

πŸ“– Complete Claude Code Guide β†’

πŸ’» Codex Integration

Use the gateway with Codex for OpenAI-compatible development tools:

# Point Codex to the gateway
export OPENAI_BASE_URL="http://localhost:3001/v1"

# Start Codex as usual  
codex

πŸ“– Complete Codex Guide β†’

Beta Testing Notes

🚧 This is a beta release - please report any issues or feedback!

Known Limitations:

  • Some edge cases in model routing may exist

Getting Help:

  • Check the logs in gateway/logs/gateway.log for debugging
  • Ensure your API keys have sufficient credits
  • Test with simple requests first before complex workflows

Project Structure

ekai-gateway/
β”œβ”€β”€ gateway/          # Backend API and routing
β”œβ”€β”€ ui/              # Dashboard frontend
β”œβ”€β”€ shared/          # Shared types and utilities
└── package.json     # Root package configuration

API Endpoints

POST /v1/chat/completions  # OpenAI-compatible chat endpoint
POST /v1/messages          # Anthropic-compatible messages endpoint
POST /v1/responses         # OpenAI Responses endpoint
GET  /usage               # View token usage and costs
GET  /health              # Health check endpoint
# OpenAI-compatible endpoint (works with all providers)
curl -X POST http://localhost:3001/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'

# Use Claude models via OpenAI-compatible endpoint
curl -X POST http://localhost:3001/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-3-5-sonnet-20241022", "messages": [{"role": "user", "content": "Hello"}]}'

# Use xAI Grok models
curl -X POST http://localhost:3001/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "grok-code-fast", "messages": [{"role": "user", "content": "Hello"}]}'

# Anthropic-compatible endpoint
curl -X POST http://localhost:3001/v1/messages \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-3-5-sonnet-20241022", "max_tokens": 100, "messages": [{"role": "user", "content": "Hello"}]}'

# OpenAI Responses endpoint
curl -X POST http://localhost:3001/v1/responses \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o-mini", "input": "Say hi in one short sentence.", "temperature": 0.7, "max_output_tokens": 128}'

# Both endpoints support all models and share conversation context
# Client A uses OpenAI format, Client B uses Anthropic format - same conversation!

# Check usage and costs
curl http://localhost:3001/usage

Model Routing (Cost-Optimized)

The proxy uses cost-based optimization to automatically select the cheapest available provider:

  1. Special routing: Grok models (grok-code-fast, grok-beta) β†’ xAI (if available)
  2. Cost optimization: All other models are routed to the cheapest provider that supports them
  3. Provider fallback: Graceful fallback if preferred provider is unavailable

Supported providers:

  • Anthropic: Claude models (direct API access)
  • OpenAI: GPT models (direct API access)
  • xAI: Grok models (direct API access)
  • OpenRouter: Multi-provider access with provider/model format

Multi-client proxy: Web apps, mobile apps, and scripts share conversations across providers with automatic cost tracking and optimization.

Production Commands

npm run build  # Build TypeScript for production
npm start      # Start both gateway and dashboard

Individual services:

npm run start:gateway  # Gateway API only (port 3001)
npm run start:ui       # Dashboard UI only (port 3000)

Development

npm run dev    # Start both gateway and dashboard in development mode

Individual services:

cd gateway && npm run dev    # Gateway only (port 3001)
cd ui/dashboard && npm run dev    # Dashboard only (port 3000)

Contributing

Contributions are highly valued and welcomed! See CONTRIBUTING.md for details.

License

Licensed under the Apache License 2.0.

About

A unified gateway for OpenRouter, Anthropic, OpenAI, Google, xAI and more. Switch providers without losing context, use the tools and interfaces you already rely on, and track all usage and costs in one place.

Resources

License

Contributing

Stars

Watchers

Forks

Languages