Skip to Content
GuidesImage Quality Optimization

Image Quality Optimization

Learn advanced techniques to generate higher quality images with xRouter.

Quality Control Parameters

Negative Prompts

Negative prompts specify what you don’t want in your image. This is one of the most effective ways to improve quality.

Basic Usage:

{ prompt: "a beautiful portrait of a woman, professional photography", negativePrompt: "blurry, distorted, low quality, bad anatomy, ugly" }

Common Negative Prompts Library:

For Photorealistic Images:

blurry, out of focus, low quality, ugly, distorted, deformed, bad anatomy, disfigured, poorly drawn, mutation, mutated, extra limb, poorly drawn hands, missing limb, floating limbs, disconnected limbs, malformed hands, oversaturated

For Portraits:

blurry, low quality, bad anatomy, bad proportions, bad hands, bad face, deformed, disfigured, mutation, extra fingers, extra limbs, asymmetric eyes, crossed eyes, bad teeth, asymmetric, distorted face

For Landscapes:

blurry, low quality, oversaturated, unrealistic colors, smudged, watermark, text, signature, low resolution, pixelated, noisy

For Artistic/Anime:

blurry, low quality, bad anatomy, poorly drawn, mutation, deformed, ugly, inconsistent style, western cartoon, realistic, 3d

Example with Negative Prompt:

import { wrapFetchWithPayment } from 'x402-fetch'; import { privateKeyToAccount } from 'viem/accounts'; const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); const fetchWithPayment = wrapFetchWithPayment(fetch, account); async function generateHighQuality() { const response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'a beautiful portrait of a woman, professional photography, studio lighting', negativePrompt: 'blurry, distorted, low quality, bad anatomy, ugly, deformed', model: 'sdxl-realvis-v4', width: 768, height: 1024, }), }); const data = await response.json(); console.log('High-quality portrait:', data.images[0].url); }

Inference Steps

The steps parameter controls how many refinement iterations the model performs. Higher steps generally produce better quality.

Important: Not all models support the steps parameter. Check the model’s supportsSteps field.

Step Ranges:

  • Low (4-8): Fast generation, good for testing
  • Medium (10-20): Balanced quality and speed
  • High (25-50): Maximum quality, slower generation

Example:

