Skip to Content
ReferenceError handling

Error handling

OpenPixels provides a structured error handling approach that helps you identify and resolve issues when using the API. Each error is categorized by both a specific error code and a broader error type, allowing for more precise error handling in your applications.

Error structure

Every error response from OpenPixels follows a consistent structure with these key components:

  • type: A broad category the error falls into (e.g., "AUTHENTICATION_ERROR")
  • code: A specific error code identifying the exact error (e.g., "INVALID_API_KEY")
  • message: A human-readable description of what went wrong
  • params: Additional context about the error (varies by error type)

Error types

Errors in OpenPixels are categorized into the following types:

Error TypeDescription
PROVIDER_ERRORErrors related to third-party model providers
INTERNAL_SERVER_ERRORUnexpected internal system errors
BAD_REQUEST_ERRORErrors due to invalid input or parameters
AUTHENTICATION_ERRORErrors with API keys or authentication
BILLING_ERRORErrors related to credits or payment issues
AVAILABILITY_ERRORErrors when services or models are unavailable

Error codes

Authentication errors

CodeDescription
INVALID_API_KEYThe API key provided is not valid
MISSING_API_KEYNo API key was provided with the request

Provider errors

Provider errors will typically be retried or rerouted automatically by OpenPixels, unless you set a specific provider in the request.

CodeDescription
PROVIDER_ERRORGeneric error when interacting with a provider
PROVIDER_HTTP_ERRORHTTP error when communicating with a provider
PROVIDER_JOB_ERRORError during job execution by a provider
PROVIDER_TIMEOUTProvider took too long to respond
PROVIDER_NOT_FOUNDThe requested provider was not found
NO_PROVIDERS_WORKINGNo providers are available to handle the request

Billing errors

CodeDescription
NO_CREDITSUser has insufficient credits for the requested operation

Request errors

CodeDescription
INVALID_ARGUMENTSThe request contains invalid arguments
UNKNOWN_MODELThe requested model does not exist or is not supported

System errors

CodeDescription
UNKNOWN_ERRORGeneric error when the cause is not known
INTERNAL_SERVER_ERRORInternal server error

Handling errors in your code

JavaScript/TypeScript example

import { OpenPixels } from 'openpixels'; const client = new OpenPixels('sk-op-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); async function generateImage() { try { const result = await client.run({ model: 'flux-dev', prompt: 'a beautiful sunset over the ocean', }); if (result.error) { // Handle error from the result object console.error(`Generation failed: ${result.error.message}`); if (result.error.code === 'NO_CREDITS') { console.error('You need to purchase more credits to continue.'); } return; } // Process successful response console.log('Generated image:', result.data); } catch (error) { // Handle unexpected errors (network issues, etc.) console.error('Unexpected error:', error); } }

Python example

from openpixels import OpenPixels client = OpenPixels(api_key='sk-op-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') try: result = client.run({ 'model': 'flux-dev', 'prompt': 'a beautiful sunset over the ocean', }) # Check if the result contains an error if 'error' in result: error = result['error'] if error.get('code') == 'NO_CREDITS': print('You need to purchase more credits to continue.') else: print(f'Error: {error.get("code")}') else: # Process successful response print(f'Generated image: {result.get("data")}') except Exception as e: # Handle unexpected errors (network issues, etc.) print(f'Unexpected error: {str(e)}')

If you encounter persistent errors or need additional help understanding an error message, please contact our support team at [email protected].