Week 1 · Day 4/30

API Design for AI

REST vs streaming, token management, rate limiting, error handling

📅 2026-03-07 ⏱️ 5-6 hodín 📊 Foundations & RAG
API Design for AI — Vector embedding space
Celkový progres 13%

🎯 Cieľ dňa

Navrhnúť resilientnú AI API vrstvu s retry logikou, circuit breakermi a model fallbackmi.

practice core

📚 Study Resources

OpenAI API — Streaming Responses

Officiálna dokumentácia SSE-based streaming. Štartovací bod.

docs
🛡️

Portkey — Retries, Fallbacks & Circuit Breakers

Praktický guide na budovanie resilientného LLM API layeru.

article
💰

Skywork — AI API Cost & Throughput Management

Token math, budgeting, throughput management. Reálne kalkulácie.

article
🔧

Sevalla — Real-time Streaming with FastAPI

Hands-on tutorial: streaming API endpoint s FastAPI a SSE. Working code.

hands-on
📋

OpenAI API — Rate Limits

TPM, RPM, Retry-After headers. Oficiálna rate limiting dokumentácia.

docs

💡 Key Concepts

REST vs Streaming — Kedy sync responses vs SSE; time-to-first-token optimalizácia
Token Management — Počítanie tokenov pred odoslaním (tiktoken), max_tokens, context windows, kalkulácia nákladov
Rate Limiting — Token bucket, leaky bucket, sliding window; client-side rate limiter implementácia
Error Handling — 4xx (neretryuj) vs 5xx/429 (retryuj s backoffom); exponential backoff s jitter
Circuit Breakers — Monitoring failure patterns, cut traffic pred kaskádovými zlyhaniami
Model Fallbacks — Fallback z drahého modelu na lacnejší pri výpadku alebo rate limitingu

🔧 Praktické cvičenie

Buildni resilientný LLM API wrapper.

  1. Vytvor Python class s API key management z env vars
  2. Pridaj token counting s tiktoken pred odoslaním
  3. Implementuj exponential backoff s jitter pre 429/5xx
  4. Pridaj fallback chain: Opus → Sonnet → Haiku
  5. Podpor sync aj streaming mode
  6. Loguj všetky requesty s latency a token counts