A unified AI model aggregation platform that provides a single API gateway to multiple Large Language Model (LLM) providers including OpenAI, Claude, and Gemini. Built with modern TypeScript technologies and designed for scalability.
- Unified API Gateway: Single endpoint for multiple LLM providers (OpenAI, Claude, Gemini)
- User Management: Complete authentication and authorization system
- API Key Management: Generate and manage multiple API keys per user
- Credit-Based Billing: Track usage and manage credits for API consumption
- Multi-Provider Routing: Intelligent routing to different LLM providers based on model selection
- Usage Analytics: Track conversations, token counts, and credit consumption
- Web Dashboard: Intuitive React-based dashboard for managing API keys, credits, and usage
- Type-Safe: End-to-end type safety with TypeScript and Prisma
This is a Turborepo monorepo containing three applications and two shared packages:
-
api-backend: LLM aggregation service that routes requests to OpenAI, Claude, and Gemini- Port: Configured for API routing
- Handles chat completions and model routing
- Manages token counting and credit deduction
-
main-backend: Core business logic server- Port: 3000
- User authentication and authorization
- API key CRUD operations
- Payment and credit management
- Model and provider configuration
-
frontend-dashboard: React-based web interface- Port: 3001
- User signup/signin
- Dashboard with usage analytics
- API key management
- Credit management
-
db: Shared Prisma database package- PostgreSQL schema definitions
- Type-safe database client
- Migrations management
-
eslint-config: Shared ESLint configurations -
typescript-config: Shared TypeScript configurations
- Runtime: Bun - Fast all-in-one JavaScript runtime
- Framework: Elysia.js - Ergonomic web framework for Bun
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT-based authentication with Elysia JWT plugin
- LLM SDKs:
- Anthropic SDK for Claude
- OpenAI SDK for GPT models
- Gemini SDK for Google models
- Framework: React 19
- Routing: React Router v7
- Styling: Tailwind CSS v4
- UI Components: Custom component library built with Base UI
- State Management: TanStack Query (React Query)
- Type Safety: Eden Treaty for end-to-end type safety with Elysia backend
- Monorepo: Turborepo for fast, efficient builds
- Package Manager: Bun
- Language: TypeScript 5.9
- Code Quality: ESLint + Prettier with auto-sorting imports
- Bun >= 1.3.8
- Node.js >= 18 (for Turborepo compatibility)
- PostgreSQL database
- API keys for LLM providers:
- OpenAI API key
- Anthropic (Claude) API key
- Google (Gemini) API key
git clone https://github.com/dev0jha/Openrouter.git
cd Openrouterbun installCreate .env files in the respective applications:
packages/db/.env
DATABASE_URL="postgresql://user:password@localhost:5432/openrouter"apps/main-backend/.env
DATABASE_URL="postgresql://user:password@localhost:5432/openrouter"
JWT_SECRET="your-jwt-secret-key"apps/api-backend/.env
DATABASE_URL="postgresql://user:password@localhost:5432/openrouter"
OPENAI_API_KEY="your-openai-key"
ANTHROPIC_API_KEY="your-anthropic-key"
GEMINI_API_KEY="your-gemini-key"cd packages/db
bun run prisma migrate dev
bun run prisma generateFrom the root directory:
# Start all applications in development mode
bun run dev
# Or start individual apps
cd apps/main-backend && bun run dev
cd apps/api-backend && bun run dev
cd apps/frontend-dashboard && bun run devThe services will be available at:
- Main Backend: http://localhost:3000
- API Backend: (configured port)
- Frontend Dashboard: http://localhost:3001
.
├── apps/
│ ├── api-backend/ # LLM aggregation service
│ │ ├── src/
│ │ │ ├── llms/ # LLM provider implementations
│ │ │ │ ├── Base.ts # Base LLM interface
│ │ │ │ ├── Claude.ts # Anthropic Claude integration
│ │ │ │ ├── Gemini.ts # Google Gemini integration
│ │ │ │ └── OpenAi.ts # OpenAI integration
│ │ │ ├── index.ts # Main API routes
│ │ │ └── types.ts # Type definitions
│ │ └── package.json
│ │
│ ├── main-backend/ # Core business logic
│ │ ├── src/
│ │ │ ├── modules/
│ │ │ │ ├── auth/ # Authentication module
│ │ │ │ ├── apikeys/ # API key management
│ │ │ │ ├── models/ # Model configuration
│ │ │ │ └── payment/ # Payment & credits
│ │ │ ├── app.ts # Application setup
│ │ │ └── index.ts # Server entry point
│ │ └── package.json
│ │
│ └── frontend-dashboard/ # Web dashboard
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── providers/ # Context providers
│ │ └── App.tsx # Main app component
│ └── package.json
│
├── packages/
│ ├── db/ # Shared database package
│ │ ├── prisma/
│ │ │ ├── schema.prisma # Database schema
│ │ │ └── migrations/ # Migration files
│ │ └── generated/ # Generated Prisma client
│ │
│ ├── eslint-config/ # Shared ESLint configs
│ └── typescript-config/ # Shared TS configs
│
├── package.json # Root package.json
├── turbo.json # Turborepo configuration
└── README.md # This file
All API requests require authentication via API key in the Bearer token format:
Authorization: Bearer YOUR_API_KEYPOST /api/v1/chat/completions
Unified endpoint for chat completions across all supported LLM providers.
Request Body:
{
"model": "openai/gpt-4",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
],
"stream": false
}Supported Models:
openai/gpt-4openai/gpt-3.5-turboanthropic/claude-3-opusanthropic/claude-3-sonnetgoogle/gemini-pro- And more...
Response:
{
"id": "chatcmpl-xxx",
"model": "openai/gpt-4",
"choices": [
{
"message": {
"role": "assistant",
"content": "I'm doing well, thank you!"
}
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 8,
"total_tokens": 18
}
}The application uses PostgreSQL with the following main entities:
- User: User accounts with email/password and credit balance
- ApiKey: Multiple API keys per user with usage tracking
- Company: LLM provider companies (OpenAI, Anthropic, Google)
- Model: Available models (GPT-4, Claude, Gemini, etc.)
- Provider: Infrastructure providers for each model
- ModelProviderMapping: Maps models to providers with pricing
- Conversation: Tracks all API calls with token counts
- OnrampTransaction: Payment and credit purchase history
# Development
bun run dev # Start all apps in development mode
# Building
bun run build # Build all apps and packages
# Code Quality
bun run lint # Lint all packages
bun run format # Format code with Prettier
bun run check-types # Type-check all packages
# Database
cd packages/db
bun run prisma migrate dev # Run migrations
bun run prisma generate # Generate Prisma client
bun run prisma studio # Open Prisma Studio- Create a new class in
apps/api-backend/src/llms/extending theBaseclass - Implement the required methods for chat completions
- Add the provider to the routing logic in
apps/api-backend/src/index.ts - Update the database with new provider and model entries
- API keys are hashed before storage
- JWT tokens for user authentication
- Rate limiting should be implemented for production
- CORS is configured for the frontend origin
- Database credentials should be stored securely
- LLM provider API keys should never be exposed to the client
bun run buildEnsure all environment variables are properly configured for production:
- Database connection strings
- JWT secrets
- LLM provider API keys
- CORS origins
- Database: Managed PostgreSQL (AWS RDS, Neon, Supabase)
- Backend: Container service (Docker, AWS ECS, Fly.io)
- Frontend: Static hosting (Vercel, Netlify, Cloudflare Pages)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is private and maintained by @dev0jha.
- Built with Turborepo
- Powered by Bun and Elysia.js
- Inspired by OpenRouter
You can build a specific package by using a filter:
# With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended)
turbo build --filter=docs
# Without [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation), use your package manager
npx turbo build --filter=docs
yarn exec turbo build --filter=docs
pnpm exec turbo build --filter=docs
To develop all apps and packages, run the following command:
cd my-turborepo
# With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended)
turbo dev
# Without [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation), use your package manager
npx turbo dev
yarn exec turbo dev
pnpm exec turbo dev
You can develop a specific package by using a filter:
# With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended)
turbo dev --filter=web
# Without [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation), use your package manager
npx turbo dev --filter=web
yarn exec turbo dev --filter=web
pnpm exec turbo dev --filter=web
Tip
Vercel Remote Cache is free for all plans. Get started today at vercel.com.
Turborepo can use a technique known as Remote Caching to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:
cd my-turborepo
# With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended)
turbo login
# Without [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation), use your package manager
npx turbo login
yarn exec turbo login
pnpm exec turbo login
This will authenticate the Turborepo CLI with your Vercel account.
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
# With [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation) installed (recommended)
turbo link
# Without [global `turbo`](https://turborepo.dev/docs/getting-started/installation#global-installation), use your package manager
npx turbo link
yarn exec turbo link
pnpm exec turbo link
Learn more about the power of Turborepo:
