DynaRoute API

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.

Quick Start

To get started, install the DynaRoute client library:

Here's how to make a simple, non-streaming chat completion request:

Automatic Cost Optimization

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.

Endpoint

POST https://api.dynaroute.com/v1/chat/completions

Creates a chat completion response for the provided messages. Compatible with OpenAI's Chat Completions API format.

Authentication

DynaRoute uses API key authentication. Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY
Get API Key

Request Parameters

ParameterTypeRequiredDescription
messagesarrayRequiredArray of message objects forming the conversation. Each message must have role and content fields.
streambooleanOptionalIf true, the response will be streamed as Server-Sent Events. Default: false
request_timeoutintegerOptionalRequest timeout in seconds. Default: 720
level_overrideintegerOptionalOverride the automatic complexity level for routing (1–5).

Level override

Use level_override to control the complexity level for routing (1–5). 5 is the most difficult and 1 is the least.

Response Format

Standard Response

When stream is false, the API returns a complete JSON response:

Cost Information

DynaRoute includes detailed cost information in the usage.cost object, showing both actual costs and GPT‑4.1 equivalent costs for comparison.

Routing Information

The _custom_routing_info object provides insights into how DynaRoute classified and routed your request.

Examples

Basic cURL Request

Streaming Response

For real‑time responses, enable streaming to receive chunks as they're generated:

Error Handling

Authentication Errors

Returns 401 for invalid or missing API keys.

{"error": {"message": "Invalid or unauthorized API key", "type": "authentication_error", "code": 401}}

Request Errors

Returns 400 for malformed requests or missing required parameters.

{"error": {"message": "No messages array found in request", "type": "invalid_request_error", "code": 400}}

Server Errors

Returns 500 for internal server errors or routing failures.

{"error": {"message": "Core routing logic is not loaded", "type": "server_error", "code": 503}}

Rate Limits & Usage

Request Tracking

All requests are tracked per API key with detailed usage metrics including token counts and costs.

Cost Optimization

DynaRoute automatically routes to cost‑effective models, with potential savings of up to 70% compared to premium models.

DynaRoute MCP Server

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.

Key Features

  • Intelligent Model Routing: Automatically classifies prompts and routes to the most cost-effective model while maintaining quality.
  • Cost Optimization: Save up to 70% compared to GPT-4.1 with per-request cost breakdowns and savings tracking.
  • API Key Management: Generate, verify, revoke, and list API keys directly from your MCP client.
  • Usage Analytics: Track token usage, costs, cumulative savings, and subscription status.
  • 11 MCP Tools: Full suite covering auth, routing, classification, models, costs, and usage.

Installation

Install via pip:

Quick Start

  1. Get your DynaRoute API key from DynaRoute
  2. Configure Claude Desktop by adding this to your claude_desktop_config.json:

  3. Restart Claude Desktop and start using DynaRoute!

Available Tools

The DynaRoute MCP server exposes 11 tools organized into three categories:

CategoryTools
API Key & Authdynaroute_generate_api_key, dynaroute_verify_api_key, dynaroute_revoke_api_key, dynaroute_list_api_keys, dynaroute_get_subscription
Routing & Modelsdynaroute_route_prompt, dynaroute_classify_prompt, dynaroute_list_models
Cost & Usagedynaroute_calculate_cost, dynaroute_get_usage_summary, dynaroute_get_cost_savings

Configuration

Environment Variables

  • DYNAROUTE_API_KEY: Your DynaRoute API key (required for authenticated tools)

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

Cursor IDE

Add to your Cursor settings:

Programmatic Usage

You can also import and use the server programmatically:

Requirements

  • Python 3.10+
  • DynaRoute API key
  • MCP-compatible client (Claude Desktop, Cursor, Claude Code, etc.)

Dependencies

  • mcp: Model Context Protocol SDK
  • firebase-admin: Firebase authentication and Firestore
  • aiohttp: Async HTTP for LiteLLM proxy calls

MCP Integration

DynaRoute'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.

MCP Tools Reference

API Key & Auth Tools

dynaroute_generate_api_key

Create a new DynaRoute API key for a user. The generated key uses the dr_ prefix and is stored in Firebase Firestore.

Parameters
NameTypeRequiredDescription
user_idstringYesFirebase user ID to create the key for
dynaroute_verify_api_key

Validate an API key and return its status, subscription tier, token limits, and remaining quota.

Parameters
NameTypeRequiredDescription
api_keystringYesThe DynaRoute API key to verify
Example Response
dynaroute_revoke_api_key

Deactivate an existing API key. The key will immediately stop working for all requests.

Parameters
NameTypeRequiredDescription
api_keystringYesThe API key to revoke
dynaroute_list_api_keys

List all API keys for a user. Keys are masked for security (only first 8 and last 4 characters shown).

Parameters
NameTypeRequiredDescription
user_idstringYesFirebase user ID whose keys to list
dynaroute_get_subscription

Fetch the current user's subscription tier, token limits, and usage. Uses the DYNAROUTE_API_KEY environment variable to identify the user.

Routing & Model Tools

dynaroute_route_prompt

Send 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.

Parameters
NameTypeRequiredDescription
promptstringYesThe user prompt to route
level_overrideint (1-5)NoOverride complexity level. 1 = cheapest, 5 = most capable
category_overridestringNoOverride category (e.g. "Code Generation", "Creative Writing")
Example Response
dynaroute_classify_prompt

Classify 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.

Parameters
NameTypeRequiredDescription
promptstringYesThe prompt text to classify
Example Response
dynaroute_list_models

Return all available models with their LiteLLM IDs and per-token costs (input and output cost per million tokens).

Example Response

Cost & Usage Tools

dynaroute_calculate_cost

Compute the cost for a given model and token counts. Also shows the GPT-4.1 equivalent cost so you can see the savings.

Parameters
NameTypeRequiredDescription
model_namestringYesModel name (e.g. "GPT-4.1", "Claude 4.5 Sonnet", "Gemini 2.5 Flash")
prompt_tokensintYesNumber of input tokens
completion_tokensintYesNumber of output tokens
dynaroute_get_usage_summary

Return usage statistics for the current user including total requests, tokens consumed, cumulative costs, savings, and subscription info. Uses the DYNAROUTE_API_KEY environment variable.

Example Response
dynaroute_get_cost_savings

Show GPT-4.1 equivalent cost vs actual cost for a model and token usage. Includes cumulative user savings when an API key is configured.

Parameters
NameTypeRequiredDescription
model_usedstringYesThe model that was used for the request
prompt_tokensintYesNumber of input tokens
completion_tokensintYesNumber of output tokens
Example Response

Classification Categories

DynaRoute classifies prompts into one of 31 categories:

LawBusinessEconomicsBiologyChemistryEngineeringPhysicsComputer ScienceMathematicsSyntax CheckCode GenerationCode ExplanationDebugging AssistanceAlgorithmSystem DesignLanguage TranslationSummarizationCreative WritingText Formatting & EditingGeneral KnowledgeHistoryGeographyPhilosophySociologyAstrologyHealthFactsLogicMiscellaneous

Complexity Levels

LevelDescriptionCost Tier
L1Foundational recall & direct taskLowest
L2Integrated analysis & multi-step reasoningLow
L3Complex synthesis & system designMedium
L4Expert-level evaluation & advanced formulationHigh
L5Novel synthesis & groundbreaking innovationHighest

Authentication

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.