Skip to main content
BUILD PROOF LABAll projects

API Camp · LLM companion tutorial

API + LLM Tutorial

A guided build brief for placing an LLM behind a small typed API while keeping the default tests deterministic, offline, and free of credentials.

01

Deterministic core

Start with a fake model adapter so request validation, response schemas, timeouts, failures, and redaction can be tested without network calls or usage charges.

02

Untrusted output

Treat model responses as untrusted data: validate structure, constrain size, escape rendered content, and keep generated actions behind explicit approval.

03

Optional live adapter

Add a provider only after the local contract passes. Load credentials from runtime secrets, set cost and timeout limits, and never put keys in source, URLs, logs, or browser storage.

Start here

A practical workflow

  1. Define typed request and response models
  2. Create a model-adapter protocol
  3. Implement a deterministic fake adapter
  4. Test validation, timeout, retry, and redaction with pytest
  5. Exercise the browser-to-API path with Playwright
  6. Optionally connect one live provider behind runtime configuration

Tutorial contents

What is included

  • Runnable local Python API
  • Deterministic fake-model adapter
  • Optional server-side HTTP adapter
  • 19 pytest and Playwright checks
  • Security and privacy boundaries
  • Portfolio exercises and CI workflow

Review the release

Continue with the guided tutorial.

Open in API Camp