Claude and the Anthropic SDK (TypeScript) · Chapter 21 of 21
Interview round
By the end of this chapter you have answered six timed questions, one idea each, from across the whole lab: reading any reply safely, a cache that never hits, JSON without forcing, what a photo costs, batch or real time, and retries that multiply. Each one ends with a measured run against the lab's Claude. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Ship it
- 6 tasks
- TypeScript
- In the all labs plan
The first 2 chapters of Claude and the Anthropic SDK (TypeScript) are free. This one comes with the all labs plan.
Why you need this
Sahay is live. Families get answers on WhatsApp, Kamla's desk reads the first draft of every claim, and Farhan watches the bill. Meher wants a second engineer for Sahay, and Arjun runs the interview the way he reviews code: "Short problems, ten minutes each. I do not care whether you remember a field name. I care whether you know the edge that breaks a Claude app in production, and whether you measure instead of guessing."
Every question is a bug Parchi really had, or nearly had: a family who got undefined, a cache that wrote on every request, a triage script that stopped working on a new model, a photo from a new phone, a batch nobody should have waited for, and an outage that sent twelve requests for one question. Each uses one idea from an earlier chapter, with no hand-holding: the file has the goal, the check has the edge cases, and every question is tried on requests the check makes itself. The ideas are below, as a refresher and as the things an interviewer listens for. The answers are not.
What you build: 6 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1 · interview question
Interview: read-any-reply.ts, why content[0].text fails
Time yourself: 10 minutes. Export readReply(reply): { text, tools, thought, complete }: the text blocks' text joined, the tool_use blocks' names in order, whether a thinking (or redacted_thinking) block is there, and whether stop_reason is end_turn. Never read content[0].
Under if (import.meta.main), ask 'claude-opus-5-5' (max_tokens 4096, Sahay's system prompt, TOOLS) How much will CLM-2402 pay? and print JSON.stringify(readReply(reply)). The check reads replies with tools, citations, a cut and none of those.
- Task 2 · interview question
Interview: stable-prefix.ts, what invalidates a cache
Time yourself: 10 minutes. oldRequest (given) writes the cache on every request and never reads it. Export buildRequest(question, now): the same request (model, max_tokens, the policy cached, the three tools, the question) with everything before the breakpoint the same byte for byte every time, and the date (now.toDateString()) still sent, after the cached part.
Under if (import.meta.main), send the three QUESTIONS (given) a day apart with oldRequest, then with buildRequest, and print old: read R1, R2, R3 and new: read R1, R2, R3 (the cache reads). The check sends four questions at four times through your buildRequest: every one after the first must read the cache.
- Task 3 · interview question
Interview: triage.ts, JSON without forcing
Time yourself: 10 minutes. Export Triage (zod: claim_id nullable string, category z.enum(CATEGORIES)) and triage(text): one client.messages.parse request to 'claude-haiku-5-5' (max_tokens 1024, a system prompt of your own, the text as the one user message, output_config: { format: zodOutputFormat(Triage) }), returning parsed_output. No tool_choice, no prefill.
Under if (import.meta.main), send oldTriage (given), catch the Anthropic.BadRequestError and print old: STATUS TYPE; then print JSON.stringify(await triage(text)) for Is CLM-2411 approved or still pending? and for Do you need a cancelled cheque for the claim?. The check triages inbox messages it never showed you.
- Task 4 · interview question
Interview: before-upload.ts, tokens from an image
Time yourself: 10 minutes. Export preflight(bytes): { ok: false, reason } for more than 5 MB or a side over 8000 px (size(bytes) is given); else { ok: true, tokens } where tokens is width x height / 750 rounded up, after scaling a long edge over 1568 px down to 1568 (both sides scaled and rounded).
Under if (import.meta.main), print FILE: N tokens for bill-CLM-2408.png and pharmacy-slip-ramesh.jpg. The check compares your answers with the API's own count for photos it makes up, two of which the API refuses.
- Task 5 · interview question
Interview: batch-or-now.ts, batch versus real time
Time yourself: 10 minutes. Export runDay(jobs): every job with 'claude-haiku-5-5', max_tokens 1024, system: SORT and its text. Waiting jobs go in real time, one messages.create each; the rest in ONE batch (custom_id the job's id), waited for and matched by custom_id. Return a Map from job id to label ('unknown' for a result that did not succeed).
Under if (import.meta.main), run JOBS (given) and print ID (now): LABEL or ID (batch): LABEL for each job in order. The check runs jobs of its own.
- Task 6 · interview question
Interview: retries-multiply.ts, which errors to retry, and how often
Time yourself: 10 minutes. Export requestsPerCall(sdkMaxRetries, wrapperTries): the most requests one call can send when the SDK's retries sit under a wrapper's tries.
Under if (import.meta.main), for new Anthropic() and then new Anthropic({ maxRetries: 0 }): labOutage(40), one withRetries (given) call that fails, the requests the lab saw meanwhile (labRequestCount, given), then clear the faults. Print default client: N requests (formula F) and maxRetries 0: N requests (formula F), with F from requestsPerCall(2, 4) and (0, 4).
What you will learn
- How to work a timed question: say the plan, name the edge, build the smallest thing that runs, then measure it.
- Six ideas again, at interview depth: content blocks (chapter 1), the cache's prefix (13 and 14), structured output instead of a forced tool or a prefill (2, 7 and 9), image tokens and limits (10), batches (17), and retries (18).
More in Ship it
Build "Interview round" yourself
Parchi, a Jaipur startup, helps families claim health insurance. You build Sahay, a claims assistant that reads bills and policies with Claude, and measure what caching, models and effort cost. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Claude and the Anthropic SDK (TypeScript) are free. This one comes with the all labs plan.