Errors
GenRex uses conventional HTTP status codes and provides detailed error information to help you handle issues.
Error Response Format
All errors follow this structure:
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable description of the error"
}
}
HTTP Status Codes
| Status | Meaning |
|---|---|
200 |
Success |
201 |
Created - Resource created successfully |
400 |
Bad Request - Invalid parameters |
401 |
Unauthorized - Invalid or missing API key |
402 |
Payment Required - Insufficient credits |
403 |
Forbidden - API key inactive or lacks permission |
404 |
Not Found - Resource does not exist |
422 |
Unprocessable Entity - Validation failed |
429 |
Too Many Requests - Rate limit exceeded |
500 |
Internal Server Error - Something went wrong |
Error Codes
Authentication Errors
| Code | HTTP | Description |
|---|---|---|
UNAUTHENTICATED |
401 | Missing authentication credentials |
INVALID_API_KEY |
401 | API key is invalid or does not exist |
ACCOUNT_DISABLED |
403 | Account is disabled |
INSUFFICIENT_CREDITS |
402 | Account has insufficient credits |
Validation Errors
| Code | HTTP | Description |
|---|---|---|
VALIDATION_ERROR |
422 | Request parameters failed validation |
INVALID_PARAMETER |
400 | Invalid parameter value |
Generation Errors
| Code | Description |
|---|---|
RESEARCH_ERROR |
Research phase failed |
TEXT_GENERATION_ERROR |
Text generation failed |
IMAGE_GENERATION_ERROR |
Image generation failed |
AUDIO_GENERATION_ERROR |
Audio narration generation failed |
CONTENT_MODERATION |
Content flagged by moderation policy |
Resource Errors
| Code | HTTP | Description |
|---|---|---|
NOT_FOUND |
404 | Resource does not exist |
FORBIDDEN |
403 | You do not have access to this resource |
INVALID_TYPE |
400 | Process type mismatch (e.g., checking research status on a document) |
RATE_LIMIT_EXCEEDED |
429 | Too many requests |
Handling Errors
const response = await fetch('https://api.genrex.io/v1/document/create', {
method: 'POST',
headers: {
'Authorization': 'Bearer grx_sk_your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt: 'Write about AI' })
});
const data = await response.json();
if (!response.ok) {
// Handle error based on code
switch (data.error.code) {
case 'INVALID_API_KEY':
case 'UNAUTHENTICATED':
console.error('Check your API key');
break;
case 'INSUFFICIENT_CREDITS':
console.error('Add more credits to your account');
break;
case 'VALIDATION_ERROR':
console.error('Fix request parameters:', data.error.message);
break;
case 'RATE_LIMIT_EXCEEDED':
// Implement exponential backoff
await sleep(1000);
// Retry request
break;
default:
console.error('Error:', data.error.message);
}
}
Failed Prompt Details
When a prompt fails during processing, the status endpoint returns additional error details:
{
"success": false,
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "failed",
"error": {
"step": "generating",
"message": "Content was flagged by moderation policy",
"code": "CONTENT_MODERATION"
}
}
| Field | Description |
|---|---|
error.step |
Pipeline step that failed: researching, generating, images, or audio |
error.code |
Machine-readable error code |
error.message |
Human-readable error description |