Image Models Guide
This guide explains how to call VLX FLUX image generation models through the OpenAI-compatible protocol and the Midjourney-Proxy protocol.
Prerequisites
- Register on VLX FLUX and create an API key
- Confirm the API base URL
https://api.vlxflux.io - Install the required runtime locally
OpenAI-Compatible API
Through the standard /v1/images/generations endpoint, you can call DALL-E, proxied Midjourney models, and other image generation capabilities.
Install Dependencies
bash
pip install openai requestsPython Usage
Basic Request
python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxx",
base_url="https://api.vlxflux.io/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A cute cat drinking coffee in cyberpunk style",
size="1024x1024",
quality="standard",
n=1,
)
image_url = response.data[0].url
print("Image URL:", image_url)Return Base64
python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxx",
base_url="https://api.vlxflux.io/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A cute cat drinking coffee in cyberpunk style",
size="1024x1024",
response_format="b64_json",
n=1,
)
image_b64 = response.data[0].b64_json
print(image_b64[:50] + "...")Save Image
python
import base64
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxx",
base_url="https://api.vlxflux.io/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A cute cat drinking coffee in cyberpunk style",
size="1024x1024",
response_format="b64_json",
n=1,
)
image_data = response.data[0].b64_json
with open("cat.png", "wb") as f:
f.write(base64.b64decode(image_data))
print("Saved as cat.png")curl Usage
bash
curl https://api.vlxflux.io/v1/images/generations -H "Content-Type: application/json" -H "Authorization: Bearer sk-xxxxxxxx" -d '{
"model": "dall-e-3",
"prompt": "a cute cat drinking coffee, cyberpunk style",
"size": "1024x1024",
"n": 1
}'Supported Models
| Model | Type | Description |
|---|---|---|
dall-e-2 | Image | Official DALL-E 2 |
dall-e-3 | Image | Better detail quality |
midjourney | Image | Proxied Midjourney |
stable-diffusion | Image | Stable Diffusion model |
Extra Prompt Parameters
python
response = client.images.generate(
model="midjourney",
prompt="a cute cat drinking coffee --ar 16:9 --niji 6",
n=1,
)Midjourney-Proxy Protocol
If your application already uses the midjourney-proxy format, you can switch the Base URL and API secret directly.
Authentication
text
mj-api-secret: sk-xxxxxxxxPython Usage
Submit Imagine Task
python
import requests
url = "https://api.vlxflux.io/mj/submit/imagine"
headers = {
"mj-api-secret": "sk-xxxxxxxx",
"Content-Type": "application/json"
}
data = {
"prompt": "a futuristic city, neon lights --ar 16:9"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())Fetch Task Status
python
import requests
task_id = "123456789"
url = f"https://api.vlxflux.io/mj/task/{task_id}/fetch"
headers = {
"mj-api-secret": "sk-xxxxxxxx"
}
response = requests.get(url, headers=headers)
print(response.json())Common Errors
| Status | Cause | Solution |
|---|---|---|
400 | Invalid parameters | Check prompt, size, and related fields |
401 | Authentication failed | Check API key or Bearer prefix |
402 | Insufficient balance | Recharge and retry |
403 | No access to model | Check model permission |
500 | Upstream overload | Retry later or switch model |