Integration guide
Generate images using gpt-image-2 (Imagen 2) through Virouter's OpenAI-compatible endpoint. Use the OpenAI SDK or direct HTTP calls with your Virouter API key.
Endpoint
https://api.virouter.com/v1/images/generationsModel ID
gpt-image-2Supported sizes
1024x1024, 1024x1536, 1536x1024Quality levels
low, medium, highUse the OpenAI SDK's images.generate() method with Virouter baseURL.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.VIROUTER_API_KEY,
baseURL: "https://api.virouter.com/v1",
});
const response = await client.images.generate({
model: "gpt-image-2",
prompt: "A cat sitting on a beach at sunset",
n: 1,
size: "1024x1024",
quality: "low", // low, medium, or high
});
console.log(response.data[0].url);
// or save base64: response.data[0].b64_jsonThe Python SDK uses the same images.generate() interface.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["VIROUTER_API_KEY"],
base_url="https://api.virouter.com/v1",
)
response = client.images.generate(
model="gpt-image-2",
prompt="A minimalist tech logo with circuit paths",
n=1,
size="1024x1024",
quality="medium",
)
print(response.data[0].url)
# or decode base64: response.data[0].b64_jsonDirect HTTP POST for testing or server-side scripts.
curl https://api.virouter.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VIROUTER_API_KEY" \
-d '{
"model": "gpt-image-2",
"prompt": "A red circle on white background",
"n": 1,
"size": "1024x1024",
"quality": "low"
}'By default, Virouter returns base64-encoded images in the b64_json field. Decode and save as PNG.
{
"created": 1781055119,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAAA...",
"revised_prompt": "A simple red circle centered on a plain white background..."
}
],
"model": "gpt-image-2",
"usage": {
"input_tokens": 24,
"output_tokens": 196,
"total_tokens": 220
}
}| Quality | Generation time | Use case |
|---|---|---|
| low | ~30 seconds | Prototyping, previews, low-cost |
| medium | ~60-90 seconds | Balanced quality and speed |
| high | ~90-120 seconds | Production, high-fidelity outputs |
Set your HTTP client timeout to at least 150 seconds to avoid premature disconnects during image generation.
Check that the model name is exactly gpt-image-2 and the path is /v1/images/generations.
Image generation takes 30-90s depending on quality. Use quality=low for faster results (~30s).
Image generation costs more than text. Ensure your wallet has sufficient Billing USD Quota.
The gpt-image-2 channel may be temporarily unavailable. Contact support or retry later.