Prompt Classifier
Automatic prompt complexity detection that routes to the cheapest adequate model.
How it works
The classifier analyzes your prompt using static heuristics (zero latency) and assigns a complexity level. Each level maps to the cheapest model that can handle it well.
| Level | Score | OpenAI | Anthropic |
|---|---|---|---|
| trivial | 0-10 | gpt-5.4-mini | claude-haiku-4.5 |
| simple | 11-30 | gpt-5.4-mini | claude-haiku-4.5 |
| medium | 31-60 | gpt-5.4 | claude-sonnet-4.6 |
| complex | 61+ | gpt-5.5 | claude-sonnet-4.6 |
Signals
The classifier extracts these signals from your prompt:
- Token count — longer prompts tend to be more complex
- Code blocks — presence and line count
- File references — multi-file operations score higher
- Task keywords — refactor/architect vs fix/explain
- Constraints — "must", "ensure", "backward compatible"
- Conversation depth — deep sessions stay on current model
Standalone Package
npm install @costlens/classifierimport { classify } from '@costlens/classifier';
const result = classify({
prompt: 'Fix the typo in line 3',
currentModel: 'gpt-5.4',
provider: 'openai',
messageCount: 3,
routingMode: 'balanced',
});
// => { level: 'simple', suggestedModel: 'gpt-5.4-mini', confidence: 0.78 }Safety Rules
The classifier will never downgrade when:
- It's the first message in a session
- Prompt contains "careful", "production", "critical"
- Conversation is deeper than 15 turns
- The suggested model would be more expensive