Skip to content

Repository files navigation

DOSRouter

High-performance LLM router written in Go. Routes requests to the optimal model based on prompt complexity, cost targets, and capability requirements.

Go port of ClawRouter (TypeScript) - rewritten for lower latency and easier deployment.

Production-proven at DOS.AI - powering the DOS.AI inference API that serves thousands of LLM requests daily with automatic model selection, cost optimization, and multi-provider failover.

Features

  • 15-dimension weighted scorer - classifies prompts in ~0.04ms (40us) without any LLM call
  • Tier-based routing - SIMPLE / MEDIUM / COMPLEX / REASONING with configurable model pools
  • Cost optimization - automatic savings calculation vs baseline (opus-class) pricing
  • Multi-provider failover - primary + fallback providers per model
  • Agentic detection - identifies tool-calling patterns, routes to capable models
  • Session pinning - maintains model consistency within conversations
  • Streaming proxy - OpenAI-compatible SSE proxy with cost breakdown injection
  • 55+ models - built-in catalog with pricing, capabilities, and aliases
  • Zero dependencies for core routing - only stdlib

Architecture

router/ Core routing logic
types.go Type definitions (Tier, ScoringResult, RoutingDecision, etc.)
config.go Default config with multilingual keywords (9 languages)
rules.go 15-dimension weighted scorer (<0.04ms per classification)
selector.go Tier -> Model selection with cost/savings calculation
strategy.go Strategy pattern + promotions + agentic detection
llm_classifier.go LLM fallback for ambiguous requests
router.go Entry point (Route function)
models/ Model catalog
models.go 55+ model definitions, aliases, pricing, capabilities
proxy/ OpenAI-compatible proxy
proxy.go HTTP server with smart routing, SSE streaming, /debug endpoint
session/ Session management
session.go Conversation pinning with TTL and explicit user overrides
cmd/dosrouter/ CLI
main.go serve, classify, models commands

15-Dimension Weighted Scorer

#DimensionWeightDetection
1reasoningMarkers0.18"prove", "theorem", "step by step"
2codePresence0.15"function", "class", "import", code blocks
3multiStepPatterns0.12regex: first.*then, step \d, \d.\s
4technicalTerms0.10"algorithm", "kubernetes", "database"
5tokenCount0.08<50 tokens=-1.0, >500=+1.0
6creativeMarkers0.05"story", "poem", "brainstorm"
7questionComplexity0.05>3 question marks
8agenticTask0.04"edit", "deploy", "debug", "step 1"
9constraintCount0.04"at most", "O(n)", "limit"
10imperativeVerbs0.03"build", "create", "implement"
11outputFormat0.03"json", "yaml", "table"
12simpleIndicators0.02"what is", "hello" (negative!)
13referenceComplexity0.02"the code above", "the docs"
14domainSpecificity0.02"quantum", "FPGA", "genomics"
15negationComplexity0.01"don't", "avoid", "never"

Tier boundaries: SIMPLE < 0.0 < MEDIUM < 0.3 < COMPLEX < 0.5 < REASONING

Confidence: Sigmoid calibration 1/(1+exp(-12*distance)), threshold 0.7

Quick Start

CLI

# Classify a prompt
go run ./cmd/dosrouter classify "hello world"
go run ./cmd/dosrouter classify "Prove the Riemann hypothesis step by step"# Start proxy server
go run ./cmd/dosrouter serve --port 8080 --upstream https://api.example.com --api-key sk-xxx
# List models
go run ./cmd/dosrouter models

As a Library

import (
"github.com/DOS/DOSRouter/router""github.com/DOS/DOSRouter/models"
)
config:=router.DefaultRoutingConfig()
pricing:=models.BuildPricingMap()
decision, err:=router.Route(
"Write a distributed system with kubernetes",
"", // system prompt4096, // max output tokens
router.RouterOptions{
Config: config,
ModelPricing: pricing,
RoutingProfile: "auto", // "auto", "eco", "premium"
},
)
fmt.Printf("Model: %s, Tier: %s, Savings: %.0f%%\n",
decision.Model, decision.Tier, decision.Savings*100)

Build & Test

go build ./...
go test ./router/ -v
go test ./router/ -bench=. -benchmem

Performance

  • Classification: ~0.04ms per request (40us)
  • Zero external dependencies for routing
  • LLM fallback only for ambiguous cases (~20-30%)

Upstream Sync

This is a Go port of BlockRunAI/ClawRouter. Routing logic is synced periodically from upstream releases. Payment, plugin lifecycle, and CLI-specific features are excluded. See UPSTREAM_SYNC.md for details.

Current sync: v0.12.146

License

MIT

About

High-performance LLM router in Go. Powers DOS.AI inference API. Ported from ClawRouter (TypeScript).

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages