Skip to main content

Error Handling

Creatoria Agent API Documentation

#Error Handling

This document describes the API error response format and common error codes.

#Error Response Format

All error responses follow a unified JSON format:

json{
  "statusCode": 400,
  "message": "Error description",
  "error": "Bad Request"
}

For validation errors, more detailed field information may be included:

json{
  "statusCode": 400,
  "message": ["name must be a string", "model is required"],
  "error": "Bad Request"
}

#HTTP Status Codes

Status CodeDescription
200Request successful
201Resource created successfully
202Request accepted (asynchronous processing)
204Operation successful, no content returned
400Bad request parameters
401Unauthorized (missing or invalid API Key)
403Insufficient permissions
404Resource not found
409Resource conflict
429Rate limit exceeded
500Internal server error

#Common Error Scenarios

#401 Unauthorized

Cause: API Key is missing or invalid

bash# Missing API Key
curl -X GET "https://your-domain.com/v1/agents"

# Returns
# HTTP 401
# {"statusCode":401,"message":"Unauthorized"}

Solution: Ensure the X-API-Key is correctly included in the request headers.

#400 Bad Request - Project context required

Cause: Missing Project context when creating an Agent

json{
  "statusCode": 400,
  "message": "Project context is required to create an agent. Ensure your account has a default project.",
  "error": "Bad Request"
}

Solution: Ensure the API Key is bound to a Project, or specify one via the X-Project-Id request header.

#403 Forbidden

Cause: The API Key does not have sufficient permissions for this operation

json{
  "statusCode": 403,
  "message": "Forbidden resource",
  "error": "Forbidden"
}

Solution: Check the API Key's permission level (read/write/admin).

#404 Not Found

Cause: The requested resource does not exist or does not belong to the current organization

json{
  "statusCode": 404,
  "message": "Agent agent_xxx not found",
  "error": "Not Found"
}

#429 Too Many Requests

Cause: Request rate exceeds the limit

json{
  "statusCode": 429,
  "message": "Too many requests",
  "error": "Too Many Requests"
}

Solution: Reduce request frequency and implement exponential backoff retry. See the Rate Limiting section below.

#Rate Limiting

API requests are subject to rate limits based on your subscription plan, enforced at three levels:

#Plan Limits

PlanPer MinutePer HourPer Day
Free601,00010,000
Pro60010,000100,000
Team3,00050,000500,000
Enterprise10,000200,0002,000,000

#Rate Limit Levels

LevelScopeWindowDescription
Level 1API Key1 minutePer-key request rate limit
Level 2Organization1 hourOrganization-level hourly request total
Level 3Organization24 hoursOrganization-level daily request total

#Response Headers

Every API response includes the following rate limit headers:

HeaderDescription
X-RateLimit-LimitMaximum requests in the current window
X-RateLimit-RemainingRemaining requests in the current window
X-RateLimit-ResetUnix timestamp when the window resets
Retry-AfterSeconds to wait when rate limited

#Rate Limit Error Response

json{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded. Please retry after 45 seconds.",
    "retryAfter": 45
  }
}

#Best Practices

#Retry Strategy

For 429 and 5xx errors, it is recommended to implement exponential backoff retry:

javascriptasync function fetchWithRetry(url, options, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url, options);
      if (response.status === 429 || response.status >= 500) {
        const retryAfter = response.headers.get('Retry-After');
        const delay = retryAfter
          ? parseInt(retryAfter) * 1000
          : Math.pow(2, i) * 1000;
        await new Promise(resolve => setTimeout(resolve, delay));
        continue;
      }
      return response;
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      const delay = Math.pow(2, i) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}

#Error Logging

It is recommended to log the following information for debugging:

  1. Request URL and method
  2. HTTP status code
  3. Error response body
  4. Request timestamp
  5. Request ID (if included in the response headers)

#SSE Streaming Error Handling

In streaming chat, errors are delivered via SSE events:

data: {"error":"Tool execution failed: timeout","sessionId":"sess_xxx"}

data: [DONE]

It is recommended to listen for the error field on the client side and handle it appropriately.