Authorization
How the gateway turns an authenticated request into exactly one recorded decision, and every check that runs between the signature and the policy.
Authorization answers one question for an authenticated agent: may this operation run against this resource right now? The answer is always exactly one of allow, deny, or require_approval, and it is recorded before anything executes.
The authorize request
POST /api/v1/runtime/authorize
Content-Type: application/json
X-AgentShield-Agent-Id: …
X-AgentShield-Timestamp: …
X-AgentShield-Nonce: …
X-AgentShield-Signature: …{
"agent_id": "3f2b8c1e-6a4d-4f7e-9b21-5c8d0e7a4b13",
"organization_id": "9a7e5d2c-1b3f-4c6a-8e0d-2f4b6a8c0e1d",
"execution_id": "c4d6e8f0-2a4c-4e6a-8c0e-1a3c5e7a9b2d",
"tool_name": "http.request",
"operation": "http.get",
"resource": "https://api.github.com/repos/octo/hello",
"arguments": { "headers": { "Accept": "application/json" } },
"requested_at": "2026-11-30T12:00:00Z",
"idempotency_key": "idem-5f0d2c8e9a1b4c7d"
}All nine fields are required and unknown fields are rejected. tool_name matches ^[A-Za-z0-9_.:-]{1,128}$, resource is 1–512 characters, arguments must be a JSON object, and idempotency_key is 16–200 printable characters.
The order of checks
Two properties matter here:
- Before a decision exists, failures (bad signature, replay, budget) return an error and record nothing. Policy never runs.
- After authentication, every failure is a recorded
denywith a reason. A database error during policy load ispolicy load failed; an invalid stored document ispolicy evaluation failed. Neither is ever an allow.
The response
| Outcome | HTTP | Body |
|---|---|---|
allow | 200 | decision_id, outcome, explanation |
require_approval | 200 | Also approval_id and approval_expires_at |
deny | 403 | The recorded decision |
{
"decision_id": "7f1c2a9e-…",
"outcome": "require_approval",
"explanation": {
"policy_id": "…",
"policy_version": 3,
"matched_rule": "approval_required:payment.refund",
"reason": "approval required"
},
"approval_id": "3b9e…",
"approval_expires_at": "2026-11-30T12:15:00Z"
}allow does not execute anything. The agent must call execute with the decision_id and the same idempotency_key.
What is written
In a single PostgreSQL transaction the gateway writes:
- A
tool_invocationsrow with the tool, operation, resource, the redacted arguments, the SHA-256 of the canonical arguments, and the idempotency key. - An
authorization_decisionsrow with the outcome, explanation, and risk (nonefor allow,mediumfor approval,lowfor deny). - A
security_eventsrow of typeauthorization.decidedand its audit-chain link. - For
require_approval, a pendingapproval_requestsrow bound to the SHA-256 of the raw body, expiring in 15 minutes. - Any behavioral incidents. See Budgets and limits.
If any write fails, the whole transaction rolls back and the agent receives 500 internal_error.
Idempotency
The idempotency_key makes authorize safe to retry. Keys are unique per organization. A retry with the same key, execution_id, tool, operation, resource, and arguments returns the stored decision instead of creating a new one. Reusing a key with any of those fields changed returns 409 conflict ("idempotency key does not match this request"). Every retry still needs a fresh nonce and signature.
The SDK clients generate a new execution_id and key per call unless you pass them, so pass both explicitly when you want a network-level retry to be idempotent.
Where policy comes in
The operation is evaluated as a policy action against the organization's active policy and the agent's active policy. The rules are covered in Policy evaluation, where you can also try them in the playground.
Implementation references
Was this page helpful?
Request Signing
The AgentShield v1 request signature. The exact signing input, header encoding, verification rules, and how to implement it in another language.
Policy Evaluation
The policy document format, the precedence rules that combine organization and agent policies, resource rules, and an interactive playground.