Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Verifieddanny/BurnGuard/llms.txt

Use this file to discover all available pages before exploring further.

BurnGuard calculates the cost of every Anthropic API call by multiplying the token counts returned in the response’s usage field against built-in pricing tables. No sampling or estimation is involved — every request is accounted for at its actual token cost. Pricing tables are compiled into the BurnGuard binary and updated with each release.

Model Pricing Table

The table below lists the per-1M-token rates encoded in analyzer.go. BurnGuard matches the model string returned by the API and selects the corresponding rate; any unrecognised model falls through to the default rate.
ModelInput ($/1M tokens)Output ($/1M tokens)
claude-fable-5$10.00$50.00
claude-opus-4-5, claude-opus-4-5-20251101, claude-opus-4-6, claude-opus-4-7, claude-opus-4-8$5.00$25.00
claude-sonnet-4-5, claude-sonnet-4-5-20250929, claude-sonnet-4-6$3.00$15.00
claude-haiku-4-5$1.00$5.00
All other models (default)$0.80$4.00

Cache-Aware Pricing

Anthropic’s prompt caching feature introduces two additional token categories beyond standard input tokens. BurnGuard reads all four usage fields from the API response and applies a separate multiplier to each category. Token categories and multipliers:
  • Standard input tokens (input_tokens): billed at the full input rate (multiplier: ×1.00)
  • Cache creation tokens (cache_creation_input_tokens): billed at 1.25× the standard input rate — a 25% premium charged when content is first written into the cache
  • Cache read tokens (cache_read_input_tokens): billed at 0.10× the standard input rate — a 90% discount applied when previously cached content is reused
Cost formula:
total_input_cost = (input_tokens × rate)
                 + (cache_creation_tokens × rate × 1.25)
                 + (cache_read_tokens × rate × 0.10)
Example calculation:
Model: claude-sonnet-4-5 (rate = $3.00/1M = $0.000003/token)

Input tokens:          1,000  →  1000 × $0.000003 × 1.00  =  $0.003000
Cache creation tokens:   500  →   500 × $0.000003 × 1.25  =  $0.001875
Cache read tokens:     2,000  →  2000 × $0.000003 × 0.10  =  $0.000600
                                                               ─────────
Total input cost:                                             $0.005475
The total cost for the response is total_input_cost + (output_tokens × output_rate).

How BurnGuard Parses Usage

BurnGuard extracts token counts through two code paths depending on whether the request uses standard HTTP responses or server-sent events (SSE) streaming. Non-streaming responses ExtractUsage() in parser.go JSON-unmarshals the full response body into a ClaudeResponse struct. The usage field maps to the following struct:
type ClaudeUsage struct {
    InputTokens              int           `json:"input_tokens"`
    OutputTokens             int           `json:"output_tokens"`
    CacheCreationInputTokens int           `json:"cache_creation_input_tokens"`
    CacheReadInputTokens     int           `json:"cache_read_input_tokens"`
    CacheCreation            CacheCreation `json:"cache_creation"`
}

type CacheCreation struct {
    Ephemeral5mInputTokens int `json:"ephemeral_5m_input_tokens"`
    Ephemeral1hInputTokens int `json:"ephemeral_1h_input_tokens"`
}
Streaming responses (SSE) ParseSSE() in sse.go accumulates SSE data lines as the response streams through the proxy. It looks for two specific event types:
  • message_start — carries the model name, initial input_tokens, and cache token counts. Cache creation tokens are sourced from the nested cache_creation object by summing ephemeral_5m_input_tokens and ephemeral_1h_input_tokens. Cache read tokens come from cache_read_input_tokens.
  • message_delta — carries the final output_tokens count in its usage field once generation is complete.
Both events must be present for a valid cost record to be written. If either is missing the stream is flagged as incomplete and no partial cost is recorded.
Pricing rates are compiled directly into the BurnGuard binary. If Anthropic updates their published prices, upgrade to the latest BurnGuard release to ensure your cost calculations reflect the new rates.

Build docs developers (and LLMs) love