API Reference

Xagent exposes three API surfaces. This page is the canonical reference for how to authenticate against each one and how errors are shaped — the other API pages link back here rather than repeat it.

API Surfaces

SurfacePrefixAuthenticationError shape
Application API/apiJWT access token from sign-in.{ "detail": "..." }
Workspace SDK/v1API key — workspace xag_personal_<prefix>_<secret> or runtime xag_<prefix>_<secret>.{ "error": { "code", "message" } }
Billing & Teams/api/billing, /api/teamsJWT access token + team context.{ "detail": "..." }

Base URL

All endpoints are served from your Xagent deployment. For a local install the backend listens on port 8000:

Self-hosted:  http://localhost:8000
Production:   https://your-domain.com

Authentication

Every request carries a bearer token; which token depends on the surface (see the table above):

Authorization: Bearer <token>
  • Application API (/api) — a JWT access token from POST /api/auth/login. See Authentication.
  • Workspace SDK (/v1) — an API key. Use a personal key (xag_personal_…) to manage agents and templates, and a runtime key (xag_…) to run tasks.

Keys are shown once

Both API key types are returned in full only at creation. The <prefix> is a public-safe 6-character handle; the secret half is never retrievable again — rotate the key to replace it. Using the wrong key type on a /v1 endpoint returns 401 invalid_api_key.

Error Handling

There are two error envelopes. Parse the one that matches the surface you are calling.

Application API and Billing/Teams (/api/*) use FastAPI's default shape — string-match or display the detail:

{ "detail": "Agent not found" }

Workspace SDK (/v1/*) uses a stable, machine-readable envelope — switch on error.code:

{
  "error": {
    "code": "invalid_input",
    "message": "Request body failed validation."
  }
}

The /v1 surface returns these codes:

Core codes

CodeHTTPMeaning
invalid_api_key401Any authentication failure — missing, malformed, wrong-type, expired, paused, or revoked key. One opaque code by design; the message is always Invalid or revoked API key.
invalid_input422, also 400 / 413Body or parameter validation failed. 400 for client-side rejections (e.g. inaccessible file ids); 413 when an upload exceeds the size cap.
agent_not_found404Agent does not exist or is not bound to this key. Also returned when a workforce key sends agent_id.
workforce_not_found404Workforce does not exist or is not bound to this key. Also returned when an agent key sends workforce_id.
template_not_found404Template id is unknown or unavailable.
task_not_found404Task does not exist, does not belong to this key, or was not created through the SDK.
file_not_found404A file id in message.files is inaccessible. Returned on workforce-run creation; the task endpoints report this as invalid_input (400) instead.
task_busy409Task is still running and cannot accept new input yet. Retryable — poll status, then retry.
internal_error500, also 503Server-side failure; the detail is sanitized. 503 signals a temporarily unavailable dependency (e.g. file storage).

Workforce run conflicts — all 409, and unlike task_busy these are permanent: retrying the same request will not succeed.

CodeMeaning
workforce_archivedThe workforce is archived. Restore it or target another workforce.
workforce_not_activeThe workforce is not in active status (for example, still a draft). Publish it first.
workforce_config_changedThe run's pinned configuration no longer matches the workforce. Start a new run.
idempotency_conflictThe idempotency_key was already used by a run whose task no longer exists. Use a new key.

Connector runtime — returned when a request carries connector_runtime_context.

CodeHTTPMeaning
connector_not_found404The referenced connector was not found or is not accessible.
invalid_runtime_context400Malformed runtime context (duplicate reference, bad shape, unsupported selector).
missing_runtime_context400A required runtime context value was not supplied.
runtime_context_immutable409Runtime context cannot be changed after the task is created.
runtime_secret_not_allowed400A runtime secret is not permitted for this entry point.
runtime_secret_unavailable400A required runtime secret is unavailable.
connector_runtime_unavailable503Runtime context is temporarily unavailable. Retry later.

Reserved codes

Handle these defensively — they are part of the contract but are not emitted by the /v1 endpoints in this deployment: rate_limited (429), quota_exceeded and client_quota_exceeded (402, emitted by hosted deployments), scheduled_secret_unavailable, mcp_oauth_authorization_failed, delegated_authorization_failed.

Pin against the code, not the status

The code is the stable contract; message is human-readable and may change. The HTTP status is chosen per endpoint, so a single code can appear with more than one status (invalid_input and internal_error both do).

Validation & quotas

Body validation fails as 422 invalid_input on /v1; the untyped Billing/Teams bodies return 400 with a detail message. Exceeding a plan quota returns 402 Payment Required — see Usage & Quotas. There is no per-second rate limiting.

Interactive & Machine-Readable Spec

Every deployment ships live API explorers generated from the server's OpenAPI schema:

ToolPathBest for
Swagger UI/docsTrying requests interactively.
ReDoc/redocReadable reference for the whole API.
OpenAPI JSON/openapi.jsonThe raw spec — import into Postman or codegen.

API Groups

GroupPrefixPurpose
Authentication/api/authLogin, SSO, refresh, password management.
Agents/api/agentsCreate, configure, publish, and key agents.
Workforces/api/workforcesMulti-agent teams and runs.
Knowledge Bases/api/kbIngest and search documents.
Tools / Skills/api/tools, /api/skillsTooling and packaged capabilities.
MCP / Custom APIs/api/mcp, /api/custom-apisExternal tool integrations.
Chat / Tasks/api/chatCreate and track task runs.
Teams/api/teams, /api/invitationsWorkspaces, members, invitations.
Billing/api/billing, /api/webhooksSubscriptions, usage, and Stripe webhooks.
Workspace SDK/v1Versioned agent & task SDK.

Reference Pages