Skip to main content

Flux Schnell Image Generation API

OpenAI-compatible API for generating images using the Flux Schnell diffusion model.

API Endpoint

https://your_endpoint/v1/images/generations

Authentication

Set your access token:

export ACCESS_TOKEN="your_token_here"

Generate Images

Method 1: Using curl + jq + base64

Dependencies:

# macOS
brew install jq

# Linux
sudo apt-get install jq

Generate and save image:

curl -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{"prompt": "a majestic lion in the savanna at sunset", "n": 1, "size": "1024x1024"}' \
"https://your_endpoint/v1/images/generations" \
| jq -r '.data[0].b64_json' \
| base64 -d > image.png

Method 2: Using OpenAI Python Client

Dependencies:

pip install openai pillow

Generate and save image:

from openai import OpenAI
import base64
from PIL import Image
from io import BytesIO
import os

client = OpenAI(
api_key=os.environ.get('ACCESS_TOKEN'),
base_url="https://your_endpoint"
)

# Generate image
response = client.images.generate(
prompt="a majestic lion in the savanna at sunset"
)

# Decode and save
image_data = base64.b64decode(response.data[0].b64_json)
image = Image.open(BytesIO(image_data))
image.save("image.png")

Request Parameters

ParameterTypeDefaultDescription
promptstringrequiredText description of the image
modelstring"flux-schnell"Model to use
ninteger1Number of images to generate
sizestring"1024x1024"Image dimensions
response_formatstring"b64_json"Response format