# codex_api **Repository Path**: chees_cn/codex_api ## Basic Information - **Project Name**: codex_api - **Description**: codex的国内api接口转发服务,适用于服务端部署,然后给本地的codex使用,支持deepseek - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-07 - **Last Updated**: 2026-06-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Codex API — Multi-Tenant AI Forwarding Platform > **Version:** v1.0.1 A multi-tenant AI model forwarding platform built on Node.js + Vue 3, fully compatible with the OpenAI API format (Chat Completions and Responses API). Supports multiple model providers including DeepSeek, Kimi, OpenAI, and SiliconFlow. Can be used as a unified backend proxy for AI coding tools such as Codex CLI, Cursor, Continue, and Aider. --- ## Features ### Core Capabilities - **Dual API Support**: Both OpenAI Chat Completions API (`/v1/chat/completions`) and Responses API (`/v1/responses`) - **Multiple Model Providers**: DeepSeek, Kimi, OpenAI, SiliconFlow, Kimi Code — switch freely - **Multi-Tenant Architecture**: User registration/login, independent API Key management, independent service configuration - **Streaming Responses**: SSE streaming and non-streaming responses with real-time content - **Tool Calls**: Auto-fixes various non-standard tool formats, supports multi-tool parallel calling - **Model Name Mapping**: Client can send any model name; server auto-matches the user's configured provider model - **Request Logging**: Complete request/response logs with usage statistics and debugging - **Health Check Endpoint**: `/health` for service monitoring ### Frontend Admin Panel - **Dashboard**: Usage statistics, request trend charts - **API Key Management**: Create, view, disable API Keys - **Provider Configuration**: System presets + user-defined model providers - **Service Management**: Create forwarding services, bind providers and models - **Request Logs**: View historical request details ### Kimi Code API Support (v1.0.1) - **Coding Agent Identity Headers**: Auto-injects `KimiCLI` request headers (`User-Agent`, `X-Msh-Platform`, etc.) to avoid 403 errors - **Dedicated Endpoint**: Supports `https://api.kimi.com/coding/v1` coding agent API --- ## Project Structure ``` codex-api/ ├── backend/ # Express + Prisma + MySQL backend │ ├── app.js # App entry │ ├── src/ │ │ ├── config/ # Config (database, env) │ │ ├── controllers/ # Controllers (Auth, API Key, Provider, etc.) │ │ ├── middleware/ # Middleware (JWT auth, API Key auth) │ │ ├── routes/ # Route definitions │ │ ├── services/ # Business logic (proxy forwarding core) │ │ └── config/ │ ├── prisma/ │ │ ├── schema.prisma # Database schema │ │ └── seed.js # Seed data (system providers) │ ├── .env # Environment variables (local) │ └── package.json # Backend dependencies │ ├── frontend/ # Vue 3 + Element Plus frontend │ ├── src/ │ │ ├── views/ # Pages (login, register, dashboard) │ │ ├── components/ # Common components │ │ ├── stores/ # Pinia state management │ │ ├── router/ # Router config │ │ └── api/ # API client │ └── package.json # Frontend dependencies │ └── README.md # This document (Chinese) └── README_EN.md # This document (English) ``` --- ## Quick Start ### Requirements - Node.js 18+ - MySQL 8.0+ ### 1. Clone ```bash git clone cd codex-api ``` ### 2. Database Configuration Create a MySQL database, then configure backend environment variables: ```bash cd backend cp .env.example .env ``` Edit `backend/.env`: ```env # Service port PORT=8001 # Database configuration (split fields for easier ops) # Database localhost:3306 DB_HOST=localhost DB_PORT=3306 DB_USER=username DB_PASSWORD=password DB_NAME=codexapi DB_CONNECTION_LIMIT=10 # JWT config JWT_SECRET=your-super-secret-jwt-key-change-in-production JWT_EXPIRES_IN=7d ``` ### 3. Initialize Database ```bash cd backend npx prisma migrate dev --name init npx prisma generate npm run db:seed # Insert system preset providers (DeepSeek, Kimi, OpenAI, SiliconFlow, Kimi Code) ``` ### 4. Start Backend ```bash cd backend npm install npm start ``` Backend will start at `http://127.0.0.1:8001`. ### 5. Start Frontend ```bash cd frontend npm install npm run dev ``` Frontend dev server will start at `http://127.0.0.1:5173`. --- ## System Preset Providers After running `npm run db:seed`, the system will auto-create the following preset providers: | Name | Display Name | Base URL | Description | |------|-------------|----------|-------------| | `deepseek` | DeepSeek | `https://api.deepseek.com` | DeepSeek AI | | `kimi` | Moonshot AI (Kimi) | `https://api.moonshot.cn` | Moonshot AI | | `kimi-code` | Kimi Code | `https://api.kimi.com/coding/v1` | Coding Agent (subscription required) | | `openai` | OpenAI | `https://api.openai.com` | OpenAI GPT | | `siliconflow` | SiliconFlow | `https://api.siliconflow.cn` | SiliconFlow | --- ## API Endpoints ### Proxy Endpoints (API Key authentication required) | Method | Path | Description | |--------|------|-------------| | POST | `/v1/chat/completions` | Chat Completions API (streaming/non-streaming) | | POST | `/v1/responses` | Responses API (streaming/non-streaming) | ### Admin Endpoints | Method | Path | Description | |--------|------|-------------| | POST | `/api/auth/register` | User registration | | POST | `/api/auth/login` | User login | | GET | `/api/auth/me` | Get current user info | | GET | `/api/providers` | Get system provider list | | GET | `/api/user-providers` | Get user's provider configs | | POST | `/api/user-providers` | Create user provider config | | GET | `/api/services` | Get user's service list | | POST | `/api/services` | Create forwarding service | | GET | `/api/api-keys` | Get API Key list | | POST | `/api/api-keys` | Create API Key | | GET | `/api/request-logs` | Get request logs | | GET | `/health` | Health check | ### API Key Authentication Include the API Key in the request header: ```http Authorization: Bearer sk-your-api-key-here ``` --- ## Client Configuration Guide ### Codex CLI ```bash export OPENAI_API_KEY="sk-your-api-key" export OPENAI_BASE_URL="http://127.0.0.1:8001/v1" codex "Hello, world!" ``` ### Cursor In Cursor Settings → Models, add a custom model: - **Model**: `deepseek-chat` (or any model name you configured) - **Base URL**: `http://127.0.0.1:8001/v1` - **API Key**: `sk-your-api-key` ### Continue (VS Code) Add an OpenAI-compatible provider in `~/.continue/config.json`: ```json { "models": [{ "title": "Codex API", "provider": "openai", "model": "deepseek-chat", "apiBase": "http://127.0.0.1:8001/v1", "apiKey": "sk-your-api-key" }] } ``` ### Generic OpenAI SDK ```javascript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: 'sk-your-api-key', baseURL: 'http://127.0.0.1:8001/v1', }); const stream = await client.chat.completions.create({ model: 'deepseek-chat', messages: [{ role: 'user', content: 'Hello!' }], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ''); } ``` --- ## Request Examples ### Chat Completions API ```bash curl http://127.0.0.1:8001/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-api-key" \ -d '{ "model": "deepseek-chat", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello" } ], "stream": true }' ``` ### Responses API ```bash curl http://127.0.0.1:8001/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-api-key" \ -d '{ "model": "deepseek-chat", "input": "Hello, what is 2+2?", "stream": true }' ``` ### Tool Calls ```bash curl http://127.0.0.1:8001/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-your-api-key" \ -d '{ "model": "deepseek-chat", "messages": [{ "role": "user", "content": "What is the weather in Beijing?" }], "tools": [{ "type": "function", "function": { "name": "get_weather", "description": "Get weather information", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "City name" } }, "required": ["city"] } } }], "stream": false }' ``` --- ## Version History ### v1.0.1 (Current) - Added Kimi Code API support with automatic coding agent identity header injection - Split DATABASE_URL into DB_HOST/PORT/USER/PASSWORD/NAME for easier operations - Added `env.js` auto-builder to compose DATABASE_URL from split variables - Updated README with v1.0.1 version and full architecture docs - Added `kimi-code` preset provider in seed data - Added Codex CLI tutorial page in frontend ### v1.0.0 - Initial multi-tenant AI forwarding platform - Support for Chat Completions and Responses API dual formats - Support for DeepSeek, Kimi, OpenAI, SiliconFlow providers - Frontend admin panel (Vue 3 + Element Plus) - User system, API Key management, service configuration, request logs --- ## Tech Stack ### Backend - **Node.js** — Runtime - **Express** — HTTP framework - **Prisma** — ORM database access - **MySQL** — Data persistence - **OpenAI Node.js SDK** — Upstream API client (OpenAI-compatible) - **jsonwebtoken / bcryptjs** — JWT authentication and password hashing - **dotenv** — Environment variable management ### Frontend - **Vue 3** — Progressive framework - **Element Plus** — UI component library - **Pinia** — State management - **Vue Router** — Routing - **ECharts** — Data visualization - **Vite** — Build tool --- ## License MIT