Skip to content
GatewayMarkdown

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).

  1. Allow agents to read invoices. The subject is any token whose principal_type is agent, 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" } }'
  2. Link it to the default set and the url type, each with the revision the last answer’s ETag gave:

    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" }'
  3. Let the agent ask for tokens for the API. Add https://api.example.com to the allowedResources of 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.

Call through the gateway with the agent’s token for https://api.example.com:

You sendYou get
GET /invoices/1Your API’s own answer. Your API sees x-agent-id set to the agent’s id
DELETE /invoices/1403, reason no_matching_policy
A user’s token, GET /invoices/1403: the policy names agents only

Then quarantine the agent:

Terminal window
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.

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.