API Error Codes

This page documents all error codes that the Bleu.js API may return, along with their meanings and suggested solutions.

HTTP Status Codes

Status CodeError TypeDescriptionSolution
400Bad RequestInvalid request format or parametersCheck request body and parameters
401UnauthorizedInvalid or missing API keyVerify your API key is correct
403ForbiddenInsufficient permissionsCheck your plan and permissions
404Not FoundResource or endpoint not foundVerify the endpoint URL
429Too Many RequestsRate limit exceededWait or upgrade your plan
500Internal Server ErrorServer-side errorRetry later or contact support
503Service UnavailableService temporarily unavailableRetry later

API-Specific Error Codes

INVALID_PROMPT

The provided prompt is invalid or too long.

Solution: Check prompt length and content

MODEL_NOT_FOUND

The specified model does not exist or is not available.

Solution: Use a valid model name

QUOTA_EXCEEDED

You have exceeded your usage quota.

Solution: Upgrade your plan or wait for reset

INVALID_PARAMETERS

One or more parameters are invalid.

Solution: Check parameter values and types

CONTENT_FILTERED

The generated content was filtered due to policy violations.

Solution: Modify your prompt to avoid policy violations

Error Response Format

All error responses follow this JSON format:

{
  "error": {
    "code": "INVALID_PROMPT",
    "message": "The provided prompt is invalid",
    "details": "Prompt length exceeds maximum allowed length of 4000 characters",
    "request_id": "req_1234567890abcdef"
  }
}

Error Handling Best Practices

  • Always check the HTTP status code first
  • Parse the error response for detailed information
  • Implement retry logic for transient errors (5xx)
  • Log request IDs for debugging
  • Handle rate limits with exponential backoff
  • Provide user-friendly error messages

Example: Error Handling

// JavaScript example
async function handleApiError(response) {
  if (!response.ok) {
    const errorData = await response.json();
    
    switch (response.status) {
      case 401:
        console.error('Authentication failed:', errorData.error.message);
        // Handle authentication error
        break;
      case 429:
        const retryAfter = response.headers.get('Retry-After');
        console.log(`Rate limited. Retry after ${retryAfter} seconds`);
        // Implement retry logic
        break;
      case 400:
        console.error('Bad request:', errorData.error.details);
        // Handle validation error
        break;
      default:
        console.error('API error:', errorData.error);
        // Handle other errors
    }
    
    throw new Error(errorData.error.message);
  }
  
  return response.json();
}

Getting Help

If you're experiencing persistent errors or need help debugging: