OpenGateway AI is an API gateway that lets you integrate multiple AI providers through a single, consistent endpoint. Switch between OpenAI, Anthropic, Google, Groq, and more without changing your application code.
- Multi-Provider Support: OpenAI, Anthropic, Google, Groq, and more
- Unified Interface: One API shape for all providers (OpenAI-compatible)
- Streaming Support: Realβtime streaming for chat completions
- Smart Routing: Load balancing and failover (providerβaware)
- Cost Optimization: Choose models by cost and performance
- Enhanced Authentication:
- JWT with refresh tokens (httpOnly cookie or token in body)
- Email verification
- Password reset
- Secure API key generation and management
- Rate Limiting: Tierβbased usage protection
- Analytics & Monitoring: Comprehensive usage and cost analytics
- Modern UI/UX:
- Refined landing page and dashboard
- Auth pages (login/register/forgot/reset) redesigned
- Authenticated Playground page (moved out from landing)
- Usage Tracking: Monitor tokens, latency, and costs
- Modern Chat UI (Next.js 14 + Tailwind CSS): ChatGPT-like layout with polished navbar, sidebar rooms, and message area.
- Database-backed Chat Rooms & Messages: Persist rooms and messages in PostgreSQL via Prisma.
- Dynamic Model Selection per Room: No fixed
modelIdat room creation; user picks model per room (stored via localStorage). - State Management with TanStack Query: Hooks for models, rooms, and messages with proper caching and loading states.
- Real-time Messaging (WebSockets with Hono/Bun): Join/leave rooms, typing indicators, and broadcast new messages.
- Message Search: Local and server-side search with highlighted results.
- File Attachments: Upload and send multiple attachments with messages; rich preview in UI.
- CORS & Auth Improvements: Correct preflight handling, credentialed requests, and wider allowed headers/methods.
- Framework: Hono + Bun (Node-compatible)
- Database: PostgreSQL via Prisma ORM
- Cache: Redis
- Auth: JWT + Refresh tokens + API Keys + Optional 2FA
- Rate Limiting: Redis-based
- Realtime: WebSockets via
hono/bunupgrade helper
- Framework: Next.js 14
- Styling: TailwindCSS
- State: TanStack Query
- UI: Custom components + Heroicons
- Hooks:
useModels,useChatRooms,useRoomModelSelection,useWebSocket,useDebounce
- Bun runtime
- PostgreSQL
- Redis
- Node.js 18+ (for frontend)
- Clone repository
git clone https://github.com/zakirkun/OpenGateway-ai.git
cd OpenGateway-ai- Install dependencies
bun install- Setup environment variables
# Backend
cp packages/backend/env.example packages/backend/.env
# Edit packages/backend/.env with your settings
# Frontend
cp packages/frontend/.env.example packages/frontend/.env.local
# Edit packages/frontend/.env.local with your settings- Setup database
cd packages/backend
bunx prisma db push
bunx prisma generate- Start development servers
# Terminal 1 - Backend
cd packages/backend
bun run dev
# Terminal 2 - Frontend
cd packages/frontend
bun run dev# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Database
DATABASE_URL="postgresql://username:password@localhost:5432/OpenGateway_ai"
# Redis
REDIS_URL="redis://localhost:6379"
# JWT
JWT_SECRET="your-super-secret-jwt-key"
# AI Provider API Keys
OPENAI_API_KEY="sk-your-openai-key"
ANTHROPIC_API_KEY="sk-ant-your-anthropic-key"
GOOGLE_API_KEY="your-google-api-key"
GROQ_API_KEY="gsk_your-groq-key"
# Server
PORT=3001
NODE_ENV="development"
# CORS
# Comma-separated list of allowed origins in dev
CORS_ORIGIN="http://localhost:3000,http://127.0.0.1:3000"NEXT_PUBLIC_API_URL="http://localhost:3001"Requests to protected endpoints require an Authorization header:
Authorization: Bearer YOUR_API_KEYcurl -X POST http://localhost:3001/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "user", "content": "Hello, world!"}
],
"max_tokens": 1000,
"temperature": 0.7,
"stream": false
}'curl -X POST http://localhost:3001/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "Tell me a story"}
],
"stream": true
}'curl -X POST http://localhost:3001/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/dall-e-3",
"prompt": "A beautiful sunset over mountains",
"n": 1,
"size": "1024x1024"
}'curl -X POST http://localhost:3001/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "[email protected]" \
-F "model=openai/whisper-1"curl -X GET http://localhost:3001/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"Notes on model objects:
- Response uses
owned_byanddisplay_nameat the top level, e.g.{ "id": "openai/gpt-4o", "owned_by": "OpenAI", "display_name": "GPT-4o" }
- Server exposes REST endpoints for rooms and messages (see
API.md), including:- Create/update/delete/archive rooms
- List messages with optional
searchquery param - Create messages with optional
attachments - Global message search endpoint
Powered by hono/bun upgrade helper. Events include:
join_room,leave_roomfor presencetypingindicator per user/roomnew_messagebroadcast to room members
openai/gpt-4o- GPT-4oopenai/gpt-4o-mini- GPT-4o Miniopenai/gpt-3.5-turbo- GPT-3.5 Turbo
anthropic/claude-3-5-sonnet-20241022- Claude 3.5 Sonnetanthropic/claude-3-5-haiku-20241022- Claude 3.5 Haikuanthropic/claude-3-opus-20240229- Claude 3 Opus
google/gemini-1.5-pro- Gemini 1.5 Progoogle/gemini-1.5-flash- Gemini 1.5 Flash
groq/llama-3.1-70b-versatile- Llama 3.1 70Bgroq/llama-3.1-8b-instant- Llama 3.1 8Bgroq/mixtral-8x7b-32768- Mixtral 8x7B
OpenGateway AI provides a comprehensive analytics dashboard:
- Usage Statistics: Total requests, tokens, dan biaya
- Performance Metrics: Latency dan error rates
- Provider Comparison: Perbandingan performa antar provider
- Cost Analysis: Analisis biaya per provider dan model
- Real-time Monitoring: Monitoring real-time untuk semua request
- API Key Authentication: Secure API key system
- Rate Limiting: Abuse & DDoS protection
- Input Validation: Strict schema validation
- Error Handling: Safe errors without leaking sensitive data
- CORS Protection: Tight CORS configuration
- Setup production environment
# Set environment variables
export NODE_ENV=production
export DATABASE_URL="your-production-db-url"
export REDIS_URL="your-production-redis-url"
# ... other production variables- Build and deploy
# Build backend
cd packages/backend
bun run build
# Build frontend
cd packages/frontend
bun run build
# Deploy using your preferred method (Docker, PM2, etc.)# Build production images
docker-compose -f docker-compose.prod.yml build
# Deploy
docker-compose -f docker-compose.prod.yml up -d- Fork repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
Distributed under the MIT License. See LICENSE for more information.
# Setup 2FA
POST /auth/2fa/setup
# Verify and enable
POST /auth/2fa/verify
{
"token": "123456"
}
# Check status
GET /auth/2fa/status
# Disable 2FA
POST /auth/2fa/disable
{
"token": "123456"
}# Login (may require 2FA)
POST /auth/login
{
"email": "[email protected]",
"password": "password123",
"twoFactorCode": "123456" # Optional, required if 2FA enabled
}- Email verification on registration
- Password reset emails
- 2FA setup notifications
- Usage alerts
- Security notifications
- Welcome emails
Configure SMTP dalam .env:
SMTP_HOST="smtp.gmail.com"
SMTP_PORT=587
SMTP_USER="[email protected]"
SMTP_PASS="your-app-password"
FROM_EMAIL="noreply@your-host"
FROM_NAME="OpenGateway AI"WEBHOOK_URL="https://your-app.com/webhooks/OpenGateway"
WEBHOOK_SECRET="your-webhook-secret"SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."- Profile management
- Subscription tier information
- Usage monitoring
- Email verification status
- Create/revoke API keys
- Usage tracking per key
- Last used timestamps
- Secure key display
- New: Copy button and creation modal feedback
- Enable/disable 2FA
- QR code generation
- Backup codes management
- Security status
- Real-time usage stats
- Cost analysis
- Provider performance
- Historical data
- Modern navbar with profile dropdown
- Sidebar with rooms (active/archive, title edit, delete)
- Dynamic per-room model selection
- Message list with streaming, typing indicator
- File attachments (upload + preview)
- Local and server-side search
- Responsive and mobile-friendly
- Issue Streaming on Chat Interface
- Need Enhance the Chat Components
- Documentation: Docs
- Email: [email protected]
- Discord: Join our community
- GitHub Issues: Report bugs
- OpenAI for powerful API
- Anthropic for Claude models
- Google for Gemini models
- Meta for Llama models
- Groq for fast inference
- Hono team for an excellent framework
- Next.js team for an amazing React framework