Error Codes and Handling
This document defines all error codes used by the AITBC API and how to handle them.
Error Response Format
All API errors follow this format:
| Field |
Type |
Description |
detail |
string |
Human-readable description |
error_code |
string |
Machine-readable error code |
request_id |
string |
Request identifier for debugging |
HTTP Status Codes
| Code |
Meaning |
When Used |
| 200 |
OK |
Successful GET, POST (update) |
| 201 |
Created |
Successful POST (create) |
| 204 |
No Content |
Successful DELETE |
| 400 |
Bad Request |
Invalid input |
| 401 |
Unauthorized |
Missing/invalid authentication |
| 403 |
Forbidden |
Insufficient permissions |
| 404 |
Not Found |
Resource doesn't exist |
| 409 |
Conflict |
Resource state conflict |
| 422 |
Unprocessable Entity |
Validation error |
| 429 |
Too Many Requests |
Rate limited |
| 500 |
Internal Server Error |
Server error |
| 502 |
Bad Gateway |
Upstream service error |
| 503 |
Service Unavailable |
Maintenance/overload |
Error Codes by Category
Authentication Errors (AUTH_*)
| Code |
HTTP |
Description |
Resolution |
AUTH_MISSING_KEY |
401 |
No API key provided |
Include X-Api-Key header |
AUTH_INVALID_KEY |
401 |
API key is invalid |
Check API key is correct |
AUTH_EXPIRED_KEY |
401 |
API key has expired |
Generate new API key |
AUTH_INSUFFICIENT_SCOPE |
403 |
Key lacks required permissions |
Use key with correct scope |
Example:
Job Errors (JOB_*)
| Code |
HTTP |
Description |
Resolution |
JOB_NOT_FOUND |
404 |
Job doesn't exist |
Check job ID |
JOB_ALREADY_CLAIMED |
409 |
Job claimed by another miner |
Request different job |
JOB_ALREADY_COMPLETED |
409 |
Job already finished |
No action needed |
JOB_ALREADY_CANCELLED |
409 |
Job was cancelled |
Submit new job |
JOB_EXPIRED |
410 |
Job deadline passed |
Submit new job |
JOB_INVALID_STATUS |
400 |
Invalid status transition |
Check job state |
Example:
Validation Errors (VALIDATION_*)
| Code |
HTTP |
Description |
Resolution |
VALIDATION_MISSING_FIELD |
422 |
Required field missing |
Include required field |
VALIDATION_INVALID_TYPE |
422 |
Wrong field type |
Use correct type |
VALIDATION_OUT_OF_RANGE |
422 |
Value outside allowed range |
Use value in range |
VALIDATION_INVALID_FORMAT |
422 |
Wrong format (e.g., date) |
Use correct format |
VALIDATION_PROMPT_TOO_LONG |
422 |
Prompt exceeds limit |
Shorten prompt |
VALIDATION_INVALID_MODEL |
422 |
Model not supported |
Use valid model |
Example:
Miner Errors (MINER_*)
| Code |
HTTP |
Description |
Resolution |
MINER_NOT_FOUND |
404 |
Miner not registered |
Register miner first |
MINER_ALREADY_REGISTERED |
409 |
Miner ID already exists |
Use different ID |
MINER_OFFLINE |
503 |
Miner not responding |
Check miner status |
MINER_CAPACITY_FULL |
503 |
Miner at max capacity |
Wait or use different miner |
Receipt Errors (RECEIPT_*)
| Code |
HTTP |
Description |
Resolution |
RECEIPT_NOT_FOUND |
404 |
Receipt doesn't exist |
Check receipt ID |
RECEIPT_INVALID_SIGNATURE |
400 |
Signature verification failed |
Check receipt integrity |
RECEIPT_ALREADY_CLAIMED |
409 |
Receipt already processed |
No action needed |
Rate Limit Errors (RATE_*)
| Code |
HTTP |
Description |
Resolution |
RATE_LIMIT_EXCEEDED |
429 |
Too many requests |
Wait and retry |
RATE_QUOTA_EXCEEDED |
429 |
Daily/monthly quota hit |
Upgrade plan or wait |
Response includes:
Payment Errors (PAYMENT_*)
| Code |
HTTP |
Description |
Resolution |
PAYMENT_INSUFFICIENT_BALANCE |
402 |
Not enough AITBC |
Top up balance |
PAYMENT_FAILED |
500 |
Payment processing error |
Retry or contact support |
System Errors (SYSTEM_*)
| Code |
HTTP |
Description |
Resolution |
SYSTEM_INTERNAL_ERROR |
500 |
Unexpected server error |
Retry or report bug |
SYSTEM_MAINTENANCE |
503 |
Scheduled maintenance |
Wait for maintenance to end |
SYSTEM_OVERLOADED |
503 |
System at capacity |
Retry with backoff |
SYSTEM_UPSTREAM_ERROR |
502 |
Dependency failure |
Retry later |
Error Handling Best Practices
Retry Logic
JavaScript Error Handling
Logging Errors
Always log the request_id for debugging:
Reporting Issues
When reporting errors to support, include:
- Error code and message
- Request ID (from response)
- Timestamp of the error
- Request details (endpoint, parameters)
- Steps to reproduce
Error Code Reference Table
| Code |
HTTP |
Category |
Retryable |
AUTH_MISSING_KEY |
401 |
Auth |
No |
AUTH_INVALID_KEY |
401 |
Auth |
No |
AUTH_EXPIRED_KEY |
401 |
Auth |
No |
AUTH_INSUFFICIENT_SCOPE |
403 |
Auth |
No |
JOB_NOT_FOUND |
404 |
Job |
No |
JOB_ALREADY_CLAIMED |
409 |
Job |
No |
JOB_ALREADY_COMPLETED |
409 |
Job |
No |
JOB_ALREADY_CANCELLED |
409 |
Job |
No |
JOB_EXPIRED |
410 |
Job |
No |
VALIDATION_MISSING_FIELD |
422 |
Validation |
No |
VALIDATION_INVALID_TYPE |
422 |
Validation |
No |
VALIDATION_PROMPT_TOO_LONG |
422 |
Validation |
No |
VALIDATION_INVALID_MODEL |
422 |
Validation |
No |
MINER_NOT_FOUND |
404 |
Miner |
No |
MINER_OFFLINE |
503 |
Miner |
Yes |
RECEIPT_NOT_FOUND |
404 |
Receipt |
No |
RATE_LIMIT_EXCEEDED |
429 |
Rate |
Yes |
RATE_QUOTA_EXCEEDED |
429 |
Rate |
No |
PAYMENT_INSUFFICIENT_BALANCE |
402 |
Payment |
No |
SYSTEM_INTERNAL_ERROR |
500 |
System |
Yes |
SYSTEM_MAINTENANCE |
503 |
System |
Yes |
SYSTEM_OVERLOADED |
503 |
System |
Yes |