API testing with AI agents: write, run, and read failures
A practical loop for AI agent API testing: let a coding agent inspect your API, write test flows with explicit assertions, run them from the terminal, and report failures.
Coding agents write endpoints fast. They also tell you a change is done when it compiles, and that is not the same as working. The useful question is not “did the agent finish?” but “can it prove the API still behaves?”
This guide shows API testing with an AI agent as a loop the agent can follow on its own: inspect what exists, write a test flow, run it, read the failures, and report. Every step is a CLI command, so any agent with a terminal can run it, and you can review the result on a visual canvas.
This article is about an agent testing your API. It is not about evaluating an AI model or testing an agent’s own tools.
Why API tests matter more with agents
An agent changes code across many files in minutes. Unit tests it writes alongside the code often test the code it just wrote, with the same assumptions. An API test checks behavior from the outside: send a real request, compare the response with an explicit expectation, and record the difference.
That gives you three things:
- Evidence instead of claims. Every assertion records the expected value, the actual value, and whether it passed, on passing runs too.
- A shared test. The flow the agent wrote opens on the visual canvas, where a person can read and edit it.
- A check that stays. The same flow runs again in CI and on a schedule, long after the agent’s session ends.
The loop
| Step | Agent runs | Result |
|---|---|---|
| 1. Inspect | flow list --all, flow view <flow-id> -o json | Knows what is already tested |
| 2. Write | flow node add, flow node assertion add | A flow with explicit checks |
| 3. Validate | flow validate <flow-id> | The graph is sound before anything runs |
| 4. Run | flow run <flow-id> -e staging -o json | One JSON object and an exit code |
| 5. Read | jq over the failed nodes | Expected against actual, per assertion |
| 6. Decide | Fix the code or fix the test | A reason, not a relaxed assertion |
| 7. Report | Exit code, node results, flow_url | A link you can open and review |
Set up the CLI for the agent
Install the CLI and sign in once. The sign-in opens a browser, so you finish it yourself:
curl -fsSL https://raw.githubusercontent.com/nanostack-dev/echopoint-cli/main/install.sh | shechopoint auth loginThe installer needs no sudo and verifies the release checksum. Flows live in a workspace, and the CLI never picks one for you. Give the agent the organization and workspace to use:
export ECHOPOINT_ORGANIZATION_ID=<organization-id>export ECHOPOINT_WORKSPACE_ID=<workspace-id>In CI, where there is no browser, use an organization API key in ECHOPOINT_API_KEY instead.
1. Inspect before writing
An agent that writes a new test for every request ends up with ten copies of the same check. Have it read what exists first:
echopoint flow list --allechopoint flow view <flow-id> -o jsonechopoint org env environments listechopoint org env view -e stagingorg env view shows the variable names of an environment, such as BASE_URL. Secret values stay hidden. When a flow already covers the path, the agent edits that flow instead of creating a new one.
2. Write a flow with explicit assertions
Each step of a flow is a request with assertions and outputs. This one creates a widget, reads it back, and deletes it:
FLOW_ID=$(echopoint flow create --name "Widgets API" -o json | jq -r .id)
echopoint flow node add "$FLOW_ID" --id create --type request --name "Create widget" \ --method POST --url "{{BASE_URL}}/widgets" \ --headers '{"Content-Type":"application/json"}' --body '{"name":"agent-{{$uuid}}"}'echopoint flow node assertion add "$FLOW_ID" create \ --extractor status_code --operator equals --value "201"echopoint flow node output add "$FLOW_ID" create \ --name widgetId --extractor json_path --path '$.id'
echopoint flow node add "$FLOW_ID" --id read --after create --type request --name "Read widget" \ --method GET --url "{{BASE_URL}}/widgets/{{create.widgetId}}"echopoint flow node assertion add "$FLOW_ID" read \ --extractor json_path --path '$.id' --operator equals --value "{{create.widgetId}}"
echopoint flow node add "$FLOW_ID" --id cleanup --after read --run-when always --type request \ --name "Delete widget" --method DELETE --url "{{BASE_URL}}/widgets/{{create.widgetId}}"{{create.widgetId}} reads an output that an earlier step declared. {{$uuid}} generates fresh test data per run. --run-when always deletes the widget even when the read failed, as long as the widget ID exists.
Teams that keep tests next to the code can write the same flow as a *.flow.yaml file. echopoint flow compile -f <file> --check lints it, and echopoint flow create -f <file> creates it.
3. Validate, then run
echopoint flow validate "$FLOW_ID"echopoint flow run "$FLOW_ID" -e staging -o jsonflow validate catches an edge to a missing step, a reference with no path from the step that produces it, or a cycle, without sending a request. flow run executes the flow from the machine the agent runs on and waits for the result, so it can reach an API on localhost or a private network.
The exit code tells the agent what happened: 0 passed, 1 a flow failed, 2 cancelled, 3 an API or runner error, 4 a timeout.
4. Read the failure
With -o json, the CLI prints one object with status, success, exit_code, error_message, flow_url, and nodes. A failed node lists its assertions with the expected and actual values:
echopoint flow run "$FLOW_ID" -e staging -o json \ | jq '.nodes[] | select(.status == "failed") | {node_id, error_message, assertions}'This is the step that makes agent testing useful. The agent gets a precise difference, such as “expected 201, actual 500” on the create step, instead of “the test failed”.
5. Decide which side is wrong
A failed assertion means the API and the test disagree. Only one of them matches the intended behavior:
- The API returned the wrong thing. Keep the assertion. The agent fixes the code, or reports the failure to you, and runs the flow again.
- The test asserts the wrong thing, because the contract changed on purpose. The agent updates the assertion, and you review that change like any other code change.
Write this rule into your agent’s instructions: never relax an assertion only to make a run pass. An agent that edits the test until it is green has proved nothing.
Guardrails for agent-run tests
- Use a test environment. A flow sends real requests and can create or delete records.
- Keep secrets out of prompts. Store credentials as secrets:
echopoint org env set -e staging --secret --var "API_TOKEN=$API_TOKEN". A read never returns a secret, and results show***. - Ask, do not guess. An agent that guesses a base URL sends test requests to someone else’s system. Have it ask for any URL, credential, or workspace it does not have.
- Report with a link. End each run with the exit code, each step’s result, and the
flow_url, so you can open the flow in the app and check it.
Give your agent the instructions
The public CLI repository includes an Echopoint skill file: setup, a first flow with assertions, running it, CI, and monitors, written as copy-paste steps for a coding agent. Add it to your agent’s instructions, or copy the rules you want into your project’s agent guide.
After the agent: review, CI and schedules
The agent’s flow is not a throwaway script. Open it on the canvas to read what it checks. The Echopoint AI copilot in the canvas can explain a flow or propose a change, and every change it applies has a restorable snapshot.
Then keep the check running:
- Tag the flow and run the suite on every pull request with the GitHub Action.
- Run a tagged suite after each deploy and on a schedule, as described in API smoke tests.
Echopoint is free while in beta. Install the CLI and follow the getting-started guide to give your agent its first flow.
FAQ
Can an AI agent write API tests?
Yes. A coding agent that can run shell commands can read your API's routes or OpenAPI file, create a test flow with the Echopoint CLI, add assertions on status codes, JSON fields and headers, validate the flow, and run it. You still review what it wrote: the agent decides what to test, and the assertions are only as good as the behavior they describe.
Which AI agents work with Echopoint?
Any agent that can run commands in a terminal can drive the Echopoint CLI, because the agent uses the same commands you do. Echopoint does not ship a native integration for a specific assistant. The public CLI repository includes a skill file with setup steps, a first flow, running it, and CI, which you can give to your agent as instructions.
Does Echopoint fix my code when a test fails?
No. Echopoint runs the tests and records the evidence: each assertion's expected value, actual value, and result. Your agent and you decide whether the API or the test is wrong. When the API returns the wrong thing, keep the assertion and fix the code; when the test asserts the wrong thing, fix the test.
Is it safe to let an agent run API tests?
Running a flow sends real requests, which can create or delete records. Point the agent at a test environment, keep credentials in Echopoint secrets rather than in prompts or files, and review your agent's command approvals. A flow that creates data should delete it in a cleanup step that runs even after a failure.
Echopoint is free while in beta.
Sign up with GitHub, Google, or email. No credit card.