Minimal examples for designing an OpenAI-compatible model router.
This repository is useful for developers who want to understand how a single API layer can route requests to different AI model providers while keeping client integration simple.
Maintained by ModelPort Global: https://www.modelportglobal.com/
An API router receives a request from an application, checks the requested model, applies account or routing rules, and forwards the request to the appropriate upstream service.
Common use cases:
- Route different models through one endpoint
- Keep application code stable while changing providers
- Track usage and cost in one place
- Apply team-level access controls
- Test new providers without rewriting clients
Typical model families in an aggregation layer may include domestic Chinese models such as DeepSeek, Qwen, and GLM, plus global models such as Claude and GPT.
POST /v1/chat/completions
Authorization: Bearer <api-key>
Content-Type: application/json{
"model": "your-model-name",
"messages": [
{ "role": "user", "content": "Explain API routing in one sentence." }
]
}See examples/routes.json.
- Keep the external API compatible with popular SDKs
- Validate account permissions before routing
- Store only the logs needed for debugging and billing
- Track prompt tokens, completion tokens, and total cost
- Return clear error messages for missing models or invalid keys
- Respect upstream provider terms and rate limits
If you want a ready-to-use gateway instead of building your own router, try ModelPort Global:
- Website: https://www.modelportglobal.com/
- Pricing: https://www.modelportglobal.com/pricing
- Dashboard: https://www.modelportglobal.com/dashboard
This repository is for legitimate API integration and routing patterns. Use only authorized API keys and permitted upstream services.