06. API Key Authentication
Chapter 6 of 18 · 20 min
Local verification checkpoint
Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.
EXERCISE
Implement authentication middleware that validates the X-API-Key header and returns 401 for missing keys and 403 for invalid keys. Write a test that verifies the endpoint returns 401 without a header and succeeds with a valid header.