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 Type | Description |
---|---|
PROVIDER_ERROR | Errors related to third-party model providers |
INTERNAL_SERVER_ERROR | Unexpected internal system errors |
BAD_REQUEST_ERROR | Errors due to invalid input or parameters |
AUTHENTICATION_ERROR | Errors with API keys or authentication |
BILLING_ERROR | Errors related to credits or payment issues |
AVAILABILITY_ERROR | Errors when services or models are unavailable |
Error codes
Authentication errors
Code | Description |
---|---|
INVALID_API_KEY | The API key provided is not valid |
MISSING_API_KEY | No 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.
Code | Description |
---|---|
PROVIDER_ERROR | Generic error when interacting with a provider |
PROVIDER_HTTP_ERROR | HTTP error when communicating with a provider |
PROVIDER_JOB_ERROR | Error during job execution by a provider |
PROVIDER_TIMEOUT | Provider took too long to respond |
PROVIDER_NOT_FOUND | The requested provider was not found |
NO_PROVIDERS_WORKING | No providers are available to handle the request |
Billing errors
Code | Description |
---|---|
NO_CREDITS | User has insufficient credits for the requested operation |
Request errors
Code | Description |
---|---|
INVALID_ARGUMENTS | The request contains invalid arguments |
UNKNOWN_MODEL | The requested model does not exist or is not supported |
System errors
Code | Description |
---|---|
UNKNOWN_ERROR | Generic error when the cause is not known |
INTERNAL_SERVER_ERROR | Internal 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].