# claude-router

> Route Claude API calls to the cheapest model that works. Embedding-based task classification (~10ms) + 5 validated scaffolds. 11x cost reduction, blind-eval validated on 300+ API calls.

## Overview

claude-router classifies incoming prompts against pre-computed embedding centroids using nomic-embed-text via Ollama. Based on the task category, it routes to Haiku, Sonnet, or Opus and optionally prepends a task-specific scaffold that constrains the model's output to improve quality.

Key finding: scaffolded Haiku beats raw Sonnet on eval/content tasks. Scaffolded Sonnet beats raw Opus on research tasks. Scaffolds hurt coding and operational tasks (anti-finding).

## Usage

- [Quick Start](https://github.com/roli-lpci/claude-router#quick-start)
- [README](https://github.com/roli-lpci/claude-router#readme)

## Key Files

- router.py: Single-file router. ClaudeRouter class with .route() and .build_prompt() methods.
- scaffolds.json: 5 scaffold templates with constraint text, evidence, and usage guidance.
- data/centroids.json: Pre-computed task classification embeddings (768-dim, nomic-embed-text).
- data/routing_table.json: Category to model + scaffold lookup (12 categories).
- examples/basic_usage.py: End-to-end example with Anthropic API call.

## Dependencies

- Python 3, requests, numpy
- Ollama running locally with nomic-embed-text model

## License

MIT
