Skip to content
Go To Dashboard

Generate Images

Generate images from text prompts, transform existing images, or upscale low-resolution images — all through a single API with no account setup required.

import { withSapiom } from "@sapiom/axios";
import axios from "axios";
// Create a Sapiom-wrapped Axios client
const client = withSapiom(
axios.create({ baseURL: "https://fal.services.sapiom.ai" }),
{
apiKey: process.env.SAPIOM_API_KEY,
baseURL: "https://api.sapiom.ai",
serviceName: "Fal.ai Image Generation",
agentName: "my-agent",
}
);
// Generate image with Fal.ai - Sapiom tracks cost automatically
const { data } = await client.post("/v1/run/fal-ai/flux/dev", {
prompt: "A serene mountain landscape at sunset",
image_size: "landscape_4_3",
});
console.log("Generated image:", data.images[0].url);

Sapiom routes image generation requests to FAL, which provides access to state-of-the-art image generation models including FLUX and SDXL. The SDK handles payment negotiation automatically — you pay per megapixel based on the model and image size.

The service supports three operations:

  1. Generate — Create images from text prompts
  2. Transform — Modify existing images with img2img
  3. Upscale — Increase image resolution

Powered by FAL. FAL provides fast, scalable inference for generative AI models with optimized GPU infrastructure.

Endpoint: POST https://fal.services.sapiom.ai/v1/run/{model}

Generate one or more images from a text prompt. The model is specified in the URL path.

Supported models: fal-ai/flux/dev, fal-ai/flux/schnell, fal-ai/flux-pro, fal-ai/stable-diffusion-xl

ParameterTypeRequiredDescription
promptstringYesText description of the image to generate
image_sizestringNoSize preset (default: landscape_4_3)
num_imagesnumberNoNumber of images to generate, 1-4 (default: 1)
num_inference_stepsnumberNoQuality steps, 1-100 (default: 28)
guidance_scalenumberNoPrompt adherence (default: 3.5)
output_formatstringNojpeg or png (default: jpeg)
seednumberNoSeed for reproducible generation

Image size presets:

PresetDimensions
square_hd1024 × 1024
square512 × 512
portrait_4_3768 × 1024
portrait_16_9576 × 1024
landscape_4_31024 × 768
landscape_16_91024 × 576
{
"prompt": "A serene mountain lake at dawn with mist",
"model": "flux-dev",
"image_size": "landscape_16_9",
"num_images": 1
}
{
"images": [
{
"url": "https://fal.media/files/abc123.jpg",
"width": 1024,
"height": 576,
"content_type": "image/jpeg"
}
],
"seed": 42,
"prompt": "A serene mountain lake at dawn with mist"
}

Endpoint: POST https://fal.services.sapiom.ai/v1/transform

Transform an existing image using img2img techniques.

ParameterTypeRequiredDescription
image_urlstringYesURL of the input image
promptstringYesDescription of the desired transformation
image_sizestringNoOutput size preset (default: landscape_4_3)
strengthnumberNoTransformation strength, 0.0-1.0 (default: 0.75)
num_inference_stepsnumberNoQuality steps, 1-100 (default: 28)
num_imagesnumberNoNumber of outputs, 1-4 (default: 1)
output_formatstringNojpeg or png (default: jpeg)
seednumberNoSeed for reproducible generation
{
"image_url": "https://example.com/photo.jpg",
"prompt": "Transform into a watercolor painting style",
"strength": 0.75
}
{
"images": [
{
"url": "https://fal.media/files/xyz789.jpg",
"width": 1024,
"height": 768,
"content_type": "image/jpeg"
}
]
}

Endpoint: POST https://fal.services.sapiom.ai/v1/upscale

Increase image resolution while preserving quality.

ParameterTypeRequiredDescription
image_urlstringYesURL of the image to upscale
modelstringNoUpscaling model (default: topaz)
scalenumberNoScale factor: 2 or 4 (default: 2)
output_formatstringNojpeg or png (default: jpeg)
{
"image_url": "https://example.com/small-image.jpg",
"scale": 4
}
{
"image": {
"url": "https://fal.media/files/upscaled.jpg",
"width": 4096,
"height": 3072,
"content_type": "image/jpeg"
}
}

Endpoints:

  • POST https://fal.services.sapiom.ai/v1/generate/price
  • POST https://fal.services.sapiom.ai/v1/transform/price
  • POST https://fal.services.sapiom.ai/v1/upscale/price

Get the estimated cost before making a request. Accepts the same parameters as the main endpoint.

{
"price": "$0.012",
"currency": "USD"
}
CodeDescription
400Invalid request — check parameters and image URL
402Payment required — ensure you’re using the Sapiom SDK
404Model not found
413Image too large for processing
429Rate limit exceeded
import { withSapiom } from "@sapiom/axios";
import axios from "axios";
const client = withSapiom(axios.create(), {
apiKey: process.env.SAPIOM_API_KEY,
});
const baseUrl = "https://fal.services.sapiom.ai/v1";
async function generateProductImage(description: string) {
// Generate a product visualization
const { data } = await client.post(`${baseUrl}/generate`, {
prompt: `Professional product photo: ${description}, studio lighting, white background`,
model: "flux-dev",
image_size: "square_hd",
num_images: 1,
guidance_scale: 4.0,
});
return data.images[0].url;
}
async function createVariation(imageUrl: string, style: string) {
// Transform an existing image
const { data } = await client.post(`${baseUrl}/transform`, {
image_url: imageUrl,
prompt: `Render in ${style} style`,
strength: 0.6,
});
return data.images[0].url;
}
// Usage
const productImage = await generateProductImage("minimalist desk lamp");
console.log("Generated:", productImage);
const artVariation = await createVariation(productImage, "pop art");
console.log("Variation:", artVariation);

Pricing is based on megapixels (MP) — the total pixels in the output image divided by 1,000,000.

ModelPrice per MP
flux-schnell$0.004
flux-dev$0.015
flux-pro$0.04
sdxl$0.007
OperationPrice per MP
Transform (img2img)$0.045
Upscale$0.03

Example costs (landscape_4_3 = 0.79 MP):

  • flux-schnell: ~$0.003
  • flux-dev: ~$0.012
  • flux-pro: ~$0.032