Agent Credential Tests: What Must Fail Before You Ship
Your agent’s token expired a minute ago. Does your API answer 401, a 500, or worse, a 200?

IN 30 SECONDS
A failure test is a test that sends a request your credential setup must refuse, and checks the exact error. Expired, replayed, stolen, over-scoped and wrong-API requests all belong in the suite. Write them before the happy path.
KEY TAKEAWAYS · 3
- Write the failure tests first. Expired, replayed, stolen, over-scoped and wrong-API requests must all be refused with the right error.
- Before a refusal test, check that a normal call works. Otherwise a server that rejects everything passes.
- Short-lived, narrow tokens limit what a hijacked agent can reach, and for how long. They don’t stop prompt injection.
On this page
The failure tests I’d ship before the agent goes live
IN SHORT A credential design is a claim about what fails. I’d write the failure tests before the happy path.
WORDS TO KNOW
- Access token
- A pass an API accepts instead of a password. It grants limited rights, and in this episode it expires within minutes.
- Scope
- The list of actions a token allows, such as reading invoices but not creating payments.
- Replay
- Sending a captured request or proof again, hoping the server accepts it a second time.
I’d run them in CI, on every code change. They’d hit a real authorization server and a real API. The test controls the clock.
Each test names the exact error, not just “blocked”.
A 500 that happens to block the request is a bug waiting to become a 200.
IN PLAIN WORDS
These are HTTP status codes: 500 is a server error, 200 a success, 401 means missing or invalid credentials, 400 a bad request.
Each row below sends an Access token A pass an API accepts instead of a password. It grants limited rights, and in this episode it expires within minutes. See the glossary or asks for a Scope The list of actions a token allows, such as reading invoices but not creating payments. See the glossary that the setup must refuse. The error codes are my mapping onto RFC 6749 and RFC 8693.
ITEM GET
Every refusal is a test
Coming up next: A server that refuses everything passes all of these. So what makes a refusal count?
Replay tests: why a normal call comes first
IN SHORT A replay test only proves something after a normal call has worked.
A Replay Sending a captured request or proof again, hoping the server accepts it a second time. See the glossary test expects a refusal. But a server that rejects everything would pass it too, so it first checks that a normal call succeeds.
STEP BY STEP
Step 1. Normal call. The test calls the API with a fresh token and a fresh DPoP proof.
- Normal call The test calls the API with a fresh token and a fresh DPoP proof.
- It works The API answers 200. A later refusal is now a real refusal.
- Replay: refused The test sends the same proof again. The API has already seen its id: 401 invalid_dpop_proof.
RFC 9449 says servers “can store the jti value of each DPoP proof” and refuse repeats. The jti is the unique id inside each proof. That’s a mitigation, not a mandate.
ITEM GET
Mandatory where it writes
RFC 9449 also names a weakness itself: “An attacker in control of the client can pre-generate DPoP proofs for specific endpoints arbitrarily far into the future by choosing the iat value in the DPoP proof to be signed by the proof-of-possession key.”
WATCH OUT
Server nonces, unpredictable fresh values the server hands out and expects back, close that gap.
Keep the results of these tests in the same append-only trail as the agent’s actions, as in proving an agent’s work to an auditor.
This episode covers systems you control. Who authorized the agent is covered in the Know Your Agent episode. How a counterparty checks which agent it’s talking to is in verifying an Agent Card and ERC-8004, an Ethereum standard proposal that is still a Draft.
FAQ
No: it limits what a hijacked agent can reach, and for how long. The agent can still misuse its narrow token until it expires. Consequential actions still need approval outside the model: episode 4 treats short-lived credentials as one layer among four.
mTLS fits when the agent’s TLS session reaches the API unbroken, as in a mesh you run, or behind a proxy that forwards the certificate in a way you trust. DPoP lives in an HTTP header, so it survives gateways that end TLS. In my design, DPoP also gets replay checks: jti tracking, plus nonces on sensitive endpoints.
A typical API key lives for months and opens everything the account can reach. It works for anyone who copies it. In an agent, it can end up in logs, reaches every sub-agent and sits one prompt injection away from the model.
STAGE CLEAR
What you now know
- Which refusals to test: expired, replayed, stolen, too wide and wrong-API requests, each with its exact error.
- Why a replay test starts with a call that works: otherwise a server that refuses everything passes.
Check yourself
Tap or click a question to see the answer.
Your expired-token test gets a 500, and the request is blocked. Does the test pass?
No. It should expect 401 invalid_token. A 500 that happens to block today is a bug that can turn into a 200 tomorrow.
You finished every stage published so far in this series. Back to the series map
Web3 x AI engineer, former CTO of Integra. Named author (1 of 5) of ERC-3643, first author of ERC-6960, co-author of ERC-7410, and co-author of ERC-8203, which is still a draft.
Have a project to ship or a role to fill?
Discuss your project or roleMy work at the web3 x AI intersectionOpen-source tools I build
Follow the engineering notes
Get new articles on production AI and smart contracts by email.