Intelligent chat completions with automatic model routing and cost optimization. DynaRoute analyzes your prompts and routes them to the most cost-effective model while maintaining quality.
To get started, install the DynaRoute client library:
Here's how to make a simple, non-streaming chat completion request:
DynaRoute automatically selects the most cost-effective model for your prompt, potentially saving up to 70% on API costs compared to always using premium models.
POST https://api.dynaroute.com/v1/chat/completionsCreates a chat completion response for the provided messages. Compatible with OpenAI's Chat Completions API format.
DynaRoute uses API key authentication. Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY| Parameter | Type | Required | Description |
|---|---|---|---|
messages | array | Required | Array of message objects forming the conversation. Each message must have role and content fields. |
stream | boolean | Optional | If true, the response will be streamed as Server-Sent Events. Default: false |
request_timeout | integer | Optional | Request timeout in seconds. Default: 720 |
level_override | integer | Optional | Override the automatic complexity level for routing (1–5). |
Use level_override to control the complexity level for routing (1–5). 5 is the most difficult and 1 is the least.
When stream is false, the API returns a complete JSON response:
DynaRoute includes detailed cost information in the usage.cost object, showing both actual costs and GPT‑4.1 equivalent costs for comparison.
The _custom_routing_info object provides insights into how DynaRoute classified and routed your request.
For real‑time responses, enable streaming to receive chunks as they're generated:
Returns 401 for invalid or missing API keys.
{"error": {"message": "Invalid or unauthorized API key", "type": "authentication_error", "code": 401}}Returns 400 for malformed requests or missing required parameters.
{"error": {"message": "No messages array found in request", "type": "invalid_request_error", "code": 400}}Returns 500 for internal server errors or routing failures.
{"error": {"message": "Core routing logic is not loaded", "type": "server_error", "code": 503}}All requests are tracked per API key with detailed usage metrics including token counts and costs.
DynaRoute automatically routes to cost‑effective models, with potential savings of up to 70% compared to premium models.
DynaRoute MCP Server is a Model Context Protocol server that provides 11 tools for intelligent chat completions, API key management, prompt classification, cost analysis, and usage tracking. Compatible with Claude Desktop, Cursor, Claude Code, and other MCP-compatible clients.
Install via pip:
Configure Claude Desktop by adding this to your claude_desktop_config.json:
The DynaRoute MCP server exposes 11 tools organized into three categories:
| Category | Tools |
|---|---|
| API Key & Auth | dynaroute_generate_api_key, dynaroute_verify_api_key, dynaroute_revoke_api_key, dynaroute_list_api_keys, dynaroute_get_subscription |
| Routing & Models | dynaroute_route_prompt, dynaroute_classify_prompt, dynaroute_list_models |
| Cost & Usage | dynaroute_calculate_cost, dynaroute_get_usage_summary, dynaroute_get_cost_savings |
DYNAROUTE_API_KEY: Your DynaRoute API key (required for authenticated tools)Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
Add to your Cursor settings:
You can also import and use the server programmatically:
mcp: Model Context Protocol SDKfirebase-admin: Firebase authentication and Firestoreaiohttp: Async HTTP for LiteLLM proxy callsDynaRoute's MCP server provides 11 tools covering the full lifecycle: key management, intelligent routing, prompt classification, cost analysis, and usage tracking — all accessible from any MCP-compatible client.
dynaroute_generate_api_keyCreate a new DynaRoute API key for a user. The generated key uses the dr_ prefix and is stored in Firebase Firestore.
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | Firebase user ID to create the key for |
dynaroute_verify_api_keyValidate an API key and return its status, subscription tier, token limits, and remaining quota.
| Name | Type | Required | Description |
|---|---|---|---|
api_key | string | Yes | The DynaRoute API key to verify |
dynaroute_revoke_api_keyDeactivate an existing API key. The key will immediately stop working for all requests.
| Name | Type | Required | Description |
|---|---|---|---|
api_key | string | Yes | The API key to revoke |
dynaroute_list_api_keysList all API keys for a user. Keys are masked for security (only first 8 and last 4 characters shown).
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | Firebase user ID whose keys to list |
dynaroute_get_subscriptionFetch the current user's subscription tier, token limits, and usage. Uses the DYNAROUTE_API_KEY environment variable to identify the user.
dynaroute_route_promptSend a prompt through DynaRoute's intelligent router. Classifies the prompt by category and complexity, selects the optimal model, calls it, and returns the response with full routing metadata and cost breakdown.
| Name | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | The user prompt to route |
level_override | int (1-5) | No | Override complexity level. 1 = cheapest, 5 = most capable |
category_override | string | No | Override category (e.g. "Code Generation", "Creative Writing") |
dynaroute_classify_promptClassify a prompt into one of 31 categories and a complexity level (1-5) without routing it to a model. Useful for understanding how DynaRoute would categorize a prompt.
| Name | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | The prompt text to classify |
dynaroute_list_modelsReturn all available models with their LiteLLM IDs and per-token costs (input and output cost per million tokens).
dynaroute_calculate_costCompute the cost for a given model and token counts. Also shows the GPT-4.1 equivalent cost so you can see the savings.
| Name | Type | Required | Description |
|---|---|---|---|
model_name | string | Yes | Model name (e.g. "GPT-4.1", "Claude 4.5 Sonnet", "Gemini 2.5 Flash") |
prompt_tokens | int | Yes | Number of input tokens |
completion_tokens | int | Yes | Number of output tokens |
dynaroute_get_usage_summaryReturn usage statistics for the current user including total requests, tokens consumed, cumulative costs, savings, and subscription info. Uses the DYNAROUTE_API_KEY environment variable.
dynaroute_get_cost_savingsShow GPT-4.1 equivalent cost vs actual cost for a model and token usage. Includes cumulative user savings when an API key is configured.
| Name | Type | Required | Description |
|---|---|---|---|
model_used | string | Yes | The model that was used for the request |
prompt_tokens | int | Yes | Number of input tokens |
completion_tokens | int | Yes | Number of output tokens |
DynaRoute classifies prompts into one of 31 categories:
| Level | Description | Cost Tier |
|---|---|---|
| L1 | Foundational recall & direct task | Lowest |
| L2 | Integrated analysis & multi-step reasoning | Low |
| L3 | Complex synthesis & system design | Medium |
| L4 | Expert-level evaluation & advanced formulation | High |
| L5 | Novel synthesis & groundbreaking innovation | Highest |
Tools that need user context (routing, usage, subscription) use the DYNAROUTE_API_KEY environment variable configured in your MCP client. Key management tools (generate, verify, revoke, list) accept explicit parameters.