Back to the curriculum

L1-M03 · Level 1 · ~29 h

LLM API Testing

What you build: API test suite

lessons
5
lesson hours (estimate)
≈ 14.5 h
lessons with a public video
5/5
0/5 lessons marked done · Progress is saved in this browser only. No account, nothing is sent to a server.
In review. The curriculum, module overviews and Levels 1–3 lessons are drafts written with AI assistance and reviewed by AI. Human review is still pending. English translation: AI-assisted, not human-reviewed.

Levels 1–3 lessons, exercises and quizzes are published as drafts, in Vietnamese with an AI-assisted English translation. They may change after human review.

Module path

  1. Lesson 1 · L1-M03-L01≈ 3 hVideo

    Calling the real API safely: keys, environment variables, spending limits

    What you build: Startup key check, budget guard, SDK against a local fake API

    Needs: L1-M01-L04, L1-M02-L05

    Key terms (8)
    • API keyKhóa bí mật để xác thực khi gọi API
    • Environment variableBiến môi trường
    • SDK (Software Development Kit)Bộ thư viện chính thức để gọi API
    • Spend limit / spend capGiới hạn chi tiêu tự đặt / trần chi tiêu của tier
    • Budget guardCơ chế chặn request vượt ngân sách
    • Fake APIServer giả trả lời theo cấu trúc của API thật
    • Live testTest gọi API thật
    • Request IDMã định danh của một request, dùng khi báo lỗi
  2. Lesson 2 · L1-M03-L02≈ 2.5 hVideo

    Testing request parameters: max_tokens, stop sequences, system and removed parameters

    What you build: Request contract tests; removed temperature/top_p/top_k

    Needs: L1-M03-L01

    Key terms (5)
    • Contract testTest khẳng định "hợp đồng" dữ liệu giữa hai bên
    • Request bodyNội dung JSON của request
    • Stop sequenceChuỗi khiến model dừng sinh output
    • Removed parameterTham số đã bị API loại bỏ
    • SDK upgradeNâng cấp phiên bản thư viện SDK
  3. Lesson 3 · L1-M03-L03≈ 3.5 hVideo

    Errors, rate limits, timeouts and retries

    What you build: Error-path suite with request counting

    Needs: L1-M03-L02

    Key terms (7)
    • RetryThử lại
    • Exponential backoffChờ lâu dần giữa các lần thử lại
    • Rate limitGiới hạn số request hoặc token trong một khoảng thời gian
    • Spend capTrần chi tiêu
    • TimeoutHết thời gian chờ
    • Typed exceptionException có class riêng cho từng loại lỗi
    • Transient errorLỗi tạm thời
  4. Lesson 4 · L1-M03-L04≈ 2.5 hVideo

    Streaming and latency (TTFT)

    What you build: Stream tests, TTFT measurement, mid-stream error

    Needs: L1-M03-L03

    Key terms (7)
    • StreamingGửi câu trả lời từng phần
    • Server-sent events (SSE)Sự kiện do server gửi qua một kết nối HTTP
    • Chunk / deltaMột mảnh output trong stream
    • Time to first token (TTFT)Thời gian tới token đầu tiên
    • Latency budgetNgưỡng độ trễ cho phép
    • Percentile (p95)Giá trị mà 95% số lần đo nằm dưới
    • MedianTrung vị
  5. Lesson 5 · L1-M03-L05≈ 3 hVideo

    Mocking, recording and replaying provider responses

    What you build: Redacting record/replay layer, fail closed

    Needs: L1-M03-L04

    Key terms (6)
    • Test doubleThành phần đứng thay thành phần thật khi test
    • Mock / fake / replayGiả lập client / server giả / phát lại response đã ghi
    • CassetteFile lưu các cặp request-response đã ghi
    • RedactionChe dữ liệu nhạy cảm
    • HashMã băm
    • Re-recordGhi lại cassette

A. Module overview

Field Value
Module ID L1-M03
Level 1 - AI QA Engineer
Description Testing the integration layer of an LLM feature, where product code calls the provider's API through the official SDK (anthropic 2.3.0). Content: key safety and cost; contract tests for requests; errors, retries, timeouts, rate limits, spend caps; streaming and latency; record and replay with redaction. All labs run with the real SDK pointed at a local fake API, so no key is needed and nothing costs money. Live tests are optional.
Why this module matters Many production incidents in LLM features start at the integration layer: unhandled errors, wrong retries, runaway costs, leaked keys. This is also the part that can be tested deterministically.
Target professional competencies Level 1: "LLM API testing"; foundation for "Python and Pytest foundations", "Non-deterministic behavior testing" and CI (L1-M07).
Estimated duration 5 lessons (165 + 150 + 210 + 150 + 180 minutes) ≈ 14 hours + module assignment ~14 hours + quiz 0.5 hours ≈ 29 hours for someone new to Python. Reviewer's estimate, not yet measured with real learners.
Prerequisites L1-M01, L1-M02. No API key needed.
Module output API test suite for a service that calls the Claude API (ShopEasy summary service assignment)
Cost 0 VND. The optional live test costs money, and the course team has not run it

B. Learning objectives

ID Objective
MO1 Configure keys and cost limits safely, and verify with tests that the key is not leaked.
MO2 Write contract tests for requests and for stop reason handling.
MO3 Verify how the integration handles errors, retries, timeouts, rate limits and spend caps.
MO4 Measure TTFT and verify stream handling, including mid-stream errors.
MO5 Build a safe replay layer and design a multi-layer CI strategy.

C. Lessons

ID Lesson Duration Prerequisites Concepts Hands-on output
L1-M03-L01 Calling the real API safely 165' L1-M01-L04, L1-M02-L05 key, environment variable, spend limit, budget guard, fake API, live test Startup test + budget guard
L1-M03-L02 Testing request parameters 150' L01 contract test, max_tokens, stop_sequences, removed parameters Contract tests for requests
L1-M03-L03 Errors, rate limits, timeouts and retries 210' L02 error codes, typed exception, SDK retries, retry-after, spend cap Error-path test suite
L1-M03-L04 Streaming and latency 150' L03 SSE, TTFT, errors after HTTP 200, percentile Stream tests + measurement plan
L1-M03-L05 Mock, record and replay 180' L04 test double, cassette, redaction, fail closed, multi-layer CI Replay layer

D. Hands-on assignment (module assignment)

API test suite for the ShopEasy summary service (fictional). The learner writes a test suite that verifies the contract of a service calling the Claude API, runs it against the fake API, then reports the defects found. Details in exercises.md.

E. Module assessment

Component Weight Content
Knowledge quiz 20% quiz.md: 12 questions, 20 points
Practical assignment 40% Rubric: Test design + Implementation
Applied QA analysis 20% Rubric: Contract analysis + Defect analysis
Review/reflection 20% Rubric: Reporting + Reflection

Formula: module score = 0.2 × quiz% + 0.8 × assignment rubric score (out of 100). Pass conditions: quiz ≥ 70% and every mandatory acceptance criterion and total ≥ 70%.

F. References

See references.md.

Objective ↔ assessment matrix

Objective Lesson Module quiz Assignment
MO1 L01 Q1, Q6, Q9 Fake key fixture; no key leak
MO2 L02 Q2, Q7 Clauses 2, 4
MO3 L03 Q3, Q8, Q10 Clauses 3, 5, 6
MO4 L04 Q4, Q11 (Optional)
MO5 L05 Q5, Q12 Reflection on CI strategy