Docs/Features/Prompt Classifier

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.

LevelScoreOpenAIAnthropic
trivial0-10gpt-5.4-miniclaude-haiku-4.5
simple11-30gpt-5.4-miniclaude-haiku-4.5
medium31-60gpt-5.4claude-sonnet-4.6
complex61+gpt-5.5claude-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/classifier
import { 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