API Code Examples

cURL

curl -X POST \
  https://ai-image.justpump.pro \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "A beautiful sunset over a mountain lake"
  }' \
  --output image.png

JavaScript

async function generateImage(prompt) {
  try {
    const response = await fetch('https://ai-image.justpump.pro', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ prompt })
    });
    
    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.message || 'Failed to generate image');
    }
    
    // Response is a PNG image
    const imageBlob = await response.blob();
    return imageBlob;
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}

// Example usage with HTML img element
async function displayGeneratedImage(prompt) {
  try {
    const imageBlob = await generateImage(prompt);
    const imageUrl = URL.createObjectURL(imageBlob);
    const imgElement = document.createElement('img');
    imgElement.src = imageUrl;
    document.body.appendChild(imgElement);
  } catch (error) {
    console.error('Failed to generate image:', error);
  }
}

Python

import requests

def generate_image(prompt):
    url = 'https://ai-image.justpump.pro'
    
    try:
        response = requests.post(
            url,
            headers={'Content-Type': 'application/json'},
            json={'prompt': prompt}
        )
        response.raise_for_status()
        
        # Save the image
        with open('generated_image.png', 'wb') as f:
            f.write(response.content)
            
        return 'generated_image.png'
    except requests.exceptions.RequestException as e:
        print(f'Error generating image: {e}')
        raise

# Example usage
try:
    image_path = generate_image('A beautiful sunset over a mountain lake')
    print(f'Image saved to: {image_path}')
except Exception as e:
    print(f'Failed: {e}')

Last updated