Skip to main content

Image API

Generate, edit, and upscale images. 39 models. Cost estimation before execution.

POST /v1/generations/image

Generate an image from a text prompt. Returns the image URL and exact cost.

Request body

FieldTypeRequiredDescription
modelstringYesModel key (e.g. "gpt-image-1.5-t2i", "z-image-turbo"). See Model Catalog.
inputobjectYesThe fields below go inside input.
input.promptstringYesText description of the image to generate.
input.negative_promptstringNoElements to exclude from the image.
input.aspect_ratiostringNoAspect ratio: "1:1", "16:9", "9:16", "4:3", "3:4". Default: "1:1".
input.width, input.heightintegerNoExplicit size in pixels, on models that support custom sizes.
input.seedintegerNoFixed seed for reproducible outputs.
input.image_urlstring (URL)NoSource image URL for image-to-image editing.
confirmbooleanNoSet to false to get a cost estimate without generating. Default: true.

Response fields

FieldTypeDescription
idstringUnique generation ID (gen_ prefix).
statusstring"completed" or "failed".
urlstringCDN URL of the generated image.
modelstringModel key used for generation.
modalitystringAlways "image".
cost.credits_usedintegerActual cost charged, in microdollars.
cost.estimated_creditsintegerEstimated cost, in microdollars.
cost.currencystringAlways "microdollars".
metadata.widthintegerOutput image width in pixels.
metadata.heightintegerOutput image height in pixels.
metadata.seedintegerSeed used (for reproducibility).

Code examples

curl

curl -X POST https://api.fairstack.ai/v1/generations/image \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "z-image-turbo",
    "input": {
      "prompt": "A mountain lake at golden hour, photorealistic"
    }
  }'

Python

from fairstack import FairStack

client = FairStack(api_key="fs_live_YOUR_KEY")

result = client.generate.image(
    model="z-image-turbo",
    prompt="A mountain lake at golden hour, photorealistic"
)
print(result.url)   # https://media.fairstack.ai/...
print(result.cost)  # $0.0048

Node.js

import { FairStack } from "fairstack";

const client = new FairStack({ apiKey: "fs_live_YOUR_KEY" });

const result = await client.generate.image({
  model: "z-image-turbo",
  prompt: "A mountain lake at golden hour, photorealistic",
});
console.log(result.url);   // https://media.fairstack.ai/...
console.log(result.cost);  // { credits_used: 4800, estimated_credits: 4800, currency: "microdollars" }

Response

{
  "id": "gen_abc123",
  "status": "completed",
  "url": "https://media.fairstack.ai/image/.../output.png",
  "model": "z-image-turbo",
  "modality": "image",
  "cost": {
    "credits_used": 4800,
    "estimated_credits": 4800,
    "currency": "microdollars"
  },
  "metadata": {
    "width": 1024,
    "height": 1024,
    "seed": 42
  }
}

Cost units. Every value inside cost is an integer in microdollars, as flagged by currency: "microdollars". The conversion is 1 USD = 1,000,000 microdollars. So credits_used: 30000 = $0.03, and the example above (4800) = $0.0048. The field is named credits_used for backward compatibility with existing SDKs — always read it as microdollars and convert as needed.

Cost estimation

Set confirm: false to get the exact cost without generating an image or being charged. This is especially useful for AI agents that need to evaluate budget impact before executing.

curl -X POST https://api.fairstack.ai/v1/generations/image \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY" \
  -d '{
    "model": "z-image-turbo",
    "input": { "prompt": "test" },
    "confirm": false
  }'

# Response (no image generated, no charge):
# { "estimated_cost": { "micro": 4800, "display": "$0.0048" } }

Image editing

Upload a source image URL and describe what to change. Models like FLUX Kontext and GPT Image 1.5 support in-context editing.

{
  "model": "flux-kontext-pro",
  "input": {
    "prompt": "Change the background to a tropical beach",
    "image_url": "https://example.com/photo.jpg"
  }
}

Quality tiers

TierExample ModelPriceBest For
StandardFLUX.2$0.03/imageMarketing, social media, product shots
PremiumNano Banana Pro$0.1608/imageProfessional, print quality, hero images
Low-costZ-Image Turbo$0.0048/imagePrototyping, bulk generation, thumbnails

Next steps