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 OpenAI 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 fallback rate.
ModelInput ($/1M tokens)Output ($/1M tokens)
gpt-4o, gpt-4o-2024-11-20, gpt-4o-2024-08-06, gpt-4o-2024-05-13$2.50$10.00
gpt-4o-mini, gpt-4o-mini-2024-07-18$0.15$0.60
gpt-4.1$2.00$8.00
gpt-4.1-mini$0.40$1.60
gpt-4.1-nano$0.10$0.40
o3, o3-2025-04-16$2.00$8.00
o3-mini, o3-mini-2025-01-31$1.10$4.40
o4-mini, o4-mini-2025-04-16$1.10$4.40
o1, o1-2024-12-17$15.00$60.00
gpt-5$1.25$10.00
gpt-5-mini$0.25$2.00
gpt-5-nano$0.05$0.40
All other models (fallback)$2.00$8.00

Cached Prompt Token Discount

OpenAI’s prompt caching feature reduces costs when the same prompt prefix is reused across requests. BurnGuard reads both prompt_tokens and prompt_tokens_details.cached_tokens from the API response and splits the prompt cost into two buckets billed at different rates. How the split works:
  • prompt_tokens — total tokens in the prompt (cached + uncached combined)
  • prompt_tokens_details.cached_tokens — the subset that was served from OpenAI’s cache
  • uncached_tokens = prompt_tokens − cached_tokens
Cache discount rates:
  • Most models: cached tokens billed at 50% of the standard input rate
  • gpt-5.4, gpt-5.4-mini, gpt-5.4-nano, gpt-5.5, gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna: cached tokens billed at 10% of the standard input rate
Cost formula:
input_cost = (uncached_tokens × rate) + (cached_tokens × rate × cache_discount)
Where cache_discount is 0.50 for most models and 0.10 for gpt-5.4 and the listed gpt-5.5/5.6 variants. Example calculation:
Model: gpt-4o (rate = $2.50/1M = $0.0000025/token, cache_discount = 0.50)

Prompt tokens (total):  1,000
  Cached tokens:          400  →  400 × $0.0000025 × 0.50  =  $0.000500
  Uncached tokens:        600  →  600 × $0.0000025 × 1.00  =  $0.001500
Completion tokens:        500  →  500 × $0.00001            =  $0.005000
                                                                ─────────
Total cost:                                                    $0.007000

How BurnGuard Parses OpenAI 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 an OpenAIResponse struct. The usage field maps to the following struct:
type OpenAIUsage struct {
    PromptTokens     int `json:"prompt_tokens"`
    CompletionTokens int `json:"completion_tokens"`
    TotalTokens      int `json:"total_tokens"`
    PromptTokensDetails struct {
        CachedTokens int `json:"cached_tokens"`
    } `json:"prompt_tokens_details"`
}
Streaming responses (SSE) ParseSSE() in sse.go accumulates SSE data lines as the response streams through the proxy. It scans each line for a valid JSON chunk and looks for:
  • The model name in the first chunk that carries a non-empty model field
  • A final chunk where usage.total_tokens > 0, which contains the complete prompt_tokens and completion_tokens counts
If no chunk with usage data is found, the stream is flagged as incomplete and no cost record is written.
Cached-token discounts are applied only for non-streaming responses. In the SSE path, prompt_tokens_details.cached_tokens is not populated by the stream chunks BurnGuard reads, so all prompt tokens are billed at the full uncached rate.
Pricing rates are compiled directly into the BurnGuard binary. If OpenAI updates their published prices, upgrade to the latest BurnGuard release to ensure your cost calculations reflect the new rates.
gpt-4.1-nano at 0.10/1Minputtokensisthemostcostefficientmodelforsimpletaskssuchasclassification,extraction,orshortsummarisation.o1at0.10/1M input tokens is the most cost-efficient model for simple tasks such as classification, extraction, or short summarisation. `o1` at 15.00/1M input is the most expensive model BurnGuard supports — set a tight per-request or daily budget limit before routing traffic to it.

Build docs developers (and LLMs) love