Skip to main content

HiveRoute — Intelligent Model Routing

HiveRoute is ModelHive's zero-cost intelligent model routing system that automatically routes LLM requests to the most appropriate model based on task difficulty. Simple questions go to fast, cheap models; complex tasks go to powerful frontier models — all transparently.

Why HiveRoute?​

Without HiveRouteWith HiveRoute
Same expensive model for every requestCheap model for trivial tasks, frontier for complex
Manual routing logic in your codeAutomatic classification — no code changes
Overpaying for simple queriesUp to 70% cost reduction on mixed workloads
No reasoning effort controlAutomatic reasoning_effort / thinking.budget_tokens injection

How It Works​

HiveRoute is a sub-feature of HiveState. When HiveState extracts the conversation state, it also classifies task difficulty and reasoning effort. HiveRoute then uses this classification to select the optimal model.

Processing Steps​

  1. Request arrives at /v1/chat/completions or /v1/messages
  2. HiveState extracts conversation state (including difficulty and reasoning_effort)
  3. HiveRoute maps difficulty → target model from configured levels
  4. The request's model field is transparently rewritten to the target model
  5. For reasoning models: reasoning_effort (OpenAI) or thinking.budget_tokens (Anthropic) is injected
Zero Extra Cost

HiveRoute piggybacks on the HiveState extraction that's already happening — there's no additional LLM call or latency for the routing decision.

Difficulty Levels​

HiveRoute classifies every request into one of three difficulty levels:

LevelExamplesTypical Model
trivialSimple questions, typo fixes, one-line changes, status checksLlama 8B, GPT-4o-mini
standardNormal coding tasks, feature implementation, explanationsGPT-4o, Claude Sonnet
complexArchitecture decisions, complex multi-file debugging, system designClaude Opus, GPT-4o (high reasoning)

Request Headers​

HeaderValuesBehavior
x-hive-route"false"Opt-out of HiveRoute model routing (HiveState compression still applies)
x-hive-state"false"Opt-out of both HiveState and HiveRoute (since HiveRoute depends on HiveState)

Response Headers​

HeaderExampleDescription
x-hiveroute-levelstandardDifficulty level classified (trivial, standard, complex)
x-hiveroute-modelgpt-ossTarget model the request was routed to
x-hiveroute-effortmediumReasoning effort injected (low, medium, high)

Usage Examples​

from openai import OpenAI

client = OpenAI(
api_key="sk-your-modelhive-key",
base_url="https://api.modelhive.ai/v1"
)

# Request any model — HiveRoute may transparently route to a better fit
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "What's 2+2?"} # trivial → routed to cheap model
]
)

# Check routing decision via response headers
# x-hiveroute-level: trivial
# x-hiveroute-model: llama-8b
# x-hiveroute-effort: low

Reasoning Effort Injection​

HiveRoute doesn't just select the model — it also injects the appropriate reasoning effort level:

OpenAI Models​

Sets the reasoning_effort field in the request body:

EffortValue
Low"low"
Medium"medium"
High"high"

Anthropic Models​

Enables extended thinking with calibrated budget_tokens:

EffortDefault Budget
Low1,024 tokens
Medium4,096 tokens
High16,384 tokens
// Automatically injected for Anthropic models
{
"thinking": {
"type": "enabled",
"budget_tokens": 4096
}
}

Load Balancing & Failover​

When multiple deployments exist for the same model, the Router layer handles load balancing:

Routing Strategies​

StrategyBehavior
shuffleRandom order each request (default)
round-robinSequential cycling through deployments
latencyPrioritize lowest-latency deployments (EMA-based)

Circuit Breaker​

Each deployment has automatic circuit breaker protection:

  • Opens after 3 consecutive failures (configurable)
  • Stays open for 60 seconds (configurable recovery period)
  • On success: resets failure counter
  • When all deployments broken: tries anyway (half-open mode)

Retry Logic​

  • Up to 3 retries with exponential backoff
  • Retryable: 429, 500, 502, 503, 504, 408, network errors
  • Non-retryable: 400, 401, 403 → fail immediately

Response Headers (Failover Info)​

HeaderExampleDescription
X-Modelhive-Providerazure-eastDeployment that served the request
X-Modelhive-Attempts2Number of attempts (only if >1)
X-Modelhive-Failedazure-west,openaiProviders that failed before success
X-Modelhive-Cost0.0012340000USD cost of the request

Supported Endpoints​

HiveRoute applies to all chat/completion endpoints:

MethodEndpointHiveRouteLoad Balancing
POST/v1/chat/completions✅✅
POST/v1/messages✅✅
POST/v1/completions❌✅
POST/v1/embeddings❌✅
Activation Condition

HiveRoute only activates when HiveState is triggered (conversation above the token threshold). For short conversations below threshold, the request goes to the originally specified model.

Cost Optimization

For maximum savings, combine HiveRoute with HiveCache. HiveCache handles repeated queries instantly, while HiveRoute ensures fresh queries use the cheapest adequate model.