A high-performance OpenAI API compatible router server with multi-provider support, built with Node.js, Express, and TypeScript. Features OpenRouter integration with free DeepSeek Chat v3.1 model as default provider.
- ๐ Free AI Access: Default integration with DeepSeek Chat v3.1 free model via OpenRouter
- ๐ Multi-Provider Support: Route requests to OpenAI, Anthropic, DeepSeek, and other AI providers
- ๐ Authentication & Authorization: Secure API key management and user authentication
- ๐ Usage Tracking: Comprehensive logging and usage statistics
- ๐ ๏ธ Function Calling: Full support for OpenAI function calling with transparent passthrough
- โก High Performance: Optimized for low latency and high throughput
- ๐ง Easy Configuration: Simple setup with environment variables
- ๐ Scalable Architecture: Designed for horizontal scaling
- ๐ ES Modules: Modern JavaScript modules with TypeScript 5.9+
- ๐จ๐ณ Chinese Friendly: Excellent Chinese language support via DeepSeek models
- Node.js 18+
- npm or yarn
- Clone the repository:
git clone git@github.com:HeiSir2014/OpenAIRouter.git
cd OpenAIRouter- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Edit .env with your OpenRouter API key and configurationDefault Configuration (Free DeepSeek Model):
# Get your free API key from https://openrouter.ai/
OPENAI_API_KEY=sk-or-v1-your-openrouter-key-here
OPENAI_BASE_URL=https://openrouter.ai/api/v1
OPENAI_DEFAULT_MODEL=deepseek/deepseek-chat-v3.1:free
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production-must-be-at-least-32-characters-long- Start the development server:
npm run devThe server will start on http://localhost:3000
First, create a user account and API key through the admin endpoints, then use the API key in your requests:
# Using default DeepSeek model (free)
curl -X POST http://localhost:3000/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "ไฝ ๅฅฝ๏ผ่ฏท็จไธญๆๅ็ญ้ฎ้ข"}
]
}'
# Specify model explicitly
curl -X POST http://localhost:3000/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-chat-v3.1:free",
"messages": [
{"role": "user", "content": "Explain quantum computing"}
]
}'POST /v1/chat/completions- Chat completions (OpenAI compatible)GET /v1/models- List available modelsPOST /auth/register- User registrationPOST /auth/login- User loginPOST /api-keys- Create API keyGET /usage- Get usage statistics
src/
โโโ controllers/ # API route handlers
โโโ services/ # Business logic
โโโ database/ # Database models and connections
โโโ providers/ # AI provider adapters
โโโ middleware/ # Express middleware
โโโ types/ # TypeScript type definitions
โโโ utils/ # Utility functions
โโโ config/ # Configuration files
โโโ routes/ # Route definitions
npm run dev- Start development server with hot reload (TypeScript direct execution)npm start- Start production server (TypeScript direct execution)npm run build- Compile TypeScript to JavaScriptnpm run build:prod- Build and run compiled JavaScript (fastest startup)npm run type-check- Type check without compilationnpm run test- Run testsnpm run lint- Run ESLintnpm run format- Format code with Prettier
Note: This project runs TypeScript directly without pre-compilation for faster development and simpler deployment.
This project follows Google TypeScript Style Guide:
- 2 spaces for indentation
- Single quotes for strings
- Semicolons required
- Max line length: 100 characters
| Variable | Description | Default | Required |
|---|---|---|---|
NODE_ENV |
Environment mode | development |
No |
PORT |
Server port | 3000 |
No |
DB_PATH |
SQLite database path | ./database/app.db |
No |
JWT_SECRET |
JWT signing secret (32+ chars) | - | Yes |
OPENAI_API_KEY |
OpenRouter/OpenAI API key | - | Yes |
OPENAI_BASE_URL |
API base URL | https://api.openai.com/v1 |
No |
OPENAI_DEFAULT_MODEL |
Default model | gpt-3.5-turbo |
No |
ANTHROPIC_API_KEY |
Anthropic API key | - | No |
deepseek/deepseek-chat-v3.1:free- Free DeepSeek model (default)deepseek/deepseek-chat- Paid DeepSeek model
openai/gpt-4o- GPT-4 Omniopenai/gpt-4o-mini- GPT-4 Omni Minianthropic/claude-3.5-sonnet- Claude 3.5 Sonnet
gpt-4,gpt-4-turbo,gpt-3.5-turbo, etc.
Add new providers by implementing the BaseProvider interface and registering them in the provider factory.
- SQLite for data persistence
- Direct database queries
- Basic caching in memory
- ES Modules with TypeScript 5.9+
- OpenRouter integration with free DeepSeek model
- Redis for caching and session management
- Improved performance and scalability
- Distributed rate limiting
- DeepSeek Chat v3.1: Completely free via OpenRouter
- High Performance: Near GPT-4 level capabilities
- Chinese Language: Excellent Chinese understanding and generation
- No Rate Limits: Stable service through OpenRouter
| Model | Cost | Performance | Chinese Support | Availability |
|---|---|---|---|---|
| DeepSeek Chat v3.1 Free | Free | High | Excellent | โ Default |
| GPT-4o | $5/1M tokens | Highest | Good | Via OpenRouter |
| GPT-3.5 Turbo | $0.5/1M tokens | Medium | Good | Via OpenAI |
| Claude 3.5 Sonnet | $3/1M tokens | High | Good | Via OpenRouter |
- Runtime: Node.js 18+ with ES Modules
- Framework: Express 5.x
- Language: TypeScript 5.9+
- Database: SQLite (Phase 1) โ Redis (Phase 2)
- Authentication: JWT + bcrypt
- Validation: Zod 4.x
- Logging: Winston
- Testing: Jest with ES Module support
- Code Quality: ESLint 9.x (Flat Config) + Prettier
- ๐ Getting Started Guide
- ๐ง OpenRouter Configuration
- ๐ Development Plan
- ๐ API Reference
- ๐ ES Module Migration
- ๐ ๏ธ Git Setup Guide
- Fork the repository:
https://github.com/HeiSir2014/OpenAIRouter - Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following the code style guidelines
- Add tests for new functionality
- Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Submit a pull request
- Follow Google TypeScript Style Guide
- Use Conventional Commits format
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass:
npm test - Run linting:
npm run lint
MIT License - see LICENSE file for details.
- ๐ Homepage: https://github.com/HeiSir2014/OpenAIRouter
- ๐ Issues: https://github.com/HeiSir2014/OpenAIRouter/issues
- ๐ Documentation: docs/
- ๐ OpenRouter: https://openrouter.ai/
- ๐ค DeepSeek: https://www.deepseek.com/
For issues and questions:
- Check the documentation
- Search existing issues
- Create a new issue if needed
- OpenRouter for providing free access to DeepSeek models
- DeepSeek for their excellent open-source models
- The Node.js and TypeScript communities for amazing tools and libraries