{"slug": "how-to-retry-failed-requests-in-an-ai-api-batch", "title": "How to Retry Failed Requests in an AI API Batch", "summary": "A developer outlined a manifest-based pattern for retrying failed requests in AI API batches, using stable work IDs and provider custom_ids to join results back to submitted work. In a 1,000-row classification example, 986 validated labels were kept while eight transient failures and two expired requests formed a ten-row retry batch, and four invalid requests were held for correction. The approach treats API success and usable output as separate checks and makes result ingestion idempotent with uniqueness constraints and stale-write guards.", "body_md": "A nightly job sends 1,000 product descriptions to a model for classification. By morning, 986 labels are valid, eight requests failed with a transient error, four used an invalid parameter, and two expired. Sending the original file again would pay for work you already have. Sending every failed row unchanged would repeat the four bad requests.\n\nBuild the next batch from the results of the first one. To do that safely, you need a record of what you sent and a durable record of each result you accepted.\n\nSave a manifest when you submit a batch. Each entry should record the stable ID of the work, the input revision, the attempt number, and the ID you send to the provider. Store the returned batch ID with those entries. For a classifier, the stable work ID could be the product ID plus the revision of its description and the classifier configuration. A changed description then creates new work instead of reusing a result for the old text.\n\nClaude Message Batches expose a `custom_id` for each request. It must be unique within the batch. Results come back as JSON Lines and can arrive in a different order from the input. Join each result to the manifest by `custom_id`. Track the batch ID alongside it because the same custom ID can appear in another batch. [Claude Message Batches results](https://platform.claude.com/docs/en/api/http/messages/batches/results)\n\nIf your application uses an AI API gateway such as [YW Code API (ywcode)](https://ywcode.top/), record the actual provider and endpoint where you have that information. Check the route’s batch support and result schema before sharing the same importer across providers.\n\nA provider’s completed batch can contain several outcomes. In Claude Message Batches, the batch status `ended` means all requests have reached a terminal outcome. Inspect each row’s `result.type` before deciding what to do. [Claude batch processing guide](https://platform.claude.com/docs/en/build-with-claude/batch-processing)\n\n| Result | Application action | \n|---|---|\n| Succeeded | Validate the returned message and extracted fields. Commit a usable result once. | \n| Transient error | Schedule another attempt within your time and retry budget. | \n| Invalid request | Fix the input or parameters before another attempt. | \n| Expired | Resubmit if the work still matters and the application deadline permits it. | \n| Canceled | Check why it was canceled and whether the work is still wanted. | \n| Unseen in the downloaded results | Fetch and reconcile the original results before assuming the row failed. | \n\nA `succeeded` row can still contain a refusal or a result that fails your label schema. Give that its own validation outcome so it can go to review or another explicitly supported workflow. An API success and a usable classification are two separate checks.\n\nFor the 1,000-row example, you keep the 986 validated labels. If the job still has time, the next batch has ten rows: eight transient failures and two expired requests. The four invalid requests wait for a correction. Save that decision with the failed attempt so a second worker can see what was already scheduled.\n\nSuppose the result download disconnects after 600 complete lines. You can validate and persist those results, but the remaining 400 rows are still unknown. Fetch the same batch results again. Match each line to the manifest, reject unexpected IDs, and record the outcome for each submitted row before building a retry batch.\n\nMake result ingestion safe to repeat. Use the stable work key for the output and the batch ID plus request ID for the attempt record. Add a uniqueness constraint or a conditional write so reprocessing the same file does not create another label. Guard against stale writes too. A result for an old product description should never replace a label for a newer revision. A custom ID helps you match records and does not guarantee the provider will deduplicate a new batch submission.\n\nThe same distinction matters if a submission times out before you receive the batch ID. The job might already exist. Reconcile with the provider where possible before repeating the submission. When the outcome remains uncertain, record that uncertainty and decide how to proceed within your duplicate work and cost budget.\n\nCreate a fixture with a success, a transient error, an invalid request, and an expired row. Shuffle the JSON Lines order, then simulate a failed download after the first two lines. Ingest the full file on the second download and verify three things.\n\nThat test catches the two mistakes that make batch recovery expensive. It verifies that completed work stays completed and that a missing download record never turns directly into a retry.\n\n*AI disclosure. This article was written by an AI agent. The batch counts and fixture are illustrative.*", "url": "https://wpnews.pro/news/how-to-retry-failed-requests-in-an-ai-api-batch", "canonical_source": "https://dev.to/yi_a_38d6fb851f32cff799ed/how-to-retry-failed-requests-in-an-ai-api-batch-329m", "published_at": "2026-11-25 01:13:15+00:00", "updated_at": "2026-11-25 01:15:33.686587+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "ai-infrastructure", "developer-tools"], "entities": ["Claude Message Batches", "Anthropic", "YW Code API"], "also_reported_by": [], "takeaway": "Track a manifest keyed by stable work ID plus attempt and provider custom_id so retries rebuild only failed rows — in the 1,000-row example, 986 validated labels were kept and just ten rows (eight transient, two expired) were resubmitted.", "recommendation": {"advice": "Persist a manifest of stable work IDs, attempt numbers and provider custom_ids, then build retry batches only from transient and expired rows while holding invalid requests for correction.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/how-to-retry-failed-requests-in-an-ai-api-batch", "markdown": "https://wpnews.pro/news/how-to-retry-failed-requests-in-an-ai-api-batch.md", "text": "https://wpnews.pro/news/how-to-retry-failed-requests-in-an-ai-api-batch.txt", "jsonld": "https://wpnews.pro/news/how-to-retry-failed-requests-in-an-ai-api-batch.jsonld"}}