Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.emergence.ai/llms.txt

Use this file to discover all available pages before exploring further.

Error Codes

All CRAFT APIs return consistent error responses. This page documents the error format, all error codes, and troubleshooting guidance for each.

Error Response Format

Error responses follow a standard JSON structure:
{
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "message": "Agent with ID '550e8400-e29b-41d4-a716-446655440000' not found.",
    "status": 404,
    "details": {
      "resource_type": "artifact",
      "resource_id": "550e8400-e29b-41d4-a716-446655440000"
    },
    "request_id": "req-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736"
  }
}
FieldTypeDescription
codestringMachine-readable error code
messagestringHuman-readable error description
statusintegerHTTP status code
detailsobjectAdditional context (varies by error type)
request_idstringUnique request identifier for support
trace_idstringOpenTelemetry trace ID for end-to-end debugging

HTTP Status Codes

StatusMeaningWhen Returned
400Bad RequestInvalid request body, missing required fields, malformed parameters
401UnauthorizedMissing, expired, or invalid JWT token
403ForbiddenValid token but insufficient permissions
404Not FoundResource does not exist or is not accessible
409ConflictResource already exists or version conflict
422Unprocessable EntityRequest is well-formed but semantically invalid
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUnexpected server error
502Bad GatewayUpstream service (Keycloak, OpenFGA) unavailable
503Service UnavailableService is starting up or shutting down

Error Codes Reference

The OpenAPI specifications define a base ErrorCode enum with 9 values: INVALID_REQUEST, INVALID_TOKEN, INSUFFICIENT_PERMISSIONS, RESOURCE_NOT_FOUND, RESOURCE_ALREADY_EXISTS, VALIDATION_ERROR, RATE_LIMIT_EXCEEDED, SERVICE_UNAVAILABLE, INTERNAL_ERROR. The implementation may return more specific codes within each category as documented below.

Authentication Errors (401)

CodeMessageTroubleshooting
UNAUTHENTICATEDNo authentication token providedInclude Authorization: Bearer <token> header
TOKEN_EXPIREDAccess token has expiredRefresh the token or obtain a new one
TOKEN_INVALIDToken signature verification failedEnsure the token was issued by the correct Keycloak realm
TOKEN_MALFORMEDToken format is invalidCheck that the token is a valid JWT (three base64-encoded segments separated by dots)

Authorization Errors (403)

CodeMessageTroubleshooting
FORBIDDENInsufficient permissions for this operationCheck your role assignment on the target project; see RBAC Configuration
PROJECT_ACCESS_DENIEDNo access to the specified projectVerify the project ID in the request matches a project you have been granted access to
ORG_ACCESS_DENIEDToken does not belong to this organizationAuthenticate against the correct Keycloak realm for the target organization

Resource Errors (404, 409)

CodeMessageTroubleshooting
RESOURCE_NOT_FOUNDResource not foundVerify the resource ID and ensure you have can_read permission
RESOURCE_ALREADY_EXISTSResource with this identifier already existsUse a unique name or identifier; use PUT to update existing resources
VERSION_CONFLICTResource has been modified by another requestRe-fetch the resource and retry with the current version

Validation Errors (400, 422)

CodeMessageTroubleshooting
VALIDATION_ERRORRequest body validation failedCheck the details field for specific field-level errors
INVALID_PARAMETERInvalid query parameterVerify parameter name, type, and allowed values
MISSING_REQUIRED_FIELDRequired field is missingInclude all required fields in the request body
INVALID_FORMATField value format is invalidCheck the expected format (UUID, URL, email, etc.)
SEARCH_QUERY_INVALIDMalformed search queryUse plain text for search queries; special operators are reserved

Rate Limiting Errors (429)

CodeMessageTroubleshooting
RATE_LIMIT_EXCEEDEDRate limit exceededWait for the Retry-After header duration; implement exponential backoff
QUOTA_EXCEEDEDTenant quota exceededContact your administrator to increase the quota for the exceeded dimension

Server Errors (500, 502, 503)

CodeMessageTroubleshooting
INTERNAL_ERRORAn unexpected error occurredRetry the request; if persistent, report with request_id and trace_id
UPSTREAM_UNAVAILABLEUpstream service is unavailableKeycloak or OpenFGA may be down; check service health. Governance down causes Assets/Utils to return 403
SERVICE_STARTINGService is initializingWait for the service to complete startup; check readiness probe
DATABASE_ERRORDatabase operation failedRetry the request; if persistent, check database connectivity

Handling Errors in Code

from em_runtime_assets_sdk import AssetsClient, ApiError

client = AssetsClient(base_url="https://<host>:8002", token=token)

try:
    agent = await client.artifacts.get(artifact_uri)
except ApiError as e:
    if e.status == 401:
        # Token expired -- refresh and retry
        token = await refresh_token()
        client.token = token
        agent = await client.artifacts.get(artifact_uri)
    elif e.status == 404:
        print(f"Agent not found: {e.error.message}")
    elif e.status == 429:
        # Rate limited -- wait and retry
        await asyncio.sleep(e.retry_after)
        agent = await client.artifacts.get(artifact_uri)
    else:
        print(f"Error {e.error.code}: {e.error.message}")
        print(f"Request ID: {e.error.request_id}")
        raise

Retry Strategy

For transient errors (429, 500, 502, 503), implement exponential backoff with jitter:
AttemptWait TimeMax Wait
1st retry1 second + jitter2 seconds
2nd retry2 seconds + jitter4 seconds
3rd retry4 seconds + jitter8 seconds
4th retry8 seconds + jitter16 seconds
Max retries530 seconds
For 429 errors, always respect the Retry-After header rather than using exponential backoff. The header provides the exact wait time until the rate limit window resets.

Getting Help

When reporting an issue, include:
  1. The request_id from the error response
  2. The trace_id for end-to-end correlation
  3. The timestamp of the request
  4. The full error response body

Next Steps

API Overview

Review the full API structure and endpoints.

API Authentication

Learn how to obtain and manage JWT tokens.

Python SDK

Use the Python SDK with built-in error handling.

TypeScript SDK

Use the TypeScript SDK with built-in error handling.