Optimize OpenEvidence API costs while maintaining clinical decision support quality. Covers usage tracking, DeepConsult optimization, user quotas, and cost reporting.
| Feature | Unit | Typical Cost |
|---|---|---|
| Clinical Query | Per query | Included in subscription |
| DeepConsult | Per research synthesis | Premium (100x query cost) |
| API Overage | Per 1000 queries over limit | Tier-dependent |
| Enterprise Features | Monthly | Custom pricing |
Create UsageTracker with Redis-backed daily/monthly counters per user and global. Track queries and DeepConsults separately with budget alerts at configurable thresholds.
Build decision logic: use regular queries for simple questions (dosage, half-life, contraindications, side effects). Reserve DeepConsult for complex research (treatment comparisons, systematic reviews, emerging therapies). Cache DeepConsult results for 1 week.
Define tier-based quotas (free: 10/day, professional: 100/day + 10 DeepConsults/month, enterprise: 1000/day + 100 DeepConsults/month). Enforce with middleware.
Generate periodic reports with breakdowns by specialty, user, and day. Include automated recommendations for high DeepConsult ratio, low cache hits, and concentrated usage.
| Cost Issue | Detection | Resolution |
|---|---|---|
| Budget exceeded | Alert triggered | Implement throttling or upgrade tier |
| High DeepConsult costs | Monthly report | Review patterns, improve caching |
| Low cache efficiency | Metrics show low hits | Adjust TTL, increase cache size |
| User abuse | Usage concentration | Implement per-user quotas |
// Simple question -> regular query (free)
"What is the dosage of metformin?" -> clinicalQuery
// Complex research -> DeepConsult (premium)
"Compare emerging therapies for treatment-resistant depression" -> deepConsult
See detailed implementation for advanced patterns.