Authentication

Send Authorization: Bearer <token>.

Token classification

  • sk_... -> API key
  • JWT-shaped token -> access token
  • anything else -> invalid token (AUTH_INVALID_TOKEN)

Classification is handled by extractBearerToken(...) and classifyToken(...) in saas-ai-api/src/lib/authToken.ts.

Public auth modes

Public routes use one of these modes:

  • access_token_only
  • api_key_or_access_token

api_key_only exists on legacy or non-public routes and is not part of the current public docs surface.

Organization scoping

Current public routes require organizationId.

  • Read routes usually take it in the query string
  • Write and run routes usually take it in the request body

If organizationId is missing, the resolver returns 400 bad_request.

For API keys, an org mismatch returns AUTH_ORG_MISMATCH.

Public route summary

FamilyAuth modeUser permissionAPI-key scope
GET /api/agents, GET /api/agents/:id, GET /api/agents/:id/versions/:versionId/diffapi_key_or_access_tokenai.useagents:read
POST /api/agents, PATCH /api/agents/:id, POST /api/agents/:id/versions, POST /api/agents/:id/publish, PUT /api/agent-versions/:id/workflow, POST /api/agent-versions/:id/workflow/validate, POST /api/agents/:id/versions/:versionId/rollbackapi_key_or_access_tokenai.useagents:write
POST /api/agents/:id/runaccess_token_onlyai.usenot supported
GET /api/agent-runs/compare, GET /api/agent-runs/:id, POST /api/agent-runs/:id/load-inputsapi_key_or_access_tokenai.useruns:read
POST /api/agent-runs/:id/rerun-from-stepaccess_token_onlyai.usenot supported
POST /api/setup/verifyapi_key_or_access_tokenai.useruns:read
Skill read routes plus preview/diffapi_key_or_access_tokenai.useskills:read
Skill write/version/publish routesapi_key_or_access_tokenai.useskills:write
POST /api/skills/:id/runaccess_token_onlyai.usenot supported
Tool read routes plus diffapi_key_or_access_tokenai.usetools:read
Tool write/version routesapi_key_or_access_tokenai.usetools:write
Evaluation read routesapi_key_or_access_tokenai.useevaluations:read
Evaluation create/run routesapi_key_or_access_tokenai.useevaluations:write

Error shape

Auth failures use structured diagnostic fields such as code, title, category, why, and optional recovery.

See also

Was this page helpful?