Skip to content

Error Handling

Reference for all error responses.

Error Response Format

All errors return JSON with this structure:

json
{
  "error": true,
  "message": "Human-readable error description",
  "code": "ERROR_CODE"
}

Error Codes Reference

Authentication Errors (401)

CodeMessageSolution
MISSING_API_KEYMissing API key. Include X-API-Key header.Add the X-API-Key header to your request
INVALID_API_KEYInvalid API key.Check your API key is correct

Authorization Errors (403)

CodeMessageSolution
SUBSCRIPTION_CANCELEDYour subscription has been canceled.Resubscribe at the pricing page
PAYMENT_PAST_DUEYour payment is past due.Update payment method in billing portal

Validation Errors (400)

CodeMessageSolution
MISSING_TITLEMissing required field: titleInclude title in your request body
TITLE_TOO_LONGTitle must be 200 characters or lessShorten your title
SUBTITLE_TOO_LONGSubtitle must be 300 characters or lessShorten your subtitle
INVALID_THEMEInvalid theme. Must be dark or lightUse "dark" or "light"
INVALID_TEMPLATEInvalid template. Must be default, minimal, or vibrantUse a valid template name
INVALID_AVATAR_URLInvalid author_avatar_url. Must be a valid URL.Provide a valid HTTPS URL
INVALID_JSONInvalid JSON bodyCheck your JSON syntax

Rate Limit Errors (429)

CodeMessageSolution
QUOTA_EXCEEDEDMonthly quota exceeded. Limit: X images.Upgrade plan or wait for monthly reset

Server Errors (500)

CodeMessageSolution
GENERATION_FAILEDFailed to generate image. Please try again.Retry the request; contact support if persistent

Handling Errors

JavaScript/Node.js

javascript
async function generateImage(options) {
  const response = await fetch('https://ogimageapi.io/api/generate', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.OG_IMAGE_API_KEY
    },
    body: JSON.stringify(options)
  });

  if (!response.ok) {
    const error = await response.json();
    
    switch (error.code) {
      case 'QUOTA_EXCEEDED':
        console.error('Quota exceeded - upgrade your plan');
        break;
      case 'INVALID_API_KEY':
        console.error('Check your API key');
        break;
      default:
        console.error(`Error: ${error.message}`);
    }
    
    throw new Error(error.message);
  }

  return response.arrayBuffer();
}

Python

python
import requests

def generate_image(options):
    response = requests.post(
        'https://ogimageapi.io/api/generate',
        headers={
            'Content-Type': 'application/json',
            'X-API-Key': os.environ.get('OG_IMAGE_API_KEY')
        },
        json=options
    )
    
    if not response.ok:
        error = response.json()
        
        if error.get('code') == 'QUOTA_EXCEEDED':
            raise QuotaExceededError(error['message'])
        elif error.get('code') == 'INVALID_API_KEY':
            raise AuthenticationError(error['message'])
        else:
            raise APIError(error['message'])
    
    return response.content

Retry Strategy

For transient errors (5xx), implement exponential backoff:

javascript
async function generateWithRetry(options, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await generateImage(options);
    } catch (error) {
      if (error.status >= 500 && attempt < maxRetries - 1) {
        // Exponential backoff: 1s, 2s, 4s
        await sleep(1000 * Math.pow(2, attempt));
        continue;
      }
      throw error;
    }
  }
}

Getting Help

If you encounter persistent errors:

  1. Check the FAQ for common issues
  2. Verify your API key and plan status
  3. Contact support with your error code and request details

Generate stunning Open Graph images programmatically.