Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Retake records real LLM API exchanges into “take” files and replays them deterministically in tests, for any language or SDK.

Tests of LLM agents that call a live API are flaky (the model answers differently from run to run), slow, cost money on every run, and need an API key wherever they run, including CI. Retake runs your test command once against the real API and records every request and response. After that, the same command replays from the recording: no network, no API key, and the same responses every time.

Secrets matching a configured pattern are redacted before any byte is written to disk. Content Retake cannot scan is never written unless you opt in with --allow-unscanned. See Redaction.

Retake is at 0.1. It supports the Anthropic Messages API on macOS and Linux. The take format may still change before 1.0; when it does, retake upgrade rewrites existing takes in the new format. See Status for what is supported, and Installation.

Status

Supported today:

  • retake record and retake replay wrapping any command, with one take per run (_main.take) in --takes-dir (default tests/takes).
  • With the pytest plugin, one take per test case, _session.take for requests outside tests, failed tests keeping their previous take, and replay failing tests that leave exchanges unused.
  • The Anthropic Messages API, including streamed (server-sent event) responses, with replay pacing selected by --pacing.
  • Content matching with mismatch descriptions, and the header allow-list.
  • Normalization rules: selectors, built-ins, user rules in retake.toml, the guard, and match counts in the summary.
  • Redaction: built-in and user patterns, consistent placeholders, the stream window, the final scan, and withholding unscannable content.
  • Binary content: hash-only parts, blob files for opted-in content, relaxed media rules, decoded text inside base64, decompressed responses and multipart uploads.
  • Refusing or dropping account and transient errors while recording.
  • Detecting test takes that depend on IDs from _session.take, finalizing such runs at the end, retake finalize after a crash, retake clean and retake init.
  • resource records for uploaded files and message batches, the leftover list in the recording summary, _resource.take and retake reap.
  • retake check and retake ls (with --json), staleness by Retake version and API version with --fail-on-stale, format versioning with retake upgrade, and JSON Schemas for takes, retake.toml and the --json output.

Not done yet for test-runner plugins: freezing the clock at the recording time during replay, other server-side resource kinds, retake prune / retake mv for renamed tests, plugins for other test runners, and outcomes other than passed, failed and skipped.

Design

The design decisions are recorded as Architecture Decision Records in docs/adr/, covering the take storage model, take granularity and naming, the write lifecycle, stream representation, redaction, the plugin–proxy protocol, replay matching, normalization rules, binary content, metadata and staleness, format versioning and JSON Schemas.

Prior art

The closest existing tool is rig-cassette, part of the Rig project. It is a Rust library for recording and replaying LLM exchanges in Rig’s own test suite. Retake differs in that it wraps any test command and works with any language’s SDK through a local proxy, and it matches requests by content and reports mismatches as readable diffs.