Skip to content
atom®technologiesBook a call
Production AI

The per-attempt AI call record: what to persist so fallbacks and rate limits stay attributable

Require one durable record per model attempt with request identity, model name, token counts, computed cost, fallback step, timestamp and outcome, then verify it with a forced fallback and a rate-limit-adjacent request reconciled against published prices.

A packed auditorium during a technology keynote

The direct answer

Persist one record per model attempt, not per user request. Each record needs a stable request identity, the model name as routed, input and output token counts, the cost you computed for that attempt, the fallback step, a timestamp and an outcome status that separates a failed attempt from a completed one. Then test it: force one fallback and one rate-limit-adjacent request, and reconcile the record against the provider's published prices and limits.

The failure mode: totals that cannot be attributed

The decision here is what your pipeline writes down when a call goes through a gateway that can reroute between models. The failure mode is a cost and quality record that only makes sense when nothing unusual happens. Cloudflare's AI Gateway documentation says Cloudflare can trigger a fallback provider in response to request errors or predetermined request timeouts, and that by default the fallback fires when a model request returns an error; the timeout behavior is something you configure, not a constant. The same page documents the response header cf-aig-step, which indicates which step successfully processed the request: 0 means the primary model, 1 the second, 2 the third, and each further fallback increments the number. That header travels in the response, so if your pipeline does not capture it into its own storage at request time, the fact that a request was answered by a different model than the one you configured is gone once the response is returned. We infer from the pricing and fallback documentation together that a workflow recording only a total cost cannot attribute that cost to a specific model or fallback step once routing has changed.

What the pricing model forces into the record

Cloudflare's Workers AI pricing page shows why the model name and token counts are not optional fields. Workers AI is priced at $0.011 per 1,000 Neurons, with a free allocation of 10,000 Neurons per day, and all limits reset daily at 00:00 UTC. The same page lists separate input-token and output-token prices per model: for example, $0.027 per million input tokens and $0.201 per million output tokens for the Llama 3.2 1B instruct model, versus $0.293 per million input and $2.253 per million output for the Llama 3.3 70B fp8-fast model, and $1.320 per million input and $3.960 per million output for DeepSeek v4 Pro. Those prices differ by more than an order of magnitude. A record that says one call, some tokens, one cost cannot be audited against any of them. Because the free allocation resets daily at a fixed UTC time, we infer that a useful record also needs a timestamp, since usage can only be interpreted against the allocation window if you know when it happened.

Rate limits make the timestamp and model identifier load-bearing

Cloudflare's Workers AI limits page documents default rate limits by task type, including 300 requests per minute for text generation unless the model requires the Workers Paid plan, and per-account, per-model limits for paid models of 20 requests per minute under standard Workers AI billing, or 50 requests per minute with prepaid AI Gateway credits. The page notes beta models may have lower rate limits. Two consequences follow, and both are inferences from these documented limits. First, whether a burst of requests was inside or outside a limit depends on the model and the minute, so the record needs both. Second, if you want to cap spend or throttle before the provider does, your cap logic has to count per model and per window, which requires per-attempt records to count from.

Retries and outcome status

The AWS Builders' Library article on idempotent APIs describes retrying as a common way to overcome transient faults, notes that AWS has baked default retry behavior into some of its SDK implementations for network I/O failures, server-side faults and service rate limiting, and warns that retries can create duplicate side effects unless the operation is idempotent. For an AI workflow the practical translation is that a retried or failed-over request may result in several attempts, some of which failed and one of which succeeded. A record that counts attempts as outcomes will double-count cost and misreport success. The proposal that follows from this: your outcome status field must distinguish a failed attempt from a successful fallback attempt, so replay and cap logic do not treat a failed call as a completed outcome.

A proposed minimum record

This schema is a proposal from us, not a documented Cloudflare or AWS requirement. Per model attempt, persist: a stable request identity shared by every attempt of the same logical request; the model name as routed; input and output token counts; the cost you computed for that attempt using the provider's published per-model prices; the fallback step captured from the cf-aig-step response header; a timestamp; and an outcome status. An input hash is a further field we propose as a replay aid, letting you re-run or re-price a request later; it is our addition, not a field the cited Cloudflare or AWS documentation specifies. Whether this schema is sufficient for a full audit or replay is our inference, and the two-scenario test below is how we would check that inference in your pipeline before treating the record as trustworthy. NIST describes its AI Risk Management Framework as guidance intended for voluntary use, with the stated aim of cultivating trust in AI technologies and promoting AI innovation while mitigating risk. If your organization aligns to that framework, we infer per-attempt records are one input such a review would draw on; treat that as our inference from the framework's stated aim and a proposal about your pipeline.

The two-scenario diligence test

Proposed test, runnable by whoever owns your data platform before release. Scenario one: force one fallback, either by pointing the primary step at a model that will error or by configuring a timeout short enough to trigger the documented timeout behavior. Then confirm the recorded fallback step matches the cf-aig-step value in the response, and that the recorded model is the fallback model, not the configured one. Scenario two: send a rate-limit-adjacent request, close to the documented requests-per-minute figure for your task type or model, and confirm the timestamp and model fields let you reconstruct whether the limit applied. In both scenarios, recompute cost from the recorded token counts and the provider's published prices and check it against the recorded cost. Any mismatch is a finding about your pipeline, not a claim about the provider.

Ownership and what would change the recommendation

The engineering leader owns the schema decision and the release gate; the data platform owner runs the two-scenario test and owns the reconciliation; whoever owns model routing owns capturing the fallback header at request time, because it cannot be recovered later. The recommendation changes under specific conditions. If you stop using a gateway with fallback routing and call one model directly, the fallback step field stops carrying information, though the model name, token counts, timestamp and outcome still let you reconcile cost against per-model pricing and daily resets. If your provider's prices or limits change, and Cloudflare's pages are undated live documentation that can change, your computed-cost field needs a price-version reference or a recompute step. If you add a second provider, the same schema extends, but the evidence here covers Cloudflare's product only, and other providers' billing and fallback semantics are outside what it establishes.