HRT-200: AI Router — Multi-provider LLM routing with failover #16

Open
admin wants to merge 2 commits from feature/HRT-200-ai-router into master
Owner

Summary

Implement AI Router for multi-provider LLM routing with automatic failover across OpenAI, Anthropic, Google, and Mistral.

Files

  • ai_router/providers/ - Abstract provider interface + 4 adapters (OpenAI SDK, Anthropic SDK, google-genai, Mistral HTTP)
  • ai_router/router.py - Core router: model resolution, prioritized ordering, exponential backoff failover
  • ai_router/api.py - Flask blueprint: /health, /models, /chat (auth), /admin/providers, /usage
  • ai_router/models.py - DB schema: ai_providers, ai_model_mapping (cost_per_1k_tokens), ai_router_log
  • ai_router/utils.py - Auth via token-broker verify endpoint
  • ai_router_api.py - Standalone entry point (port 8783)

Auth

Uses existing token-broker /api/v1/tokens/verify. @require_auth (Bearer/X-API-Key) and @admin_required (admin/ai_router_admin scope) decorators.

Tests

21 unit tests passing: provider interface, router logic (failover, all-down), DB CRUD, API endpoints.

## Summary Implement AI Router for multi-provider LLM routing with automatic failover across OpenAI, Anthropic, Google, and Mistral. ### Files - **ai_router/providers/** - Abstract provider interface + 4 adapters (OpenAI SDK, Anthropic SDK, google-genai, Mistral HTTP) - **ai_router/router.py** - Core router: model resolution, prioritized ordering, exponential backoff failover - **ai_router/api.py** - Flask blueprint: /health, /models, /chat (auth), /admin/providers, /usage - **ai_router/models.py** - DB schema: ai_providers, ai_model_mapping (cost_per_1k_tokens), ai_router_log - **ai_router/utils.py** - Auth via token-broker verify endpoint - **ai_router_api.py** - Standalone entry point (port 8783) ### Auth Uses existing token-broker /api/v1/tokens/verify. @require_auth (Bearer/X-API-Key) and @admin_required (admin/ai_router_admin scope) decorators. ### Tests 21 unit tests passing: provider interface, router logic (failover, all-down), DB CRUD, API endpoints.
admin added 2 commits 2026-05-24 10:22:17 +02:00
- New api_v1/routes/admin.py: admin client management blueprint
- admin_users table for admin role (no ALTER TABLE needed)
- require_admin decorator for endpoint protection
- GET/PUT/DELETE /api/v1/admin/clients/<id>
- POST /api/v1/admin/setup (first-time admin init)
- POST /api/v1/admin/clients/<id>/suspend|activate
- GET /api/v1/admin/stats (client counts by plan)
- Registered in api_v1/__init__: auto-wired into portal_server.py
- No new service, no merge tables, no ALTER TABLE
- 4 provider adapters: OpenAI (SDK), Anthropic (SDK), Google (google-genai), Mistral (direct HTTP)
- Core router with automatic failover + exponential backoff
- Flask blueprint with /api/v1/ai/* endpoints
- Auth via token-broker verify endpoint
- DB models for ai_providers, ai_model_mapping, ai_router_log
- /health endpoint (parallel provider check), /usage stats
- 21 unit tests (all passing)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/HRT-200-ai-router:feature/HRT-200-ai-router
git checkout feature/HRT-200-ai-router
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/turf_saas#16