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/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 intelligent chat completions with automatic model routing and cost optimization. It's compatible with Claude Desktop, Cursor, and other MCP-compatible clients.

Key Features

  • Intelligent Model Routing: Automatically routes queries to the most cost-effective model while maintaining quality.
  • Cost Optimization: Save up to 70% compared to premium models like GPT‑4o.
  • Detailed Analytics: Get comprehensive metrics including token usage, costs, and performance data.
  • Routing Intelligence: See exactly which model was selected and why.
  • Easy Integration: Works seamlessly with Claude Desktop, Cursor, and other MCP‑compatible clients.

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!

Usage

Once configured, you can use DynaRoute in Claude Desktop by:

  • Asking for AI responses: "Use DynaRoute to explain quantum computing"
  • Requesting cost analysis: "Get a cost‑optimized response about machine learning"
  • Explicit tool usage: "Use the DynaRoute tool to answer this question"

Example Output

When you use the DynaRoute tool, you'll get:

🤖 DynaRoute Response:
[Your AI response content here]

📊 PERFORMANCE METRICS:
• Model Used: gcp-gemini-2.0-flash-thinking
• Response Time: 2.5 seconds
• Request ID: chatcmpl-xyz123

🔢 TOKEN USAGE:
• Input Tokens: 25
• Output Tokens: 150
• Total Tokens: 175

💰 COST BREAKDOWN:
• Input Cost: $0.000012
• Output Cost: $0.000045
• Total Cost: $0.000057

📈 COST SAVINGS vs GPT-4o:
• GPT-4o Equivalent Cost: $0.000175
• Your Actual Cost: $0.000057
• Money Saved: $0.000118
• Savings Percentage: 67.4%

✅ EFFICIENCY SUMMARY: DynaRoute saved you 67.4% compared to GPT-4o while maintaining quality!

Configuration

Environment Variables

  • DYNAROUTE_API_KEY: Your DynaRoute API key (required)

Tool Parameters

The dynaroute_chat tool accepts:

  • messages: Array of conversation messages (required)
  • level_override: Override complexity level 1–5 (optional)

Claude Desktop Configuration

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

Other MCP Clients

Cursor IDE

Add to your Cursor settings:

Custom Usage

You can also import and use the server programmatically:

Requirements

  • Python 3.8+
  • DynaRoute API key
  • MCP‑compatible client (Claude Desktop, Cursor, etc.)

Dependencies

  • mcp: Model Context Protocol implementation
  • dynaroute-client: Official DynaRoute Python client

MCP Integration

DynaRoute's MCP server enables seamless integration with all MCP‑compatible clients, allowing you to use intelligent model routing while maintaining your preferred AI interface.