{ prompt: "a detailed fantasy castle on a cliff, dramatic lighting", model: "flux-schnell", width: 1024, height: 1024, steps: 20 // Higher quality }

Comparison:

// Quick test { steps: 4 } // Fast, good quality // Balanced { steps: 10 } // Better quality, moderate speed // Maximum quality { steps: 50 } // Best quality, slowest

Guidance Scale (CFG)

The guidance parameter (Classifier-Free Guidance) controls how strictly the model follows your prompt.

Guidance Ranges:

  • Low (1-5): More creative freedom, may deviate from prompt
  • Medium (6-9): Balanced adherence and creativity
  • High (10-20): Strict prompt following, less variation
  • Very High (20-30): Maximum prompt adherence, may reduce naturalness

Example:

{ prompt: "a red sports car in front of modern architecture", model: "flux-schnell", width: 1024, height: 1024, guidance: 7.5 // Strong prompt adherence }

When to Use Different Guidance:

Low Guidance (3-5): Artistic freedom

{ prompt: "abstract art, colorful patterns", guidance: 4 // Let the model be creative }

Medium Guidance (7-9): Balanced (recommended)

{ prompt: "a mountain landscape at sunset", guidance: 7.5 // Good balance }

High Guidance (12-15): Specific requirements

{ prompt: "a product photo of red sneakers on white background", guidance: 12 // Follow exactly }

Seeds for Reproducibility

The seed parameter enables reproducible results. Using the same seed with the same parameters produces the same image.

Use Cases:

  • Testing prompt variations
  • Iterative refinement
  • Consistent character generation
  • A/B testing

Example - Reproducible Generation:

const seed = 42; const response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'a steampunk robot, brass and copper, intricate details', model: 'flux-schnell', width: 1024, height: 1024, seed: seed, // Same seed = same image }), });

Example - Testing Prompt Variations:

async function testPromptVariations() { const baseSeed = 12345; const baseParams = { model: 'sdxl-realvis-v4', width: 1024, height: 1024, seed: baseSeed, }; // Test different prompts with same seed const prompts = [ 'a cat sitting on a chair', 'a cat sitting on a chair, professional photography', 'a cat sitting on a chair, professional photography, studio lighting', ]; for (const prompt of prompts) { const response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...baseParams, prompt }), }); const data = await response.json(); console.log(`Prompt: ${prompt}`); console.log(`Image: ${data.images[0].url}\n`); } }

Prompt Engineering

Anatomy of a Good Prompt

A high-quality prompt follows this structure:

[Subject] + [Style/Medium] + [Quality Keywords] + [Details/Modifiers]

Examples:

Basic Prompt:

"a dog"

Improved Prompt:

"a golden retriever puppy, professional photography, highly detailed, soft lighting"

Advanced Prompt:

"a golden retriever puppy sitting in a meadow of wildflowers, professional nature photography, golden hour lighting, shallow depth of field, highly detailed fur texture, 8k resolution, award-winning composition"

Prompt Templates

Photorealistic Portrait:

"portrait of [subject], [expression], professional photography, studio lighting, [background], highly detailed, sharp focus, 8k resolution"

Example:

{ prompt: "portrait of a young woman, slight smile, professional photography, studio lighting, neutral gray background, highly detailed, sharp focus, 8k resolution", negativePrompt: "blurry, low quality, bad anatomy, distorted face" }

Landscape Photography:

"[location/scene], [time of day/lighting], [weather conditions], professional landscape photography, wide angle, highly detailed, [mood], 8k resolution"

Example:

{ prompt: "mountain lake at sunrise, golden hour lighting, misty atmosphere, professional landscape photography, wide angle, highly detailed, serene and peaceful, 8k resolution", negativePrompt: "blurry, oversaturated, unrealistic colors, low quality" }

Product Photography:

"product photo of [item], [background], professional product photography, studio lighting, highly detailed, sharp focus, commercial quality"

Example:

{ prompt: "product photo of modern wireless headphones, white background, professional product photography, studio lighting, highly detailed, sharp focus, commercial quality", negativePrompt: "blurry, shadows, reflections, low quality" }

Fantasy/Concept Art:

"[scene/subject], [art style], highly detailed, [lighting], [mood/atmosphere], concept art, digital painting, trending on artstation"

Example:

{ prompt: "ancient wizard's tower on a floating island, fantasy art style, highly detailed, dramatic sunset lighting, magical atmosphere, concept art, digital painting, trending on artstation", negativePrompt: "blurry, low quality, photo, realistic, modern" }

Anime/Manga:

"anime [character description], [pose/action], [setting], [style keywords], highly detailed, vibrant colors, [specific anime style if desired]"

Example:

{ prompt: "anime girl with long blue hair, school uniform, cherry blossom background, modern anime style, highly detailed, vibrant colors, soft lighting", negativePrompt: "realistic, 3d, western cartoon, low quality, blurry", model: "sd15-counterfeit-v3" }

Advanced Prompt Techniques

Quality Keywords: Add these to improve output quality:

highly detailed, sharp focus, professional, 8k resolution, award-winning, masterpiece, best quality, ultra detailed, photorealistic, crisp, clean

Style Keywords: Specify artistic style:

// Photography professional photography, studio lighting, natural lighting, golden hour, bokeh, shallow depth of field, portrait photography, landscape photography // Digital Art digital painting, concept art, matte painting, digital illustration, trending on artstation, CGI, 3D render // Traditional Art oil painting, watercolor, pencil sketch, ink drawing, acrylic painting // Specific Artists/Styles in the style of [artist name], [art movement] style

Lighting Keywords: Control lighting:

studio lighting, natural lighting, golden hour, dramatic lighting, soft lighting, rim lighting, backlighting, volumetric lighting, cinematic lighting, moody lighting

Camera Keywords (for photorealistic images):

wide angle, telephoto, macro, 50mm lens, 85mm portrait lens, shallow depth of field, bokeh, f/1.4, f/2.8

Model-Specific Optimization

FLUX Models

Best Practices:

  • Use 10-20 steps for balanced quality
  • Guidance 7-9 works well
  • Excellent for photorealism
  • Negative prompts highly effective

Example:

{ prompt: "professional portrait, highly detailed, studio lighting", negativePrompt: "blurry, distorted, low quality", model: "flux-dev", width: 1024, height: 1024, steps: 20, guidance: 8 }

SDXL Models

Best Practices:

  • 20-40 steps recommended
  • Guidance 7-10 works well
  • Versatile across styles
  • Good for artistic and realistic

Example:

{ prompt: "fantasy landscape, concept art, highly detailed", negativePrompt: "blurry, low quality, photo", model: "sdxl-dreamshaper", width: 1024, height: 1024, steps: 30, guidance: 9 }

SD 1.5 Models

Best Practices:

  • 8-20 steps usually sufficient
  • Model-specific keywords important
  • Excellent for anime/illustration
  • Lower guidance (5-8) often better

Example:

{ prompt: "anime girl, vibrant colors, detailed", negativePrompt: "realistic, 3d, blurry", model: "sd15-counterfeit-v3", width: 768, height: 1024, steps: 12, guidance: 7 }

Premium Models

Best Practices:

  • No steps parameter needed (not supported)
  • Focus on prompt quality
  • Negative prompts still work
  • Higher base quality

Example:

{ prompt: "professional product photography, highly detailed, commercial quality", negativePrompt: "blurry, low quality, amateur", model: "ultra-imagen", width: 1024, height: 1024 // No steps parameter for premium models }

Resolution and Quality

Resolution Selection Strategy

Testing Phase: 512×512

  • Fast generation
  • Quick iteration
  • Low cost

Development Phase: 1024×1024

  • Good quality
  • Balanced cost
  • Suitable for most uses

Production Phase: 1536×1536 or 2048×2048

  • High quality
  • Print-ready
  • Maximum detail

Example Workflow:

async function iterativeQuality(prompt: string) { const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); const fetchWithPayment = wrapFetchWithPayment(fetch, account); // Phase 1: Quick test at 512×512 console.log('Testing at 512×512...'); let response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt, width: 512, height: 512, seed: 42, }), }); let data = await response.json(); console.log('Test image:', data.images[0].url); // Phase 2: Refine at 1024×1024 console.log('Generating at 1024×1024...'); response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt, width: 1024, height: 1024, seed: 42, steps: 15, guidance: 8, }), }); data = await response.json(); console.log('Final image:', data.images[0].url); }

Complete Quality Optimization Workflow

Here’s a complete example using all quality techniques:

import { wrapFetchWithPayment } from 'x402-fetch'; import { privateKeyToAccount } from 'viem/accounts'; const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); const fetchWithPayment = wrapFetchWithPayment(fetch, account); async function generateOptimizedImage() { const response = await fetchWithPayment('https://api.x-router.ai/v1/images/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ // Detailed, specific prompt with quality keywords prompt: ` professional portrait of a young woman, slight smile, elegant business attire, studio lighting, neutral gray background, highly detailed, sharp focus, professional photography, 8k resolution, award-winning portrait `.trim().replace(/\s+/g, ' '), // Comprehensive negative prompt negativePrompt: ` blurry, out of focus, low quality, ugly, distorted, deformed, bad anatomy, bad proportions, disfigured, poorly drawn, mutation, extra limbs, bad hands, bad face, oversaturated `.trim().replace(/\s+/g, ' '), // Model selection model: 'sdxl-realvis-v4', // Quality resolution width: 1024, height: 1024, // Quality parameters steps: 25, guidance: 8.5, seed: 42, }), }); const data = await response.json(); console.log('High-quality image generated'); console.log('URL:', data.images[0].url); return data; }

Common Quality Issues and Solutions

Issue: Blurry Images

Solutions:

  • Increase resolution (1024×1024 → 2048×2048)
  • Add more steps (if model supports)
  • Add quality keywords: “sharp focus”, “highly detailed”, “8k”
  • Use negative prompt: “blurry, out of focus, low quality”
  • Try a different model

Issue: Colors Look Wrong

Solutions:

  • Add lighting keywords: “natural lighting”, “studio lighting”
  • Specify color: “vibrant colors”, “muted colors”, “realistic colors”
  • Use negative prompt: “oversaturated”, “desaturated”, “unrealistic colors”
  • Adjust guidance scale

Issue: Doesn’t Match Prompt

Solutions:

  • Increase guidance scale (8-12)
  • Make prompt more specific and detailed
  • Use negative prompts for unwanted elements
  • Add emphasis to key terms
  • Try different model

Issue: Anatomical Errors (hands, faces)

Solutions:

  • Use negative prompt: “bad anatomy, bad hands, bad face, deformed”
  • Choose models known for anatomy: sdxl-realvis-v4, flux-dev
  • Increase steps for better refinement
  • Add quality keywords

Issue: Style Inconsistency

Solutions:

  • Use seed for reproducibility
  • Be very specific about style in prompt
  • Use model specialized for that style
  • Add style references: “in the style of…”, “art movement”

Quality Checklist

Before generating your final image:

  • Prompt is specific and detailed
  • Quality keywords included (“highly detailed”, “professional”, etc.)
  • Negative prompt covers common issues
  • Appropriate model selected for your style
  • Resolution appropriate for use case
  • Steps parameter set (if model supports and quality matters)
  • Guidance in optimal range (7-9 for most cases)
  • Seed set if reproducibility needed
Last updated on