Image API
Generate images using AI with OpenAI and Replicate formats
The Image API supports two formats for AI image generation:
- OpenAI Format - Synchronous generation (compatible with OpenAI SDK)
- Replicate Format - Asynchronous predictions (for longer-running models)
Authentication: API Key or OAuth token
Required Scopes (OAuth): ai:images
Quick Comparison
OpenAI Format (Generations)
Endpoint
POST /api/v1/images/generations
Quick Start
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.GATEWAY_API_KEY,
baseURL: 'https://hypery.ai/api/v1'
})
const response = await client.images.generate({
model: 'dall-e-3',
prompt: 'A serene landscape with mountains',
n: 1,
size: '1024x1024'
})
console.log(response.data[0].url)Request Format
{
"model": "dall-e-3",
"prompt": "A beautiful sunset over the ocean",
"n": 1,
"size": "1024x1024",
"quality": "standard",
"style": "vivid"
}Request Parameters
Response Format
{
"created": 1699564800,
"data": [
{
"url": "https://hypery.ai/api/v1/images/serve/abc123",
"revised_prompt": "A beautiful sunset over the ocean with vibrant colors"
}
]
}Replicate Format (Predictions)
For slower models or when you need polling support, use the Predictions.
See complete Predictions documentation →
Quick Example
// 1. Create prediction
const prediction = await fetch('https://hypery.ai/api/v1/predictions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'black-forest-labs/flux-schnell',
provider: 'replicate',
input: {
prompt: 'A futuristic city at night',
width: 1024,
height: 1024
}
})
}).then(r => r.json())
// 2. Poll for completion
while (prediction.status === 'starting' || prediction.status === 'processing') {
await new Promise(resolve => setTimeout(resolve, 1000))
prediction = await fetch(
`https://hypery.ai/api/v1/predictions/${prediction.id}`,
{ headers: { 'Authorization': `Bearer ${apiKey}` } }
).then(r => r.json())
}
// 3. Get result
if (prediction.status === 'succeeded') {
console.log('Image URL:', prediction.output[0])
}Available Models
Fast Models (OpenAI Format)
Advanced Models (Replicate Format)
Code Examples
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.GATEWAY_API_KEY,
baseURL: 'https://hypery.ai/api/v1'
})
// Generate image
const image = await client.images.generate({
model: 'dall-e-3',
prompt: 'A programmer drinking coffee, digital art',
size: '1024x1024',
quality: 'hd'
})
console.log(image.data[0].url)from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://hypery.ai/api/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A programmer drinking coffee, digital art",
size="1024x1024",
quality="hd"
)
print(response.data[0].url)curl https://hypery.ai/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "A programmer drinking coffee, digital art",
"size": "1024x1024",
"quality": "hd"
}'Error Responses
Insufficient Credits
{
"error": {
"message": "Insufficient credits for image generation",
"type": "insufficient_quota",
"code": "insufficient_credits"
}
}Status Code: 429
Invalid Model
{
"error": {
"message": "Model not found or not supported for image generation",
"type": "invalid_request_error",
"code": "model_not_found"
}
}Status Code: 400
Best Practices
Choose the Right Format
- Use OpenAI format for fast models (DALL-E)
- Use Replicate format for slower, higher-quality models (Flux, SD3)
Handle Errors
try {
const image = await client.images.generate({
model: 'dall-e-3',
prompt: 'A sunset'
})
} catch (error) {
if (error.status === 429) {
console.error('Out of credits')
} else if (error.status === 400) {
console.error('Invalid request:', error.message)
}
}Estimate Costs
Check model pricing before generation:
// List image models with pricing
const models = await fetch(
'https://hypery.ai/api/v1/models?type=image'
).then(r => r.json())
models.data.forEach(model => {
console.log(`${model.id}: $${model.pricing?.imageCost || 'varies'}`)
})