OpenPixels client reference
This document provides a detailed reference for the OpenPixels client API, including all available arguments and their requirements.
Client initialization
The OpenPixels client can be initialized in both Python and TypeScript/JavaScript.
You should initialize the client once and reuse it across requests rather than creating a new client for each request. This improves performance and resource utilization.
Python
from openpixels import OpenPixels
client = OpenPixels(api_key="your-api-key")
JavaScript/TypeScript
import { OpenPixels } from 'openpixels';
const client = new OpenPixels({ apiKey: 'your-api-key' });
Constructor Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
api_key | str | Yes | - | Your OpenPixels API key for authentication |
base_url | str | No | "https://worker.openpixels.ai" | The base URL for the OpenPixels API |
Making Requests
The client supports different models with specific parameters for each.
The OpenPixels client provides the following main method:
run(payload)
: Submits a job and waits for completion, returning the final result.
Models and Parameters
Available Models
At launch, OpenPixels supports the following models:
flux-dev
flux-schnell
flux-pro-1.1
Model Parameters
Each model accepts a set of parameters in the payload. Here’s a breakdown of all available parameters:
Common Parameters for Image Generation
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
model | string | Yes | - | The model to use (e.g., "flux-dev" , "flux-schnell" ) |
prompt | string | Yes | - | The text prompt describing the image to generate |
width | int | No | 1024 | Width of the output image in pixels |
height | int | No | 1024 | Height of the output image in pixels |
Example Usage
Python Example
# Initialize the client once at the start of your application
from openpixels import OpenPixels
client = OpenPixels(api_key="your-api-key")
# Generate an image
result = client.run({
"model": "flux-dev",
"prompt": "A serene landscape with mountains and a lake",
"width": 768,
"height": 512,
})
print("Image URL:", result.get("data", {}).get("url"))
JavaScript/TypeScript Example
import { OpenPixels } from 'openpixels';
// Initialize the client once when your application starts
const client = new OpenPixels({ apiKey: 'your-api-key' });
async function generateImage() {
const result = await client.run({
model: 'flux-dev',
prompt: 'A serene landscape with mountains and a lake',
width: 768,
height: 512,
});
console.log("Image URL:", result?.data?.url);
}
generateImage();
Response Structure
The responses from the API include the following fields:
Final Result
{
"type": "result",
"status": "complete",
"data": {
"url": "https://example.com/image.png" // or base64 data
}
}
Error Response
{
"type": "result",
"status": "failed",
"error": {
"type": "error_type",
"code": "error_code",
"message": "Error message",
"params": { /* ... */ }
}
}
Client Lifecycle Best Practices
- Create the client once: Initialize the client when your application starts, not for each request.
- Reuse across requests: Use the same client instance for multiple image generation requests.
Error Handling
For detailed information on error handling, please refer to the Error Handling documentation.
Thread Safety
For information about thread safety and concurrency, please refer to the Thread Safety documentation.
Provider Information
For details about the underlying providers and routing, please see the Providers documentation.