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/generateGenerate a single image from a text prompt.
POST
/v1/image/generate/batchGenerate multiple images in a single request.
POST
/v1/image/variationCreate 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
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Required | Main text description of the image you want to generate. |
negative_prompt | string | Optional | Optional prompt describing what to avoid (e.g. 'blurry, text'). |
width | number | Optional | Output image width in pixels (default 1024). |
height | number | Optional | Output image height in pixels (default 1024). |
steps | number | Optional | Number of diffusion steps (higher = more detail, slower). |
seed | number | Optional | Random seed for reproducible generations. |
webhook_url | string | Optional | Optional 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_KEYImportant: Never expose your secret API key in public client‑side code. Use environment variables and call the API from a secure backend whenever possible.