Open an API to agents
Let your organization's agents call an API through the gateway, read-only, and see a stopped agent refused within seconds.
API
Your invoices API should be open to your AI agents, but only to read, and an agent that misbehaves should lose access at once, not when its token runs out. With the gateway in front of the API, a policy in the realm says what agents may do, the gateway refuses everything else, and quarantining an agent stops it at the API within one revocation poll. This guide is for the team that owns the API and the realm administrator who runs the agents.
Before you start: the gateway runs in front of the API as in Get started with Gateway,
enforcing the default policy set, with the audience https://api.example.com. Its image isn’t published yet: ask
your Cvyūh contact for it. The agent invoice-agent is registered, as in
Register an agent. You’re a realm administrator in a group
holding RealmOwner, with your session in $CVYUH_SESSION (Call the API).
Write the policy
Section titled “Write the policy”-
Allow agents to read invoices. The subject is any token whose
principal_typeisagent, whichever agent it is:Terminal window curl -i "https://foobar.cvyuh.com/api/v0/am/objects/v1/policy?id=agents-read-invoices" \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "active": true,"resources": ["*://*:*/invoices/*"],"actionValues": { "GET": true },"subject": { "type": "JwtClaim", "claimName": "principal_type", "claimValue": "agent" } }' -
Link it to the
defaultset and theurltype, each with the revision the last answer’sETaggave:Terminal window curl https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/agents-read-invoices/relationships/policySet \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-H 'If-Match: "<rev>"' \-d '{ "targetId": "default" }'curl https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/agents-read-invoices/relationships/resourceType \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-H 'If-Match: "<rev>"' \-d '{ "targetId": "url" }' -
Let the agent ask for tokens for the API. Add
https://api.example.comto theallowedResourcesof the agent’s client. A list is replaced whole, so send the resources it already names with it.
The gateway picks the policy up at its next poll, within a minute.
Check it worked
Section titled “Check it worked”Call through the gateway with the agent’s token for https://api.example.com:
| You send | You get |
|---|---|
GET /invoices/1 | Your API’s own answer. Your API sees x-agent-id set to the agent’s id |
DELETE /invoices/1 | 403, reason no_matching_policy |
A user’s token, GET /invoices/1 | 403: the policy names agents only |
Then quarantine the agent:
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/agent/invoice-agent \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \ -H "Content-Type: application/json" \ -d '{ "status": "quarantined" }'Call again with the same token: within ten seconds, the gateway’s next revocation poll, the answer is
401 agent_revoked. The agent can’t get a new token either. The quarantine is on the audit trail as a PATCHED
record for the agent; the gateway’s refusal is a warning line in its own log.
Undo it
Section titled “Undo it”Set the agent’s status back to active to let it in again, and delete the agents-read-invoices policy to close the
API to agents.
Related
Section titled “Related”- Run the gateway: every check a request goes through.
- Requests and refusals: what callers see.
- Stop an agent: quarantine and kill, and every agent beneath.
- Policies: writing more rules.