Skip to Content
ReferenceClient Reference

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

ParameterTypeRequiredDefaultDescription
api_keystrYes-Your OpenPixels API key for authentication
base_urlstrNo"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

ParameterTypeRequiredDefaultDescription
modelstringYes-The model to use (e.g., "flux-dev", "flux-schnell")
promptstringYes-The text prompt describing the image to generate
widthintNo1024Width of the output image in pixels
heightintNo1024Height 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

  1. Create the client once: Initialize the client when your application starts, not for each request.
  2. 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.