Last reviewed: November 7, 2026 (Asia/Shanghai). Public references were checked on November 6, 2026 UTC.
Direct answer
Treat a timeout or lost response as an ambiguous attempt whenever the request might have reached the provider. Save an application attempt record before dispatch, give it a stable opaque identity, and move it to submission_unknown when the client cannot prove whether the provider accepted it. Keep its reservation and possible cost visible. Reconcile provider response data, request IDs, response IDs, usage, and account evidence before deciding whether a new attempt is allowed.
A retry is a new billable possibility. It needs its own attempt number, admission decision, and reservation. Do not replay the original request just because the local socket closed. The replay can run beside work that the provider already accepted, leaving two charges and two results for one logical operation.
CometAPI’s public error guide separates request errors that should be fixed from 429, timeout-class, and temporary server failures that can be retried with backoff. It also tells operators to keep the request ID. Its Chat Completions reference exposes a response ID and a usage object whose token counts are used for billing. Those fields make reconciliation possible, but they do not turn a client timeout into proof that no work happened. The cost-estimation guide likewise treats a pre-call estimate as a budget guard and directs operators to use actual usage and billing records after completion.
The control has four outcomes: accepted_and_settled, rejected_before_dispatch, submission_unknown, and reconciled_absent. Only the last two require evidence work. An unresolved attempt stays visible until an owner can show that it was never accepted or can settle its usage. A missing field is unknown, not zero.
Who this is for
This guide is for platform engineers, FinOps owners, and service teams that call AI APIs through an SDK, gateway, queue worker, or scheduled job. It applies to chat, text, embedding, moderation, and other billable routes where a transport timeout can occur after the remote service has started processing.
It is especially useful for workloads with automatic retries, shared budgets, asynchronous workers, or user-visible side effects. It assumes the application can persist a small operational record and can inspect provider response or usage evidence through an approved account path. The examples use placeholders and do not require an API key or a live generation.
This is an application reconciliation pattern. It does not claim that any provider offers exactly-once execution, a universal idempotency key, a guaranteed cancellation, or a specific billing outcome for a timed-out call. Verify those properties for the exact route before relying on them.
Key takeaways
- Create the attempt identity and budget decision before the network call.
- Preserve the request fingerprint, provider request ID, response ID, route, model, and pricing revision without logging prompts or credentials.
- Classify a timeout after possible handoff as
submission_unknown; do not release its reservation or start a full replay. - Reconcile by the provider’s documented evidence and account records, then settle calculated usage separately from invoice confirmation.
- Retry only a bounded, retryable outcome, with a new attempt ID and a new reservation linked to the original logical operation.
- Tie the cost to a useful unit such as an accepted request, workflow, case, or token budget so a cheaper duplicate is still visible as duplicate work.
Contract details to verify
Define the identity before dispatch
Give each logical operation a stable operation_id and each provider call a distinct attempt_id. Store a private fingerprint of the exact route, model, request revision, input-data revision, output limit, tool configuration, and other response-affecting settings. A fingerprint helps find an earlier attempt; it is not proof that a provider will deduplicate a later call.
Record the budget scope and pricing revision used for the estimate. CometAPI’s cost guide says to combine the model’s current price with the endpoint’s billable units and configured output limit, then compare actual usage and billing records after completion. Keep the estimate labeled as an estimate. Do not rewrite it when a later price snapshot changes; add an identified adjustment instead.
A minimal record can look like this:
action: create_summary
operation_id: op-7f31
attempt_id: att-0001
request_fingerprint: fp-91c2
provider: cometapi
route: /v1/chat/completions
model: approved-model-id
pricing_revision: price-2026-11-06-a
estimated_input_tokens: 1800
reserved_max_cost: 0.012
state: admitted
provider_request_id: null
provider_response_id: null
usage_state: pending
Keep the payload, authorization header, and generated text in their approved data boundary. The cost record needs enough identity to reconcile work, not a second copy of the request.
Separate local failure from remote uncertainty
There are three useful points on the dispatch path:
- Rejected before dispatch: validation, authorization, or budget admission failed and the application can prove no upstream call was made. Release the reservation under the documented transaction rule.
- Accepted or completed: a provider response or durable response record exists. Store the provider identifiers and usage, validate the application result, and settle the attempt.
- Unknown after possible handoff: the client saw a timeout, connection break, process crash, or gateway failure after dispatch could have happened. Hold the reservation and reconcile.
The distinction matters because CometAPI’s error guide says malformed requests and authentication failures should not be retried, while 429 and temporary 500, 503, 504, or 524 failures can be retried with backoff. That classification tells you how to handle a known response. It does not answer whether a transport failure occurred before or after the provider accepted the request. Preserve the unknown state until another evidence source answers that question.
Keep retry and billing rules explicit
A retry policy should name eligible error classes, maximum attempts, backoff, jitter, deadline, and the owner of retrying. CometAPI shows exponential backoff with jitter for rate limits and temporary server failures. AWS guidance adds two constraints that matter for cost controls: retries are safest for idempotent operations, and known nontransient errors should fail fast. Treat those as design checks, not permission to replay every timeout.
Define the financial treatment for each state:
| State | Reservation | New upstream attempt |
|---|---|---|
admitted before dispatch claim | Held | One owner may dispatch |
rejected_before_dispatch | Released after proof | Allowed only after fresh admission |
accepted_and_settled | Settled from usage | Only if the product explicitly asks for another result |
submission_unknown | Held or conservatively accrued | Blocked until reconciliation or approved exception |
reconciled_absent | Released with evidence | A bounded retry may use a new reservation |
A lease expiry is not evidence that the provider never received the request. Release an unknown reservation only after the application can prove that dispatch was impossible or an approved policy converts the hold into an accounted charge.
Happy-path operator workflow
- Validate and estimate. Check the request shape, route, model, output ceiling, and budget scope. Estimate the maximum exposure from the current price revision. Reject malformed or unauthorised work before any network call.
- Persist admission. In one durable transaction, create the operation and attempt records, reserve the estimated maximum, and mark the attempt
admitted. The dispatcher must be able to claim this attempt only once. - Claim and dispatch. Record a dispatch timestamp and increment the local attempt counter immediately before the call. Send the request through the approved client. Do not place an unbounded retry loop inside a library wrapper that the ledger cannot see.
- Capture identifiers. On a response, store the provider response ID, any request ID from an error or response header, status class, and usage fields. CometAPI’s Chat Completions example returns
idand token usage; its error guide providesrequest_idas a safe operational field after secrets and large content are removed. - Validate and settle. Separate provider completion from application acceptance. A 2xx response may still fail a schema or business check. Record token usage once for the attempt, calculate cost with the bound pricing revision, and keep invoice reconciliation as a later evidence step.
- Close the operation. Mark the logical operation accepted, failed, or held. Release only unused reservation under the settlement transaction, and keep a link from the operation to every attempt and correction.
Use the same fields for synchronous and queued workers. A queue acknowledgement proves only that a local worker accepted a job; it does not prove that the provider accepted the remote request.
Error-path operator workflow
When a timeout or process crash occurs, first record submission_unknown and preserve the attempt ID, fingerprint, dispatch timestamp, and reservation. Do not let a generic worker retry hook create a second attempt while the first is unresolved.
Reconcile in this order:
- Check the local dispatch ledger and worker logs for a completed response, captured request ID, or response ID. Treat logs as evidence only when their retention and integrity are known.
- Query the provider’s documented status, request, or usage surface when one exists. Use the stored provider identifier and bounded time window. Do not search by raw prompt text.
- Compare account-visible usage or billing evidence after its stated reporting delay. CometAPI’s cost guide explicitly places actual usage and billing records after the request, so a missing immediate field should remain pending.
- Classify the result as accepted, rejected before dispatch, proven absent, or still unknown. Record the evidence source, access time, and reviewer.
- If and only if the result is proven absent or an owner approves a conservative exception, create a new attempt with a new ID, linked parent operation, fresh estimate, and bounded retry budget.
For a known 429 or temporary server error, follow the provider’s retry guidance, honor any retry delay, reduce concurrency when required, and count every attempt. For a 400, invalid request, authentication failure, or known spend/quota block, fix the cause or stop. Retrying a billing or quota error adds no useful evidence and can obscure the original decision.
If the provider returns a successful response but the application loses it before persistence, keep the attempt in usage_pending or completion_unknown until the response ID or account evidence is recovered. A second successful response does not erase the first possible charge.
Verification before rollout
Use a fake dispatcher and controlled provider fixtures before enabling rejection or automatic retry. These are acceptance criteria, not claims about a production run.
| Scenario | Required observation |
|---|---|
| Validation fails before dispatch | No provider call; reservation released under the transaction rule |
| Two workers receive the same job | One dispatch claim and one attempt record |
| Timeout before the client writes a dispatch marker | State reflects the local uncertainty; no automatic replay without reconciliation |
| Timeout after the provider may have accepted work | submission_unknown, reservation held, provider identifiers searched |
| Provider returns 429 with a retry hint | One bounded retry owner, delayed retry, and separate attempt cost |
| Provider returns 400 or invalid authentication | No retry; actionable failure recorded |
| Response is received but persistence fails | Attempt remains pending; response ID or usage reconciliation is required |
| Duplicate completion event arrives | One settlement; the second event is recorded as duplicate evidence |
| Usage is absent | Usage remains unknown or pending, never fabricated as zero |
| A retry is approved | New attempt ID, parent operation link, fresh reservation, and bounded deadline |
Measure more than request count. Track unresolved reserved value, unknown-attempt age, retry rate by error class, calculated cost versus billing evidence, and cost per accepted unit. The FinOps Foundation describes unit metrics such as cost per request, workload, token, or business case as a way to connect technology cost with value. Choose one denominator that the workload owner can explain, then keep it stable while comparing versions.
Failure modes
The client timeout is treated as rejection. The worker releases money and submits the same payload again. Preserve submission_unknown until evidence proves the original absent.
A response ID is saved only after parsing the full body. A crash during parsing loses a useful identity. Capture headers and provider identifiers as soon as the client exposes them, then persist the body under the approved content boundary.
SDK retries are invisible to the ledger. A library makes three attempts while the application records one. Configure one retry owner or reserve and record the library’s documented maximum exposure.
The request fingerprint contains secrets. Raw prompts, authorization headers, or personal data end up in logs. Hash a canonical, redacted representation and keep the mapping in restricted storage.
A lease releases an in-flight reservation. A quiet worker is assumed dead while its request is still running. Revoke dispatch ownership separately from financial certainty; an old worker must be unable to send again before a reservation is released.
A successful result is charged to every caller or retry. Logical operations, attempts, and settlements are conflated. Charge the provider usage once per attempt and link business outcomes to it.
Backoff is applied to permanent errors. Invalid requests, authentication failures, and spend limits continue to fail. Follow the provider’s error class and stop conditions instead of adding delay to an unrecoverable condition.
A unit metric changes during the comparison. One release reports cost per request while another reports cost per accepted case. Keep the denominator and scope visible so a lower number does not hide lower quality or more duplicate attempts.
FAQ
Is a timeout always billable?
No universal answer follows from a client timeout. The provider may have rejected the request, accepted it, or processed it before the connection failed. Keep the attempt pending and use provider and account evidence. Do not record zero without support.
Can an idempotency key solve the problem?
Only if the exact provider route documents its semantics and the application uses them correctly. An application attempt ID and fingerprint still matter for accounting and reconciliation. They do not prove that a provider will suppress a duplicate.
Should every 500 be retried?
Use the route’s current error contract. CometAPI documents temporary 500, 503, 504, and 524 failures as retryable with backoff, while a 500 carrying invalid_request should be fixed. Inspect the error type and code, cap attempts, and keep the first attempt visible.
When can an unknown attempt be released?
When durable evidence shows dispatch was impossible, or when an approved accounting policy converts the uncertainty into a recorded charge. A timeout, worker restart, lease expiry, or missing immediate usage field is insufficient by itself.
How should a budget owner compare retries?
Separate logical operations, provider attempts, calculated usage, and invoice evidence. Report total calculated cost per accepted unit: every original and retry attempt stays in the numerator, while each accepted logical outcome is counted once in the denominator. Track retry rate, attempts per operation, and unresolved spend as separate metrics so duplicate work cannot hide inside the unit-cost denominator. A retry that rescued a valuable operation can be justified; it still remains part of total cost and needs an owner.
What should routine logs contain?
Use operation and attempt IDs, route, model, pricing revision, status class, retryability, provider request or response ID, usage state, reservation, and a short decision reason. Exclude prompts, completions, credentials, and unrestricted error bodies.
Reader next step
Choose one high-volume AI API route and draw its dispatch boundary. Add an attempt record before the call, a one-time dispatch claim, a submission_unknown state, a provider-evidence lookup, and a settlement event that cannot run twice. Then exercise the timeout, duplicate-delivery, permanent-error, and missing-usage fixtures above.
Pair this control with Reserve AI API Budget Atomically Before Parallel Requests to make admission and reservation one decision. Use Trace CometAPI Cost and Usage for Token Budgets when the attempt has to be joined to account-visible usage or pricing evidence.
Approve automatic replay only after the first unresolved case has a documented resolution path, a bounded retry budget, and a unit metric that the cost owner accepts. Keep the evidence record with the operation so the next timeout is a reconciliation task rather than a guess.
Sources checked
- CometAPI: Handle API errors and retries — fetched November 6, 2026 UTC. Supports separating non-retryable request and authentication failures from retryable 429 and temporary server failures, exponential backoff with jitter, and retaining request IDs in sanitized logs.
- CometAPI: Create a chat completion — fetched November 6, 2026 UTC. Supports the OpenAI-compatible chat route, response IDs, request error examples containing request IDs, and usage fields used for billing.
- CometAPI: Estimate request cost before calling a model — fetched November 6, 2026 UTC. Supports pre-call cost guards based on current model pricing and configured units, followed by actual usage and billing reconciliation.
- AWS Prescriptive Guidance: Retry with backoff pattern — fetched November 6, 2026 UTC. Supports idempotency as a retry consideration, exponential backoff for transient faults, and fail-fast handling for known nontransient errors.
- FinOps Foundation: Unit Economics — fetched November 6, 2026 UTC. Supports documenting unit metrics such as cost per request, workload, token, or business unit and relating spend to value.
These sources describe public interfaces and operating principles. They do not establish exactly-once execution, account-specific billing treatment, a universal idempotency guarantee, or measured savings for a particular deployment. The state machine, reservation handling, evidence retention, and acceptance matrix are application recommendations.