Skip to Content

Error Handling

Stable

Learn how to handle API errors effectively in your elizaOS Cloud integrations.

Error Format

All errors follow a consistent JSON format:

{ "error": { "code": "ERROR_CODE", "message": "Human-readable description", "details": "Additional context (optional)", "requestId": "req_abc123" } }

HTTP Status Codes

StatusMeaningAction
400Bad RequestFix request parameters
401UnauthorizedCheck authentication
402Payment RequiredAdd credits or payment
403ForbiddenCheck permissions
404Not FoundVerify resource exists
409ConflictResolve conflict
422UnprocessableFix validation errors
429Rate LimitedSlow down, retry later
500Server ErrorRetry, contact support
503Service UnavailableWait, retry later

Error Codes

Authentication Errors

CodeDescriptionSolution
UNAUTHORIZEDInvalid/missing authCheck API key
INVALID_API_KEYAPI key not recognizedVerify key is correct
EXPIRED_TOKENSession expiredRe-authenticate
FORBIDDENInsufficient permissionsCheck key permissions

Request Errors

CodeDescriptionSolution
INVALID_REQUESTMalformed requestCheck request format
MISSING_FIELDRequired field missingAdd required field
INVALID_FIELDField value invalidFix field value
VALIDATION_ERRORSchema validation failedCheck all fields

Resource Errors

CodeDescriptionSolution
NOT_FOUNDResource doesn’t existVerify resource ID
ALREADY_EXISTSDuplicate resourceUse existing resource
CONFLICTState conflictResolve conflict

Rate Limiting

CodeDescriptionSolution
RATE_LIMITEDToo many requestsWait and retry
QUOTA_EXCEEDEDPlan quota exceededUpgrade plan

Payment Errors

CodeDescriptionSolution
INSUFFICIENT_CREDITSNot enough creditsTop up account
PAYMENT_REQUIREDPayment neededAdd payment method
PAYMENT_FAILEDPayment declinedCheck payment method

Generation Errors

CodeDescriptionSolution
CONTENT_POLICYContent policy violationModify content
GENERATION_FAILEDGeneration errorRetry with different input
MODEL_UNAVAILABLEModel offlineTry different model
CONTEXT_LENGTHInput too longReduce input size

Handling Errors

JavaScript Example

async function makeRequest(url, options) { try { const response = await fetch(url, options); if (!response.ok) { const error = await response.json(); switch (error.error.code) { case "RATE_LIMITED": const retryAfter = response.headers.get("Retry-After"); await sleep(retryAfter * 1000); return makeRequest(url, options); // Retry case "UNAUTHORIZED": throw new AuthError("Invalid API key"); case "INSUFFICIENT_CREDITS": throw new PaymentError("Please top up your account"); default: throw new ApiError(error.error.message, error.error.code); } } return response.json(); } catch (error) { if (error instanceof ApiError) throw error; throw new NetworkError("Network request failed"); } }

Python Example

import requests import time class ElizaAPIError(Exception): def __init__(self, code, message): self.code = code self.message = message def make_request(url, headers, data=None, retries=3): for attempt in range(retries): try: response = requests.post(url, headers=headers, json=data) if response.status_code == 429: retry_after = int(response.headers.get('Retry-After', 60)) time.sleep(retry_after) continue if not response.ok: error = response.json()['error'] raise ElizaAPIError(error['code'], error['message']) return response.json() except requests.RequestException as e: if attempt == retries - 1: raise time.sleep(2 ** attempt) # Exponential backoff

Retry Strategy

Retryable Errors

These errors can be retried:

Non-Retryable Errors

Don’t retry these:

Exponential Backoff

async function retryWithBackoff(fn, maxRetries = 5) { for (let i = 0; i < maxRetries; i++) { try { return await fn(); } catch (error) { if (!isRetryable(error) || i === maxRetries - 1) { throw error; } const delay = Math.min(1000 * Math.pow(2, i), 30000); const jitter = Math.random() * 1000; await sleep(delay + jitter); } } }

Debugging

Request ID

Every response includes a request ID:

X-Request-Id: req_abc123def456

Include this when contacting support.

Verbose Errors

Enable verbose errors in development:

curl -X POST "https://cloud.milady.ai/api/v1/chat/completions" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "X-Debug: true" \ -d '...'

Best Practices

Troubleshooting

”UNAUTHORIZED” errors

Problem: Getting 401 errors on every request.

Solutions:

  1. Verify your API key starts with ek_live_ or ek_test_
  2. Check the key hasn’t been revoked in Dashboard → API Keys
  3. Ensure you’re using Authorization: Bearer YOUR_KEY (not X-API-Key)

“RATE_LIMITED” errors

Problem: Getting 429 errors during normal usage.

Solutions:

  1. Implement exponential backoff (see code example above)
  2. Check your rate limit headers: X-RateLimit-Remaining
  3. Upgrade your plan for higher limits at Dashboard → Billing

”INSUFFICIENT_CREDITS” errors

Problem: Getting 402 errors.

Solutions:

  1. Check your balance at Dashboard → Billing
  2. Enable auto top-up to avoid interruptions
  3. Top up credits via Stripe or crypto payments

Streaming not working

Problem: Stream responses come as a single chunk.

Solutions:

  1. Ensure stream: true is set in your request body
  2. Don’t buffer the response—read chunks as they arrive
  3. Check your proxy/CDN isn’t buffering SSE responses

Agent not responding as expected

Problem: Agent ignores personality/style settings.

Solutions:

  1. Verify character JSON is valid with the API Explorer
  2. Check you’re using the agent ID (not model name) as the model parameter
  3. Clear conversation history and start fresh

Next Steps