claudio.cool
CCDV-FLessons

CCDV-F · Applications and Integration

Integration resilience, error classes, streaming events and the Files API

⏱ 4 min readDraft

A worker retries every failure five times without looking at which one it is. The audit finds thousands of retries that could never succeed. A streaming chat shows answers that stop mid-sentence next to a dashboard that says “100% success”. And a document upload module works with PDFs and breaks with a spreadsheet. All three are integration defects, and the exam asks you to find them in the code or the error and pick the fix that respects how the API behaves.

The question that organizes everything

If I send exactly the same thing in a while, can it succeed? If yes, it is a transient error and you retry. If no, retrying only burns time and quota: fix the request or send it another way.

Code and type What it means What to do
429 rate_limit_error You went over a rate limit Retry with exponential backoff and jitter, honoring retry-after
500 api_error Internal Anthropic error Retry with backoff
529 overloaded_error The API is overloaded Retry with backoff; if it persists, fall back to another model
504 timeout_error The request took too long Streaming or batches for long requests
400 invalid_request_error Malformed request, or uses something the model does not accept Read the message and fix it; never retry as is
401 / 403 Invalid key or no permission Check credentials and permissions
413 request_too_large Request too big Shrink the input or use files

The official SDK already retries connection errors, 429s and 5xx with backoff (twice by default). If you also wrap every call in your own five-retry loop, you multiply the load exactly when the API is saturated. And if a retry could duplicate an effect (a charge, an email), the request to your own backend needs an idempotency key: the second attempt with the same key returns the stored result instead of repeating the operation.

What arrives with HTTP 200

Some problems are not HTTP errors. Look at the stop_reason:

  • max_tokens: the response hit the limit and was cut off. Raise the limit for that feature and do not show the text as complete.
  • refusal: the model declined. It arrives as a 200, so a dashboard that counts HTTP codes never sees it; it goes down another path (rephrase, fallback, human review).

Streaming: which event closes what

The sequence is message_start and, for each block, content_block_start, several content_block_delta and content_block_stop; at the end, message_delta and message_stop.

  • content_block_stop closes one block, not the message. A handler that treats the first one as the end misses the blocks that follow (for example, a tool_use after the text).
  • The stop_reason travels in message_delta, not in message_start. If you never read it, a response cut off by the limit is shown as complete.
  • The terminal event is message_stop. If the stream drops without it, the response is incomplete: discard it or flag it, do not store it.
  • An error can arrive inside the stream even though the API already answered 200. Treat it as the error it is.
  • Tool inputs arrive as input_json_delta fragments: accumulate them and parse only when the block closes.

Several formats with the Files API

The Files API uploads a file once and then references it by file_id in content blocks, without resending the bytes on every request. It works for PDFs, text and images. A spreadsheet, a docx or a CSV does not go in as a document: convert it to text first and send it as text. A module that branches only on file extension and assumes everything “is a PDF” fails exactly with the odd formats; one that validates type and size before uploading (and handles the 413) does not.

The typical traps

  • Retrying a 400, 401 or 403 “just in case”.
  • Retrying with no backoff, all clients at once, or ignoring retry-after.
  • Two stacked retry loops: yours and the SDK’s.
  • Taking the first content_block_stop as the end of the message.
  • Storing as success everything that came back 200 without checking stop_reason or message_stop.
  • Raising max_tokens or changing models before reading which error it is.

On the exam

Read the code, the error type and the stop_reason the scenario gives. If it asks which to retry, pick the transient ones (429, 500, 529) and drop those describing a problem with the request or the credentials. If a stream “ends fine” but the text is cut off, look for the option that reads stop_reason in message_delta and waits for message_stop. If one specific format fails, look for converting it before sending it.

Quick question

A practice exam question on this domain. It counts towards your progress.

A data-platform team uses Claude Code daily on a monorepo. Their project CLAUDE.md includes the line "Never run database migrations; ask a human instead." Most of the time Claude follows it.

Last week, during a long session fixing a failing test, Claude ran the migration script against the shared staging database. The developer had approved the command quickly without reading it. No customer data was affected, but the staging data had to be restored from a backup.

The team lead proposes rewriting the line in capital letters and repeating it in three places in CLAUDE.md.

The team has twelve developers, and everyone uses the same committed .claude/settings.json file.

What is the most reliable way to prevent this from happening again?

Practise this domain in a practice exam →