Ragex.AI.Usage
(Ragex v0.8.0)
View Source
Tracks AI provider usage including requests, tokens, and estimated costs.
Maintains statistics per provider with time-windowed tracking for rate limiting.
Configuration
config :ragex, :ai_limits,
max_requests_per_minute: 60,
max_requests_per_hour: 1000,
max_tokens_per_day: 100_000Cost Estimation
Pricing as of January 2026 (subject to change):
- OpenAI GPT-4-turbo: $0.01/1K input, $0.03/1K output
- OpenAI GPT-3.5-turbo: $0.0005/1K input, $0.0015/1K output
- Anthropic Claude-3-Opus: $0.015/1K input, $0.075/1K output
- Anthropic Claude-3-Sonnet: $0.003/1K input, $0.015/1K output
- Anthropic Claude-3-Haiku: $0.00025/1K input, $0.00125/1K output
- DeepSeek R1: $0.001/1K input, $0.002/1K output
- Ollama: Free (local)
Summary
Functions
Check if rate limits would be exceeded by a new request.
Returns a specification to start this module under a supervisor.
Get usage statistics for a provider or all providers.
Record a request with token usage.
Reset all usage statistics.
Functions
Check if rate limits would be exceeded by a new request.
Returns :ok if within limits, {:error, reason} if limit would be exceeded.
Returns a specification to start this module under a supervisor.
See Supervisor.
Get usage statistics for a provider or all providers.
Record a request with token usage.
Reset all usage statistics.