Week 4 Master Guide

Week 4: HTTP/REST APIs, LLM Tokenizers, Prompt Engineering & Month 1 Capstone

Week 4 Daily Breakdown (5 Days)

Day 1

Week 4 — Day 1: How the Internet, HTTP & REST APIs Work (From Zero to LLM Wire Protocol)

1 code file(s) • 2 Q&A
Day 2

Week 4 — Day 2: How LLMs Actually Process Text — BPE Tokenization, Softmax Temperature & `top_p` Math

1 code file(s) • 2 Q&A
Day 3

Week 4 — Day 3: Prompt Engineering Mastery, Chain-of-Thought & Defending Against Prompt Injection

1 code file(s) • 2 Q&A
Day 4

Week 4 — Day 4: Production API Resilience — Exponential Backoff, Full Jitter & Circuit Breakers

1 code file(s) • 2 Q&A
Day 5

Week 4 — Days 5 to 7: Month 1 Capstone Project — SRE Runbook Copilot CLI

1 code file(s) • 0 Q&A

Week 4: HTTP/REST APIs, LLM Tokenizers, Prompt Engineering & Month 1 Capstone (week4.md)

Mentor's Note (10+ YOE Staff AI Engineer POV): Welcome to Week 4—the final week of Month 1 where everything you mastered in Weeks 1–3 (Terminal, Git, Core Python, Generators, Decorators, Pydantic v2, asyncio, and SQL/Databases) connects directly to Large Language Models and culminates in Capstone Project 1: SRE Runbook Copilot CLI!

What separates a beginner calling client.chat.completions.create() from a Senior AI Engineer?

  1. Understanding HTTP & Wire Protocols (Day 1): Knowing exact HTTP status codes (400 vs 401 vs 422 vs 429 vs 503), Authorization: Bearer headers, and Retry-After headers.
  2. Understanding BPE Tokenization & Sampling Math (Day 2): How Byte-Pair Encoding (BPE) merges subword tokens, how the Softmax Temperature equation (Pi=exp⁡(zi/T)∑jexp⁡(zj/T)P_i = \frac{\exp(z_i / T)}{\sum_j \exp(z_j / T)}) controls determinism, and how top_p (nucleus sampling) and logprobs measure model confidence.
  3. Advanced Prompt Engineering & Grounding (Day 3): Zero-shot vs Few-shot vs Chain-of-Thought (CoT), XML/Markdown delimiters to defeat Indirect Prompt Injection, and forcing response_format={"type": "json_object"}.
  4. Production API Resilience (Day 4): Exponential Backoff with Full Jitter (tsleep=uniform(0,min⁡(Tmax⁡,b⋅2attempt))t_{\text{sleep}} = \text{uniform}(0, \min(T_{\max}, b \cdot 2^{\text{attempt}}))) and Circuit Breakers.
  5. Month 1 Capstone Project (Days 5–7): Building, testing, and defending the complete SRE Runbook Copilot CLI (capstones/month01_sre_runbook_copilot_cli/)!

Week 4 Architecture & Daily Folder Map

text
week04_apis_http_llms_and_capstone_1/ ├── week4.md # Master Week 4 Syllabus & Architecture ├── day01_http_rest_apis_headers_status_codes/ # Day 1: HTTP/REST Internals, Headers & Status Codes │ ├── README.md │ ├── src/http_protocol_inspector.py │ ├── tests/test_http_protocol_inspector.py │ └── interview_questions.md ├── day02_bpe_tokenization_sampling_temperature_math/ # Day 2: BPE Tokenizer From Scratch & Softmax Math │ ├── README.md │ ├── src/bpe_and_sampling_math.py │ ├── tests/test_bpe_and_sampling_math.py │ └── interview_questions.md ├── day03_prompt_engineering_cot_delimiters_json_mode/ # Day 3: Prompt Engineering, CoT & Injection Defense │ ├── README.md │ ├── src/prompt_architect.py │ ├── tests/test_prompt_architect.py │ └── interview_questions.md ├── day04_api_resilience_backoff_jitter_circuit_breaker/ # Day 4: Exponential Backoff + Jitter & Circuit Breakers │ ├── README.md │ ├── src/resilience_engine.py │ ├── tests/test_resilience_engine.py │ └── interview_questions.md └── day05_to_07_month1_capstone_sre_runbook_copilot/ # Days 5-7: Guide & Bridge to Capstone 1 └── README.md capstones/month01_sre_runbook_copilot_cli/ # MONTH 1 CAPSTONE PROJECT REPOSITORY ├── README.md # Complete Capstone Documentation & Architecture ├── main.py # Parallel CLI Entry Point + SQL Audit + Cost Report ├── runbooks/ │ ├── payments_service.md │ └── database_failover.md ├── src/ │ ├── __init__.py │ ├── schemas.py # Pydantic v2 `RunbookResponse` & `CostRecord` │ ├── cost_calculator.py # Exact Token & USD Cost Auditor │ ├── copilot.py # Async OpenAI/Gemini/Deterministic Engine │ └── audit_db.py # SQLite Persistent Cost & Telemetry Ledger └── tests/ └── test_capstone_month01.py # Comprehensive Capstone Verification Test Suite

Daily Schedule & Core Deliverables

DayTopicDeep Theory & Math CoveredProduction Deliverable
Day 1HTTP, REST APIs, Headers & Status CodesTCP/TLS handshake, Request/Response anatomy, GET vs POST idempotency, Status Codes (200, 400, 401, 403, 422, 429, 500, 502, 503), Retry-Afterhttp_protocol_inspector.py — Builds OpenAI/Gemini-compatible HTTP payloads and classifies retryable vs fatal HTTP status codes
Day 2BPE Tokenization, Softmax Temperature & top_p MathByte-Pair Encoding (BPE) merge algorithm; Softmax with Temperature: Pi=ezi/T∑jezj/TP_i = \frac{e^{z_i/T}}{\sum_j e^{z_j/T}}; Nucleus Sampling (top_p); converting logprobs to linear probability (p=elogprobp = e^{\text{logprob}})bpe_and_sampling_math.py — Trains a miniature BPE tokenizer from scratch + implements Softmax Temperature & top_p nucleus filtering
Day 3Prompt Engineering, CoT & Injection DelimitersSystem/User/Assistant message hierarchy, Few-Shot exemplars, Chain-of-Thought (CoT), XML tag sandboxing (<runbook_context>), and negative constraintsprompt_architect.py — Prompt template compiler with XML context sandboxing and prompt injection detector
Day 4API Resilience: Exponential Backoff, Jitter & Circuit BreakersWhy naive retries cause "Thundering Herd" outages; Full Jitter math: t=U(0,min⁡(Tmax⁡,b⋅2k))t = U(0, \min(T_{\max}, b \cdot 2^k)); 3-state Circuit Breaker (CLOSED →\rightarrow OPEN →\rightarrow HALF_OPEN)resilience_engine.py — Production Exponential Backoff + Full Jitter calculator & stateful Circuit Breaker
Days 5–7Month 1 Capstone: SRE Runbook Copilot CLICombining Pydantic v2 + AsyncOpenAI / Universal .env + Cost Auditor + SQLite Audit Ledger + Parallel ExecutionFull Month 1 Capstone in capstones/month01_sre_runbook_copilot_cli/ + Capstone Defense Interview!
Week 4: Week 4: HTTP/REST APIs, LLM Tokenizers, Prompt Engineering & Month 1 Capstone | 24-Week AI Engineer Academy · DataArena