Skip to main content

Overview

RAPTOR provides comprehensive cost tracking and budget enforcement for LLM API usage across multiple providers. All costs are tracked in real-time and enforced before budget limits are exceeded.

Real-Time Tracking

Track costs as requests are made, not after the fact

Budget Enforcement

Hard limits prevent runaway costs from expensive operations

Multi-Provider Support

Unified cost tracking for Anthropic, OpenAI, Gemini, Mistral, and Ollama

Cost Callbacks

LiteLLM integration provides automatic token counting and cost calculation

Cost Configuration

Setting Budget Limits

Default budget: $10.00 per scan
For production security research on large codebases, consider increasing to $25-50. For quick tests on small targets, $1-5 is usually sufficient.

Per-Model Pricing

RAPTOR automatically configures per-model costs based on current provider pricing:
Pricing is configured at initialization time. Update config.py if provider pricing changes.

Budget Enforcement

Pre-Request Checks

Before making any LLM request, RAPTOR checks if the estimated cost would exceed the budget:
Behavior:
  • Within budget: Request proceeds
  • Would exceed budget: Request blocked with clear error message

Hard Budget Limit

When budget is exceeded, RAPTOR raises RuntimeError with guidance:
Example error message:
Budget enforcement is a hard limit. Once exceeded, all LLM requests will fail until budget is increased or costs are reset.

Real-Time Cost Tracking

Token-Based Calculation

Costs are calculated based on actual token usage reported by LiteLLM:
Cost calculation:

Per-Provider Tracking

Each provider maintains its own cost counter:

Global Cost Aggregation

The client aggregates costs across all providers:

LiteLLM Integration

Automatic Token Counting

LiteLLM provides automatic token counting for all providers:
Supported providers:
  • Anthropic (Claude)
  • OpenAI (GPT)
  • Google (Gemini, PaLM)
  • Mistral
  • Ollama (reports tokens even though free)

Cost Callbacks

RAPTOR registers a LiteLLM callback for detailed cost visibility:
Callback benefits:
  • Atomic logging of every LLM call
  • Token usage from LiteLLM’s perspective (not just our calculation)
  • Duration tracking for performance analysis
  • Automatic error capture
Callbacks complement manual logging. Manual logs provide RAPTOR-level context (retries, fallbacks), while callbacks provide LiteLLM-level metrics (tokens, duration).

Cost Optimization Strategies

1. Response Caching

Avoid re-computing identical requests:
Cache key: sha256(model + system_prompt + user_prompt) Cache format:
Cache is not invalidated automatically. Clear out/llm_cache/ if you update prompts or want fresh analysis.

2. Model Selection

Use cheaper models for simpler tasks:
Task-specific models:

3. Prompt Optimization

Reduce token usage with shorter prompts:
Savings: 90% reduction in prompt tokens = 45% reduction in total cost (assuming 50/50 input/output split)

4. Quota Detection and Fallback

Automatic fallback when quota exceeded:
Quota guidance:

5. Local Model Usage

Use Ollama for free inference:
Trade-offs:
  • Zero cost: No API fees
  • Privacy: Data never leaves your machine
  • No rate limits: Run as many requests as hardware allows
  • Offline capable: Works without internet
RAPTOR warns when using Ollama for exploit generation:

Cost Reporting

Real-Time Statistics

Get current cost statistics during scan:
Example output:

Post-Scan Summary

After scan completion, RAPTOR reports total costs:

Budget Exhaustion Warning

When budget is nearly exhausted:
When budget exceeded:

Advanced Configuration

Per-Scan Budget Override

Cost Reset

Reset cost tracking between scans:

Disable Cost Tracking

Only disable cost tracking in development/testing environments. Production scans should always enforce budgets.

Cost Analysis Tools

Cost Breakdown by Task

Example output:

Cost Prediction

Best Practices

Set Realistic Budgets

Start with 10forsmallscans,10 for small scans, 25-50 for production. Monitor first scan to calibrate.

Enable Caching

Cache responses to avoid re-computing identical requests (can save 30-50%).

Use Task-Specific Models

Route simple tasks to cheaper models (Gemini for classification, Sonnet for analysis).

Monitor in Real-Time

Check client.get_stats() during scan to detect runaway costs early.
Always enforce budgets in production to prevent accidentally expensive scans.
Quota exceeded = provider rate limit (need to wait or switch provider)Budget exceeded = RAPTOR cost limit (need to increase max_cost_per_scan)
Use Ollama for development/testing, cloud models for production security research.

Troubleshooting

error
Cause: Scan hit cost limit before processing all findingsFix:
warning
Possible causes:
  • Using expensive model (Opus) for all tasks
  • Long prompts with unnecessary context
  • Cache disabled or not working
Debug:
info
Check:
  • Is enable_caching=True?
  • Are prompts identical (including whitespace)?
  • Does out/llm_cache/ directory exist?
Verify:

Further Reading

LiteLLM Cost Tracking

Official LiteLLM documentation on cost tracking features

Provider Pricing

Up-to-date pricing for all major LLM providers

Client Configuration

Full LLM client configuration reference

Optimization Guide

Comprehensive guide to optimizing LLM costs