- Register unifiedRoutes under /openai prefix to enable /openai/v1/chat/completions
- Reuse existing intelligent routing logic from unified.js (no code duplication)
- Keep existing Codex API routes (/openai/responses, /openai/v1/responses) unchanged
Benefits:
- Fixes 404 error for /openai/v1/chat/completions endpoint
- Provides consistent API experience across /api and /openai prefixes
- Automatically routes to correct backend (Claude/OpenAI/Gemini) based on model
Tested:
- ✅ /openai/v1/chat/completions now returns authentication error (route works)
- ✅ /api/v1/chat/completions continues to work
- ✅ Existing Codex routes remain functional
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Created new src/routes/unified.js (225 lines)
- detectBackendFromModel(): Detects backend from model name
- routeToBackend(): Routes to Claude/OpenAI/Gemini with permission checks
- POST /v1/chat/completions: OpenAI-compatible endpoint with intelligent routing
- POST /v1/completions: Legacy completions endpoint with intelligent routing
- Updated src/routes/api.js (reduced from 1185 to 968 lines)
- Removed ~217 lines of routing logic
- Kept Claude-specific endpoints (/api/v1/messages)
- Maintained all other Claude API functionality
- Updated src/app.js
- Added unifiedRoutes registration at /api prefix
Benefits:
- Single responsibility: api.js focuses on Claude API routes
- Better organization: routing logic isolated in unified.js
- Easier maintenance: changes to routing won't affect Claude code
- File size reduction: api.js reduced by 18%
Tested:
- ✅ Claude model routing via /v1/chat/completions
- ✅ OpenAI model routing (correct backend detection)
- ✅ Gemini model routing (correct backend detection)
- ✅ Legacy /v1/completions endpoint
- ✅ All tests pass, no regressions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add modelService for centralized model management
- Support dynamic model list from config file (data/supported_models.json)
- Include 2025 latest models: GPT-4.1, o3, o4-mini, Gemini 2.5, etc.
- File watcher for hot-reload configuration changes
- Improve model detection logic in api.js
- Priority: modelService lookup → prefix matching fallback
- Smart backend routing based on model provider
- Add intelligent routing endpoints
- /v1/chat/completions: unified OpenAI-compatible endpoint
- /v1/completions: legacy format support
- Auto-route to Claude/OpenAI/Gemini based on requested model
- Add Xcode system prompt support in openaiToClaude
- Detect and preserve Xcode-specific system messages
- Export handler functions for reuse
- openaiClaudeRoutes: export handleChatCompletion
- openaiRoutes: export handleResponses
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>