agent.serve(), you can protect HTTP endpoints with authentication. Set agent.auth to an auth provider and all requests to /run and webhook endpoints require valid credentials.
API Key Authentication
X-API-Key header or the Authorization: Bearer <key> header:
A single API key or a set of allowed keys.
HTTP header name to read the key from. Falls back to the
Authorization header if the primary header is empty.apikey_<sha256[:12]>.
JWT Authentication
Authorization header:
Secret key or public key for token validation.
JWT algorithm.
Expected audience claim.
Expected issuer claim.
sub, then user_id, then id. Remaining claims are available in AuthContext.metadata.
Requires
pyjwt: pip install pyjwt or pip install 'definable[jwt]'Per-Webhook Auth Override
Individual webhooks can override the agent-level auth:AuthContext
When authentication succeeds, the provider returns anAuthContext:
| Field | Type | Description |
|---|---|---|
user_id | str | Canonical user identifier |
metadata | Dict[str, Any] | Extra claims or info from the provider |
Custom Auth Provider
Implement theAuthProvider protocol to create your own auth backend:
authenticate method can be sync or async. Return AuthContext on success, None on failure (returns 401).
Auth Bypass
/healthis always public- Webhooks with
auth=Falsebypass authentication - In dev mode,
/docs,/redoc, and/openapi.jsonare also public