The record to write for each call
Write one durable row per model call, keyed by a request or idempotency key, holding the requested model, the model or fallback step that actually served the request, input and output token or Neuron quantities, computed cost, and an outcome. Write it in the same durable write as the workflow step result, or as an idempotent upsert keyed by request ID, so retries do not duplicate it. This is our proposed design rule, not a source finding; the test at the end of this article settles whether your implementation works.
To be precise about what the sources support: Cloudflare's documentation establishes the need for model identity, token or Neuron quantities, a fallback-step indicator, and a timestamp with an outcome, because those are the quantities its pricing, limits and fallback behavior turn on. The remaining fields, input hash, workflow or tenant identifier, computed cost, start and end time, are design choices we propose for attribution and replay, not requirements the sources establish.
Why model identity and token counts decide cost
Cloudflare's Workers AI pricing documentation prices inference at $0.011 per 1,000 Neurons, with a free allocation of 10,000 Neurons per day, and lists per-model token prices that differ by model and by token direction. For example, it prices @cf/meta/llama-3.1-8b-instruct-fp8-fast at $0.045 per million input tokens and $0.384 per million output tokens, while @cf/meta/llama-3.3-70b-instruct-fp8-fast is listed at $0.293 per million input tokens and $2.253 per million output tokens. The same page lists cached input token prices for some models, such as $0.014 per million cached input tokens for one DeepSeek model.
Our inference from that pricing structure: because price varies by model and by token direction, a record that stores only a request count cannot reconstruct cost per call. You need the model identity and the input and output quantities as the provider meters them. Without those fields, aggregate spend can be compared to a provider invoice, but individual calls cannot be attributed to a workflow, tenant or feature.
Which model actually served the request
Cloudflare's AI Gateway fallbacks documentation says Cloudflare can trigger a fallback provider in response to request errors or predetermined request timeouts, and that the response header cf-aig-step indicates which step successfully processed the request: 0 means the primary model was used, 1 means the request fell back to the second model, 2 to the third, with each fallback incrementing the step number.
Our inference: if a fallback can change which provider or model produces an output, a call record without a served-model or fallback-step field cannot tell you whether the primary or the fallback produced a given response. That breaks cost attribution, since the fallback model may carry a different price, and any audit of whether fallback behavior matches your intent. We propose capturing the header value and the served model on each call record, rather than recording them once per workflow.
Timestamps and outcomes near limits
Cloudflare's Workers AI pricing documentation states that all limits reset daily at 00:00 UTC and that if you exceed a limit, further operations fail with an error. The Workers AI limits documentation lists a default text generation rate limit of 300 requests per minute unless the model requires the Workers Paid plan, and says paid models carry a per-account, per-model limit of 20 requests per minute under standard Workers AI billing, or 50 requests per minute with prepaid AI Gateway credits.
Our inference from those two pages: because calls can fail at a limit boundary and limits reset on a clock, a record needs a timestamp and an outcome field to distinguish a failed call from a successful one. We reason that a workflow counting only successful responses would understate both spend attempts and error-driven retries, while one counting attempts without outcomes would overstate delivered work. Treat that as our reasoning to check against your own pipelines, not a measured result.
Where the write happens relative to retries
The AWS Builders' Library article on idempotent APIs says retrying a service call as mitigation for a transient fault rests on the simplifying assumption that the operation can be retried without side effects, and defines an idempotent operation as one where the result happens only once even if the call is made multiple times in a retry loop. The article describes a network timeout that leaves a provisioning process unsure whether a workload is running, and notes that simply retrying could result in multiple workloads.
That guidance is about general API design, not AI calls specifically, so we propose applying it rather than citing it as established practice for inference logging. The proposal: write the call record either in the same durable write as the step result, or as an upsert keyed by the request ID, so a retried call updates one row instead of creating two. If the record write is a separate, non-idempotent append that happens after the model call returns, a timeout between the two writes loses the record, and a retry duplicates it.
The test that settles it
Proposed diligence step, not a source finding: before you rely on the record for caps or audits, run two checks against a non-production workflow. First, force a fallback, by configuring a primary model request that errors or times out per the Cloudflare fallbacks documentation, and confirm the stored record shows the fallback step and served model rather than the requested model. Second, retry a single request and confirm the record shows one row, or two rows sharing an idempotency key with a distinguishable attempt count, and that cost is not double-counted. Then reconcile one day of records against the provider's metered quantities. If any check fails, the record cannot yet support cost attribution or fallback audit.
Who owns each step
We propose this split, as a proposal rather than a source prescription. The platform or data team should own the record schema and the write path, because both workflows and finance will depend on them. Each workflow author owns emitting the request ID and input hash at call time. Whoever owns release criteria owns running the forced-fallback and retry test before the workflow is trusted with a spend cap. If no one owns the schema and write path today, that gap is the first thing to fix, because every other control built on the record inherits it.
Conditions that change the recommendation
The sources here are vendor documentation: the Cloudflare pages are undated product documentation describing Cloudflare's own metering and fallback behavior, and they do not establish how other providers meter or bill calls. The AWS guidance is general API idempotency, not AI-specific. No source supplies a universal call-record schema or proves these fields are sufficient for every audit, replay or cap; treat the schema as a floor to extend, not a finished standard. If your provider does not expose per-call token counts or a served-model indicator, check what it does expose before designing the record. And if a single model with no fallback serves every call, we still propose writing the served-model field, because it is what proves the configuration has not drifted.
