Batch API lab
Define the lab goal and success criteria
Ship a falsifiable slice of **overnight batch job that grades 50k support transcripts via provider Batch API** — success is fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40, not a polished screenshot.
1Try it yourself
Decision drill
Batch API lab
Sync for interactive latency — batch for large offline embed/index builds.
1/3Embed 1 query at request time while a user waits in the UI.
2Learn the idea
Read
Name the operable slice
This lab builds overnight batch job that grades 50k support transcripts via provider Batch API. The human in the loop is QA lead who needs cost-capped offline eval by 07:00 UTC. Scope is intentionally narrower than “make AI reliable”: you will prove one oracle — fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40 — and one invariant — each input line has a stable custom_id; failed lines never poison the whole file. Record non-goals in your notes so a later change cannot silently expand authority. The incident mnemonic for the chapter is BATCH-DUP-8841; design as if that ticket is already written and you are filling evidence.
Read
Write the acceptance contract
Turn the oracle into a table: input fixture, expected observable, prohibited side effect, owner, latency/cost ceiling. Separate model taste from software correctness — transport, auth, parsing, and termination must be deterministic even when generated text varies. Primary metric family: batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8. Averages without a denominator or revision label do not gate release. Fake external dependencies in unit tests; live calls wait until fakes pass.
Read
Implementation artifact
{"custom_id":"ticket-1042","method":"POST","url":"/v1/chat/completions","body":{"model":"gpt-4.1-mini","messages":[{"role":"user","content":"Grade tone 1-5"}]}}
Read
Freeze the first red test
Before implementation, encode a failing check that would have caught duplicate custom_id causes silent overwrite of the better grade. That failure is the pedagogical north star for later pages: contracts reject it, happy path never performs it, validation asserts it, failure-handling contains it, observability detects it, security-ops prevents privilege tricks around it, and mastery replays it in a drill. Endpoint under study: POST /v1/batches.
Read
Stage depth
Capacity note for planners: estimate peak demand on POST /v1/batches and the cost ceiling for a failed retry storm. Write the abort conditions — unbounded spend, cross-tenant leakage, or inability to roll back — before you enjoy the first green test. Prefer synthetic fixtures shaped like production over anonymized production dumps you cannot share in class. When you are tempted to widen scope, re-read the oracle (fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40) and cut features that do not serve it. The teaching outcome is judgment under constraints: QA lead who needs cost-capped offline eval by 07:00 UTC gets a trustworthy control, not a kitchen-sink framework. Keep the language of release decisions: promote, hold, or roll back — never “see if it gets better.”
Read
Field notes for `batch-api-lab` / `lab-goal`
Decide what will live in version control on day one: fixtures, contract markdown, and a failing test name. Write the cost ceiling as a hard number with currency and period. If the lab involves clusters, name the non-prod context you will use and forbid prod kubecontexts in scripts. Capture the baseline metric once before changing code so later gains are comparative. Refuse tools that hide the request path behind magic macros until the oracle is green on fakes. Your README section for this page should be five lines or fewer and still falsifiable. In this chapter the product is overnight batch job that grades 50k support transcripts via provider Batch API, the human stakeholder is QA lead who needs cost-capped offline eval by 07:00 UTC, and the incident id you design against is BATCH-DUP-8841. Re-state the oracle in your notes — fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40 — and keep the invariant visible: each input line has a stable custom_id; failed lines never poison the whole file. Track batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8 as the scoreboard. Surface under change control: POST /v1/batches.
Go deeper
Before you start
Why this matters
Write the single done-definition a reviewer would accept for Batch API lab (BATCH-DUP-8841). Include the numeric gate hidden in this oracle: fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40. Then name the fake success you refuse: a demo that ignores duplicate custom_id causes silent overwrite of the better grade. Keep the sentence beside your editor; every later page should make this sentence easier to prove.
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.