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
-
Set a mark before you run your code:
apxy mark -
Run the code that sends the request, through the proxy.
-
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 28d8229dd3c23ae2To 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 code | Meaning |
|---|---|
0 | A request matched, and every --expect passed. |
7 | A request matched, but at least one --expect failed. |
8 | No request matched before the timeout. |
2 | The 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 9b1f03c2a7e4d118AI 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:
| Value | Traffic 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-2 | Traffic since apxy mark attempt-2. |
An RFC3339 time, such as 2026-11-21T09:00:00Z | Traffic since that time. |
A duration, such as 30s or 5m | Traffic from that long ago until now. |
all | All 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.
| Field | Value |
|---|---|
method, host, path, url | The request line. |
status | The 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.
| Operator | Example |
|---|---|
==, != | body.status == paid |
contains, startswith, endswith | header:Content-Type contains json |
matches (regular expression) | url matches .*/v2/.* |
>, >=, <, <= | status < 400 |
exists | body.order.id exists |
Rules for expressions:
==,!=,contains,startswith, andendswithignore case.existsworks withheader: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--expectholds one condition. Add one--expectflag 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'| Field | Value |
|---|---|
sse.count | The number of events. |
sse.event, sse.data | The 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.text | The data of all events joined into one text. OpenAI, Anthropic, and Gemini deltas become the full answer. |
ws.count, ws.client.count, ws.server.count | The number of data frames: in both directions, from the client, or from the server. |
ws.client.data, ws.server.data | Any frame in that direction. Add .<path> for a JSON field. |
ws.client.last.data, ws.server.last.data | The 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, sosse.event != errormeans that there was no error event. - While the stream is open,
apxy waitchecks again until every--expectpasses, the stream ends, or the timeout passes. When the stream ends without a match, it exits with code7at once. !=can pass before the stream ends. To check the whole stream, add a condition for its end, such assse.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.