Maximum context window is explicitly configured per model
Why it matters
Hardcoded token limit numbers (if (tokens > 4000)) become silently wrong when you upgrade a model. GPT-3.5 turbo ran at 4K, then 16K. GPT-4o runs at 128K. Claude Sonnet at 200K. If the magic number in your route handler was written for an old model and the model is later swapped, every conversation will truncate far too aggressively — or not at all — with no indication that the limit constant is stale. ISO 25010 maintainability requires that configuration be centralized and named, not scattered as bare literals.
Severity rationale
Low because stale magic number limits degrade behavior silently on model upgrades but do not cause immediate crashes or security failures.
Remediation
Define a centralized MODEL_CONFIG object in src/lib/ai/models.ts that maps each model to its context window and pricing, then reference it by name throughout the codebase. Never write bare token-limit numbers in route handlers.
// src/lib/ai/models.ts
export const MODEL_CONFIG = {
"gpt-4o": { contextWindow: 128000, inputPricePer1M: 2.50, outputPricePer1M: 10.00 },
"gpt-4o-mini": { contextWindow: 128000, inputPricePer1M: 0.15, outputPricePer1M: 0.60 },
"claude-3-5-sonnet-20241022": { contextWindow: 200000, inputPricePer1M: 3.00, outputPricePer1M: 15.00 },
} as const;
export type SupportedModel = keyof typeof MODEL_CONFIG;
Verify by searching the codebase for bare token limit numbers (4096, 16384, 128000) in route handlers — none should appear as inline literals.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Token Optimization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability.modifiability — Modifiability — centralized model context-window configuration
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-token-optimization·automated