Control API

aimock exposes a small HTTP control surface under the /__aimock/* prefix for inspecting recorded traffic and resetting server state between test runs — no restart required.

All control routes are exact-match and live alongside your mocked LLM endpoints on the same port. They are intended for use from test harnesses (directly via fetch / curl, or through the aimock-pytest client).

Route Overview

Method Path Description
GET /__aimock/health Liveness probe
GET /__aimock/journal Read-only snapshot of recorded requests
GET /__aimock/fixtures How many fixtures are currently loaded
POST /__aimock/fixtures Add fixtures at runtime
DELETE /__aimock/fixtures Clear all fixtures
POST /__aimock/reset Full reset: fixtures, journal entries, fixture match-counts (sequence position), video + fal.ai job state, and the Gemini interaction / event-id counters
POST /__aimock/reset/journal Clear only the request journal entries
POST /__aimock/reset/fixtures Deprecated. Alias for /reset
POST /__aimock/error Queue a one-shot error injection

Reset Routes

aimock keeps several kinds of in-memory state between requests: the loaded fixtures, the per-provider generation state (video and fal.ai jobs, plus the Gemini interaction and event-id counters), the fixture match-counts (sequence position), and the request journal (recorded requests). Two routes clear it: POST /__aimock/reset clears all of it, and POST /__aimock/reset/journal clears only the recorded requests and leaves everything else intact. A third, POST /__aimock/reset/fixtures, is a deprecated alias for the full reset.

Pick the narrower routePOST /__aimock/reset wipes the loaded fixtures along with everything else, and what happens to the next request then depends on the mode. In replay mode it fails with 404, and in strict mode with 503 — both carry code: "no_fixture_match". But in record mode, with a provider key configured, an unmatched request is proxied to the real provider — so a full reset mid-recording means live upstream calls and real spend, not an error. If all you want is a clean read between test runs, use POST /__aimock/reset/journal — it leaves your fixtures intact.

POST /__aimock/reset

Full reset. Returns the server to a pristine, fixture-free state. It clears the in-memory fixtures, the journal entries and the per-test fixture match-counts (so sequenced fixtures rewind to their first response), the video and fal.ai job and queue state, and the Gemini interaction and event-id counters.

Full reset shell
$ curl -X POST http://localhost:4010/__aimock/reset
Response json
{ "reset": true }

POST /__aimock/reset/journal

Journal only. Clears only the request journal entries. Your loaded fixtures, generation state, and fixture match-counts (sequence position) are preserved, so the next request still matches. This is the recommended call for a clean read between test runs.

Journal-only reset shell
$ curl -X POST http://localhost:4010/__aimock/reset/journal
Response json
{ "reset": true }

POST /__aimock/reset/fixtures (Deprecated)

Deprecated alias for /__aimock/reset. The name promises a fixtures-only reset, but it performs the same full reset — journal, match-counts, job state and counters all go with it. It additionally sets a Deprecation: true response header and adds deprecated / deprecation fields to the body. Use /reset for a full reset, or /reset/journal for a journal-only one; to clear fixtures and nothing else, use DELETE /__aimock/fixtures.

Deprecated reset shell
$ curl -i -X POST http://localhost:4010/__aimock/reset/fixtures
Response json
// Deprecation: true   (response header)
{
  "reset": true,
  "deprecated": true,
  "deprecation": "POST /__aimock/reset/fixtures is deprecated; use POST /__aimock/reset (full reset) or POST /__aimock/reset/journal (journal only)"
}

Inspection

GET /__aimock/health

A simple liveness probe. Returns 200 once the server is accepting requests.

Health check shell
$ curl http://localhost:4010/__aimock/health
Response json
{ "status": "ok" }

GET /__aimock/journal

Returns a read-only snapshot of the recorded request entries as a JSON array. The journal records each incoming request so tests can assert on what was sent. Clearing it does not affect fixtures — see /__aimock/reset/journal above.

Read the journal shell
$ curl http://localhost:4010/__aimock/journal
Response json
[
  /* recorded request entries */
]

Fixtures

GET /__aimock/fixtures

Read-only: how many fixtures are currently registered. Useful for asserting a CI job or test harness actually loaded its tape before it starts making requests, without having to send a probe request and infer the answer from the reply. Returns the count only — fixtures hold predicate functions, so nothing about their contents is serialized.

Count fixtures shell
$ curl http://localhost:4010/__aimock/fixtures
Response json
{ "count": 2 }

POST /__aimock/fixtures

Add fixtures at runtime without restarting the server. The body is an object with a "fixtures" array of fixtures to register. Returns the number of fixtures added.

Add fixtures shell
$ curl -X POST http://localhost:4010/__aimock/fixtures \
  -H "Content-Type: application/json" \
  -d '{ "fixtures": [{ "match": { ... }, "response": { ... } }] }'
Response json
{ "added": 1 }

DELETE /__aimock/fixtures

Clears all registered fixtures. Generation state and the journal are left untouched. To clear everything at once, use /__aimock/reset instead.

Clear fixtures shell
$ curl -X DELETE http://localhost:4010/__aimock/fixtures
Response json
{ "cleared": true }

Error Injection

POST /__aimock/error

Queues a one-shot error injection. The next matching request returns the queued error instead of a normal response, after which the injection is consumed. See Error Injection for the full request shape and options.

Queue an error shell
$ curl -X POST http://localhost:4010/__aimock/error \
  -H "Content-Type: application/json" \
  -d '{ "status": 429, "body": { "message": "rate limited", "type": "rate_limit_error" } }'
Response json
{ "queued": true }