Pomelo

Error Handling

Our API uses conventional HTTP status codes to indicate the success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information (e.g., a required parameter was missing), and codes in the 5xx range indicate an error with our servers.

HTTP Status Codes

Status CodeDescription
200 - OKEverything worked as expected.
400 - Bad RequestThe request was unacceptable, often due to missing a required parameter.
401 - UnauthorizedNo valid API key provided.
403 - ForbiddenThe API key doesn't have permissions to perform the request.
404 - Not FoundThe requested resource doesn't exist.
429 - Too Many RequestsToo many requests hit the API too quickly. See Rate Limits.
500, 502, 503, 504 - Server ErrorsSomething went wrong on our end.

Error Response Format

When an error occurs, our API returns a JSON response with the following structure:

{
  "error": {
    "type": "invalid_request_error",
    "message": "The 'model' parameter is required",
    "code": "parameter_required",
    "param": "model",
    "status": 400
  }
}

Error Fields

FieldDescription
typeThe type of error: authentication_error, invalid_request_error, api_error, etc.
messageA human-readable message providing details about the error.
codeA machine-readable error code.
paramIf the error is parameter-specific, the parameter related to the error.
statusThe HTTP status code.

Common Error Codes

Error CodeDescription
parameter_requiredA required parameter was not provided.
parameter_invalidA provided parameter is not valid.
invalid_api_keyThe API key provided is not valid.
rate_limit_exceededYou have exceeded your rate limit.
quota_exceededYou have exceeded your monthly quota.
server_errorAn error occurred on our server.

Handling Errors

We recommend implementing proper error handling in your applications to gracefully handle any API errors. Here's an example of how to handle errors when making API requests:

# Python example
import requests

def make_api_request(endpoint, data):
    url = f"https://api.pomeloapi.example.com{endpoint}"
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }
    
    try:
        response = requests.post(url, headers=headers, json=data)
        
        # Check if the request was successful
        response.raise_for_status()
        
        # Return the JSON response if the request was successful
        return response.json()
    except requests.exceptions.HTTPError as e:
        # Handle HTTP errors (4xx, 5xx)
        if response.status_code == 400:
            error = response.json().get("error", {})
            print(f"Bad request: {error.get('message')} (Code: {error.get('code')})")
        elif response.status_code == 401:
            print("Authentication error: Invalid API key")
        elif response.status_code == 429:
            print("Rate limit exceeded. Please slow down your requests.")
        else:
            print(f"HTTP error occurred: {e}")
    except requests.exceptions.RequestException as e:
        # Handle network-related errors
        print(f"Request error: {e}")
    
    return None

Need Help?

If you're experiencing persistent errors that you can't resolve, please contact our support team for assistance. We're here to help!