Skip to Content
Advanced FeaturesWait & Verify

Wait & Verify

Use apxy mark and apxy wait to check that your code sent the request you expect. You don’t need to poll apxy logs list. Each attempt sees only its own traffic. The exit code tells a script or an AI agent whether the check passed.

Verify one attempt

  1. Set a mark before you run your code:

    apxy mark
  2. Run the code that sends the request, through the proxy.

  3. Wait for the request and check it:

    apxy wait --match "POST /checkout" \ --expect "status == 200" \ --expect "body.order.id exists"

apxy wait checks traffic captured since the mark. If no request matches yet, it waits until one is captured, for up to 30 seconds. Then it prints the matched request and one result per --expect:

✓ POST http://localhost:3000/checkout → 200 (id 28d8229dd3c23ae2, 2026-11-21T09:12:09.104+07:00) ✓ status == 200 (actual: "200") ✓ body.order.id exists (actual: "42") Next: apxy logs show --id 28d8229dd3c23ae2

To check again after a fix, run apxy mark again. The new mark replaces the old one, so traffic from the earlier attempt no longer matches.

You can start apxy wait before or after your code runs. The command first checks traffic captured since the mark, so a request that arrived early still counts.

Read the result from the exit code

Exit codeMeaning
0A request matched, and every --expect passed.
7A request matched, but at least one --expect failed.
8No request matched before the timeout.
2The command is invalid. For example, an expression contains a typo.

The output is printed for codes 0, 7, and 8. For code 7, the output shows the actual value of each failed expectation:

✗ POST http://localhost:3000/checkout → 500 (id 9b1f03c2a7e4d118, 2026-11-21T09:14:31.552+07:00) ✗ status == 200 (actual: "500") ✗ body.order.id exists (actual: absent) Next: apxy logs show --id 9b1f03c2a7e4d118

AI agents get the same result as JSON. Add --output agent to force JSON output. The result is in data.matched and data.passed. With --expect, data.expectations[] holds one item per check, with expr, pass, and actual.

Checks run on the raw record, but the record and actual values that apxy wait prints are masked. See AI Data Redaction.

Choose which traffic counts

--since sets the earliest capture time that apxy wait considers:

ValueTraffic that counts
(not set)Traffic since the mark named default. With no default mark, only traffic captured after apxy wait starts.
A mark name, such as attempt-2Traffic since apxy mark attempt-2.
An RFC3339 time, such as 2026-11-21T09:00:00ZTraffic since that time.
A duration, such as 30s or 5mTraffic from that long ago until now.
allAll captured traffic. This value is slow on a large history.

Use named marks to keep several attempts apart:

apxy mark attempt-2 # run your code apxy wait --match "POST /checkout" --since attempt-2 --expect "status == 201"

The name all is reserved. apxy mark all fails with exit code 2.

Marks are stored in the shared database, ~/.apxy/data/apxy.db, one set per workspace. In a git worktree, apxy mark sets the mark of that worktree, and --since names the marks of that worktree. Agents in parallel worktrees can each set default without moving each other’s mark.

Check traffic from parallel agents

In a git worktree, apxy wait considers the requests of that workspace and untagged requests. A request from another worktree never matches. When an untagged request matches while other workspaces are active, the output carries a warning, because the request can come from another agent. --from-workspace <id or name> checks the requests of another workspace, and --all-workspaces checks every workspace. See Workspaces.

Know when a mock answered

When a mock rule answered the matched request, the JSON result has data.mocked_by with the id, name, and source of the rule, and data.warning starts with passed on a mocked response. The pass proves that your code handled the mock, not that the real API works. To reach the real API, remove the mock with apxy mock remove --id <id>, adding --global for a global rule, and check again.

Check traffic without waiting

To check traffic that is already captured, set --timeout 0. The command checks one time and does not block:

apxy wait --match "GET /api/profile" --since 5m --timeout 0 --expect "status == 200"

If more than one request matches, apxy wait uses the earliest one at or after --since.

Write match and expect expressions

--match selects the request. --expect checks it. Both use the same expression language.

--match also accepts the short form "METHOD /path". It matches the method and the exact path, without the query string. "POST /checkout" is the same as method == POST && path == /checkout.

FieldValue
method, host, path, urlThe request line.
statusThe response status code.
header:<Name>A request header. If the request does not have it, the response header.
body.<path>A field in the JSON response body, such as body.order.id.
req.body.<path>A field in the JSON request body, such as req.body.items.0.sku.

Body paths use gjson syntax . For example, body.items.# is the length of the items array.

OperatorExample
==, !=body.status == paid
contains, startswith, endswithheader:Content-Type contains json
matches (regular expression)url matches .*/v2/.*
>, >=, <, <=status < 400
existsbody.order.id exists

Rules for expressions:

  • ==, !=, contains, startswith, and endswith ignore case.
  • exists works with header: fields, body fields, and the event and data fields of a stream.
  • If a body field is missing, every operator fails for that field, including !=.
  • In --match, join conditions with && and ||, and use parentheses to group them. Each --expect holds one condition. Add one --expect flag for each check.
  • Put quotes around values that contain spaces: body.message == "card declined".

Check a stream

For a Server-Sent Events (SSE) response or a WebSocket, --expect also reads what the stream carried:

apxy wait --match "POST /v1/chat/completions" \ --expect 'sse.last.data == "[DONE]"' \ --expect 'sse.text contains "Hello"' apxy wait --match "GET /ws" --expect 'ws.server.data.type == order_created'
FieldValue
sse.countThe number of events.
sse.event, sse.dataThe type or data of any event. An event without a type is message.
sse.data.<path>A JSON field in the data of any event.
sse.last.event, sse.last.data, sse.last.data.<path>The last event.
sse.textThe data of all events joined into one text. OpenAI, Anthropic, and Gemini deltas become the full answer.
ws.count, ws.client.count, ws.server.countThe number of data frames: in both directions, from the client, or from the server.
ws.client.data, ws.server.dataAny frame in that direction. Add .<path> for a JSON field.
ws.client.last.data, ws.server.last.dataThe last frame in that direction. Add .<path> for a JSON field.

Rules for streams:

  • A field over many events or frames passes when any of them satisfies the condition. != passes when none of them equals the value, so sse.event != error means that there was no error event.
  • While the stream is open, apxy wait checks again until every --expect passes, the stream ends, or the timeout passes. When the stream ends without a match, it exits with code 7 at once.
  • != can pass before the stream ends. To check the whole stream, add a condition for its end, such as sse.last.data == "[DONE]".
  • APXY must decrypt an HTTPS stream to read it. See SSL Proxying.
  • A WebSocket message split across continuation frames is not joined.

The output ends with a summary, such as stream: sse, 7 events, ended. JSON output has it in data.stream.

Reference

For all flags, see CLI Reference → Traffic.

Last updated on