API Reference

API Errors

HTTP error codes, SDK exceptions, and error handling patterns.

API Errors

Overview

Reference for HTTP error codes returned by the AgentTrust gateway and SDK exceptions raised on the client side.

Why It Matters

Correct error handling prevents silent governance bypass and enables proper alerting.

Prerequisites

None — reference document.

Step-by-Step Guide

Gateway HTTP errors

StatusMeaningAction
400Bad request — malformed bodyFix request schema
401Unauthorized — missing/invalid tokenCheck AGENTRUST_KEY
403Forbidden — tier insufficientUpgrade tier
404Resource not foundVerify envelope_id
422Unprocessable — validation failedFix request fields
429Rate limitedBack off; increase limit in config
500Internal errorCheck gateway logs
503Service unavailableCheck Postgres/Redis health

SDK exceptions

ExceptionWhen raised
BlockedErrorDecision outcome is block (or escalate with block config)
GatewayUnavailableErrorGateway unreachable + failure_mode=closed
GatewayVersionErrorSDK/gateway version incompatible
TierGateErrorTier-gated adapter or capability blocked
from agentrust_sdk import BlockedError, TierGateError, GatewayUnavailableError
from agentrust_sdk.decorator import BlockedError  # same class

TypeScript errors

import { BlockedError, GatewayError } from 'agentrust-sdk';

Examples

Handle all SDK errors:

from agentrust_sdk import AgentTrustClient, BlockedError, GatewayUnavailableError, TierGateError

try:
    with AgentTrustClient(failure_mode="closed") as client:
        result = client.validate(...)
except BlockedError as e:
    log.warning("Governance blocked: %s", e)
except GatewayUnavailableError:
    alert_ops("AgentTrust gateway down")
except TierGateError as e:
    log.error("Upgrade required: %s", e)

Best Practices

  • Alert on GatewayUnavailableError in production with failure_mode=closed
  • Log decision.reasons with every BlockedError
  • Handle 429 with exponential backoff
  • Never swallow 403 — indicates misconfigured tier

Common Mistakes

  • Catching generic Exception and continuing (masks governance failures)
  • Not distinguishing gateway down (503) from block (200 with block outcome)

Troubleshooting

See Troubleshooting.