our logo
API Documentation

Image Generation API

Programmatically generate high‑quality images from text prompts. Use our Image Generation API to create marketing visuals, product shots, avatars, and more with a single HTTP request.

Image Generation API Reference

Use these endpoints to turn text prompts into production‑ready images. Choose your preferred language below and copy the ready‑to‑run examples.

Quick Start Examples

JavaScript / Node.js
// Install axios: npm install axios
import axios from "axios";

async function generateImage() {
  try {
    const response = await axios.post(
      "https://api.photocraft.com/v1/image/generate",
      {
        prompt: "cinematic portrait of a cyberpunk character, neon lights",
        negative_prompt: "blurry, low quality",
        width: 1024,
        height: 1024,
      },
      {
        headers: {
          Authorization: "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
        },
      }
    );

    console.log("Image URL:", response.data.result_url);
  } catch (error: any) {
    console.error("Generation failed:", error?.response?.data ?? error);
  }
}

generateImage();

Available Endpoints

POST/v1/image/generate

Generate a single image from a text prompt.

POST/v1/image/generate/batch

Generate multiple images in a single request.

POST/v1/image/variation

Create variations from an existing image and prompt.

Response Format

{
  "success": true,
  "result_url": "https://api.photocraft.com/results/img_123.jpg",
  "job_id": "job_abc123",
  "processing_time": "3.1s",
  "credits_used": 1
}

Request Parameters

ParameterTypeRequiredDescription
promptstringRequiredMain text description of the image you want to generate.
negative_promptstringOptionalOptional prompt describing what to avoid (e.g. 'blurry, text').
widthnumberOptionalOutput image width in pixels (default 1024).
heightnumberOptionalOutput image height in pixels (default 1024).
stepsnumberOptionalNumber of diffusion steps (higher = more detail, slower).
seednumberOptionalRandom seed for reproducible generations.
webhook_urlstringOptionalOptional webhook URL for async processing callbacks.

Authentication

All Image Generation API requests require authentication using your API key. Include it in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Important: Never expose your secret API key in public client‑side code. Use environment variables and call the API from a secure backend whenever possible.