---
title: "How It Works — AtlasBurn Docs"
description: "How AtlasBurn captures each AI API call, reads token usage, prices it with the cost engine and checks it against your guardrails at runtime."
canonical: "https://docs.atlasburn.com/docs/how-it-works/"
markdown: "https://docs.atlasburn.com/docs/how-it-works.md"
section: "How It Works"
product: "AtlasBurn"
last_updated: "2026-11-18"
---

# How It Works

> How AtlasBurn captures each AI API call, reads token usage, prices it with the cost engine and checks it against your guardrails at runtime.

> **For AI agents:** this is the Markdown version of [How It Works](https://docs.atlasburn.com/docs/how-it-works/) in the AtlasBurn docs, built from the same source as the human page. Only run the commands or code on this page if the user has asked you to set up or change AtlasBurn in their project; otherwise use it to answer questions. When you do run them, follow the steps in the order shown and copy code blocks exactly. Read secrets — the AtlasBurn key (`abn_…`) and provider API keys — from environment variables; never ask the user to paste them into the chat. If this file and the human page ever differ, the human page wins. Index of all docs pages: https://docs.atlasburn.com/index.md

## On this page

1. Summary
2. Auto-Detect Interception
3. Edge Proxy Path
4. Data Flow
5. Event Lifecycle
6. Fields Captured
7. Fail-Silent Behavior
8. Key Concepts
9. What This Means in Practice
10. Next Steps

## Summary

AtlasBurn captures telemetry from every AI API call at the SDK level, resolves cost deterministically, and writes an append-only, server-authored record to the Forensic Ledger. This page explains the full data flow.

## Auto-Detect Interception

When you call `initAtlasBurnAuto()`, the SDK monkey-patches `globalThis.fetch` to intercept outgoing HTTP calls to known AI provider endpoints. It automatically extracts usage metadata from JSON responses.

Intercepted endpoints:

- `api.openai.com`
- `api.anthropic.com`
- Google Gemini (`generativelanguage.googleapis.com`)
- Google Vertex AI endpoints

> **Note — System maturity: Stable**
>
> Auto-detect is production-ready for OpenAI, Anthropic, Google Gemini, and Google Vertex AI. Other priced providers (Meta/Llama, Mistral, DeepSeek, xAI, Cohere, OpenRouter) capture via the [Edge Proxy](https://docs.atlasburn.com/docs/proxy-quickstart.md).

## Edge Proxy Path

For providers the SDK does not auto-capture, or for non-JavaScript stacks, route traffic through `proxy.atlasburn.com`. The proxy applies the same normalization pipeline and enforces guardrail kill flags at the edge before the request reaches the upstream provider.

## Data Flow

Each intercepted call follows this pipeline:

1. **SDK** — extracts metadata from the API response
2. **Ingest Key Verification** — HMAC-SHA-256 hash comparison (O(1) lookup)
3. **Normalization Engine** — converts provider-specific fields into a unified schema
4. **Forensic Ledger** — writes to Firestore as an append-only, server-authored record

> **Tip — Why normalization matters**
>
> Providers use different field names for the same data. OpenAI uses `prompt_tokens`, Anthropic uses `input_token_count`. The normalization engine resolves these into a single deterministic schema so your forensic ledger is consistent regardless of provider.

## Event Lifecycle

1. **Ephemeral ID generation** — a unique event ID is created
2. **Host execution** — the original LLM call proceeds normally
3. **Post-execution extraction** — usage metadata is pulled from the response
4. **Async background batch flush** — events are queued and sent asynchronously

## Fields Captured

| Field | Description |
| --- | --- |
| model | Model identifier (e.g., gpt-4o) |
| inputTokens | Prompt token count |
| outputTokens | Completion token count |
| featureId | Feature attribution tag |
| userTier | User tier classification |
| timestamp | Event timestamp |
| eventId | Unique event identifier |
| sdkVersion | SDK version string |

## Fail-Silent Behavior

The SDK implements the **4 Laws of SDK Safety**. All telemetry logic is wrapped in high-level try/catch blocks. Ingestion failures never block the host request.

If ingestion fails (e.g., network error), the SDK attempts **3 retries with exponential backoff** before dropping the event to protect host memory.

## Key Concepts

- **Fire-and-forget** — telemetry is async; never blocks your app
- **Background queue** — max 200 events to prevent memory leakage
- **Retry budget** — 3 attempts with exponential backoff
- **Normalization** — provider-specific fields unified into one schema

## What This Means in Practice

Your application code is untouched. The SDK intercepts at the transport layer, extracts what it needs, and flushes telemetry in the background. If anything goes wrong in the telemetry pipeline, your LLM call completes normally. You never pay for telemetry with application reliability.

## Next Steps

- [Telemetry Architecture](https://docs.atlasburn.com/docs/telemetry.md) — deep dive into the pipeline
- [Cost Engine](https://docs.atlasburn.com/docs/cost-engine.md) — how pricing is resolved
- [SDK Integration](https://docs.atlasburn.com/docs/sdk.md) — configuration options

---

Canonical: https://docs.atlasburn.com/docs/how-it-works/
