Image Generation
Our image generation capabilities provide state-of-the-art models for creating high-quality images from text descriptions. We offer both standard and fast generation options to suit different use cases.
Available Models
Model | Speed | Quality | Resolution | Use Case |
---|---|---|---|---|
SDXL Base | Standard | Best | 1024x1024 | Production quality |
SDXL Lightning | 2x Faster | Great | 1024x1024 | Rapid prototyping |
Model Selection Guide
-
SDXL Base (Standard)
- Provider: Stability AI
- Steps: 20 (configurable)
- Best for: High-quality production images
- Guidance scale: 7.5 (configurable)
-
SDXL Lightning (Fast)
- Provider: ByteDance
- Steps: 10 (optimized)
- Best for: Quick iterations, prototyping
- Guidance scale: 7.5 (optimized)
Basic Usage
Native SDK
import { Neuredge } from '@neuredge/sdk';
const neuredge = new Neuredge({
apiKey: 'your-api-key'
});
const image = await neuredge.generateImage({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: 'A serene lake at sunset with mountains in the background',
width: 1024,
height: 1024,
num_steps: 20,
guidance: 7.5
});
REST API
const response = await fetch('https://api.neuredge.dev/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: 'A cyberpunk cityscape at night with neon signs',
width: 1024,
height: 1024,
num_steps: 20
})
});
const image = await response.blob();
Real-World Applications & Examples
1. E-commerce Product Visualization
async function generateProductVariant(product, color) {
const response = await neuredge.generateImage({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: \`${product.name} in ${color} color, professional product photography,
white background, high resolution, detailed texture\`,
width: 1024,
height: 1024,
num_steps: 20,
guidance: 7.5
});
return response;
}
Use Cases:
- Product mockups
- Color variations
- Marketing materials
- Catalog imagery
- Design prototypes
2. Real Estate Visualization
async function generateInteriorDesign(specs) {
const response = await neuredge.generateImage({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: \`${specs.style} style ${specs.room} with ${specs.features.join(', ')},
interior design, photorealistic, natural lighting\`,
width: 1024,
height: 1024,
num_steps: 20,
guidance: 8.0 // Slightly higher for more photorealism
});
return response;
}
Use Cases:
- Interior design concepts
- Property staging
- Renovation previews
- Architectural visualization
- Design alternatives
3. Marketing Content Creation
async function generateSocialMedia(campaign) {
// For quick iterations during brainstorming
const draft = await neuredge.generateImage({
model: '@cf/bytedance/stable-diffusion-xl-lightning',
prompt: campaign.concept,
width: 1024,
height: 1024,
num_steps: 10
});
// For final production version
const final = await neuredge.generateImage({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: campaign.finalPrompt,
width: 1024,
height: 1024,
num_steps: 20,
guidance: 7.5
});
return { draft, final };
}
Use Cases:
- Social media content
- Ad creatives
- Marketing materials
- Campaign assets
- Brand imagery
Integration Examples
Express.js Image Generation API
import express from 'express';
import { Neuredge } from '@neuredge/sdk';
const app = express();
app.use(express.json());
const neuredge = new Neuredge({
apiKey: process.env.NEUREDGE_API_KEY
});
app.post('/generate-image', async (req, res) => {
try {
const { prompt, style = 'standard' } = req.body;
const model = style === 'fast'
? '@cf/bytedance/stable-diffusion-xl-lightning'
: '@cf/stabilityai/stable-diffusion-xl-base-1.0';
const response = await neuredge.generateImage({
model,
prompt,
width: 1024,
height: 1024,
num_steps: style === 'fast' ? 10 : 20
});
// Convert to Base64 for JSON response
const base64 = await response.arrayBuffer()
.then(buffer => Buffer.from(buffer).toString('base64'));
res.json({
image: \`data:image/png;base64,\${base64}\`,
model
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Next.js Image Generation
// pages/api/generate.js
import { Neuredge } from '@neuredge/sdk';
const neuredge = new Neuredge({
apiKey: process.env.NEUREDGE_API_KEY
});
export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' });
}
try {
const { prompt, style = 'standard' } = req.body;
const response = await neuredge.generateImage({
model: style === 'fast'
? '@cf/bytedance/stable-diffusion-xl-lightning'
: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt,
width: 1024,
height: 1024,
num_steps: style === 'fast' ? 10 : 20
});
// Set proper content type for image response
res.setHeader('Content-Type', 'image/png');
res.send(await response.arrayBuffer());
} catch (error) {
res.status(500).json({ error: error.message });
}
}
Best Practices
-
Prompt Engineering
- Be specific and detailed
- Include desired style
- Specify important details
- Use descriptive adjectives
-
Model Selection
- Use Lightning for drafts
- SDXL Base for final images
- Consider use case requirements
- Balance speed vs quality
-
Performance Optimization
- Cache generated images
- Use appropriate dimensions
- Optimize step count
- Implement retry logic
-
Error Handling
- Handle failed generations
- Provide fallback options
- Monitor error rates
- Log issues for analysis
Quotas and Limits
Plan | Monthly Generation Quota |
---|---|
Free Tier | 50 images |
$29 Plan | 500 images |
$49 Plan | 750 images |
Resolution Limits
- Maximum: 1024x1024 pixels
- Minimum: 512x512 pixels
- Aspect ratio: 1:1 (square)
When to Use Each Model
SDXL Base (Standard)
✅ Ideal For:
- Production content
- Marketing materials
- Client deliverables
- Brand assets
- Professional use
SDXL Lightning (Fast)
✅ Ideal For:
- Rapid prototyping
- Design iterations
- Concept exploration
- Quick drafts
- Testing ideas
Getting Started
- Install the SDK:
npm install @neuredge/sdk
# or
pip install neuredge-sdk
- Initialize the client:
import { Neuredge } from '@neuredge/sdk';
const neuredge = new Neuredge({
apiKey: 'your-api-key'
});
Learn more: