Generate product photos for an online store with an API
Generate AI product photos and studio backdrops with an API using thelastapi, the OpenAI SDK, and permanent image hosting in project Files.
On this page 9 sections
- How product image generation works via API
- Picking the right model for product photography
- Step 1: Uploading an original product packshot
- Step 2: Generating product photos with the OpenAI SDK
- Step 3: Generating photos using curl or HTTP
- Quick prototyping from the terminal
- Managing production costs and budgets
- Next steps
- FAQ
You can generate product photos for an online store via API by calling image models like vibiz/image-pro or vibiz/image through an OpenAI-compatible endpoint. thelastapi provides unified access to Google and OpenAI image models, accepts reference product images through image_url or image_urls, and automatically saves every generated photo to your project's permanent file storage. You can run new product renders from text prompts, restyle existing packshots onto studio backgrounds, or place items into lifestyle scenes without managing separate storage buckets or vendor accounts.
Whether you run a marketplace that automates merchant uploads or an ecommerce brand creating social variations, this guide shows how to generate and edit commercial product photos using the CLI, TypeScript, and raw HTTP requests.
How product image generation works via API
Generating photos for an online store generally falls into two patterns: generating a brand-new concept from scratch using text, or editing an existing product photo to place it on a clean studio surface or lifestyle background.
thelastapi handles both through the standard POST /v1/ai/images/generations route:
- Text-to-image: You send a detailed prompt describing the item, lighting, angle, and backdrop. The API returns an image matching the prompt.
- Image-to-image editing: You pass the original product snapshot via
image_url(or multiple references viaimage_urls), along with a prompt describing what to modify or replace. The model preserves the core subject while generating a new setting, shadows, and reflections.
Every image generated through a project key is automatically saved into your project's Files. You receive a permanent public URL directly in the response payload (url and file_url), meaning you can immediately write the image URL to your ecommerce database or pass it to an inventory sync workflow without re-uploading the file to a separate CDN.
Picking the right model for product photography
Different image models excel at different commercial tasks. Three dedicated tiers cover most store requirements:
| Model ID | Runs on | Best suited for | Cost |
|---|---|---|---|
vibiz/image-pro | Nano Banana 2.1 (Google) | High-definition product shots, detailed materials, fast generation | about $0.034 per image |
vibiz/image | Nano Banana 2 (Google) | Edits, scene restyling, consistent character and product placement | about $0.067 per image |
vibiz/image-text | GPT-5.4 Image 2 (OpenAI) | Complex scenes, labels, and rendering legible text on packaging | about $0.04 per image |
If you need specialised pipelines beyond these tiers—such as background removal, try-on, or upscalers—you can search available media models using the CLI:
vibiz media-modelsYou can also call specific models by their id, including black-forest-labs/flux-schnell or black-forest-labs/flux-dev. For more details on the media catalog, see our guide on one API for image, video and voice AI models.
Step 1: Uploading an original product packshot
When modifying an existing product image, the API requires a publicly accessible HTTPS link. You can store your clean product packshots directly in project Files using the CLI or the @vibiz/app SDK.
From the command line:
vibiz files upload ./bottle-raw.png --folder productsThis returns a permanent link formatted as https://thelastapi.dev/f/<key>/bottle-raw.png.
In your application code, you can upload assets using the SDK:
import { vibiz } from '@vibiz/app';
import { readFileSync } from 'node:fs';
const bytes = readFileSync('./bottle-raw.png');
const file = await vibiz.files.upload(bytes, {
name: 'bottle-raw.png',
contentType: 'image/png',
folder: 'products',
});
console.log('Public URL:', file.url);Public files have permanent links that never expire. If you need to combine people with merchandise in your generated scenes, see our guide on how to combine a person and a product in one image with an API.
Step 2: Generating product photos with the OpenAI SDK
thelastapi exposes an OpenAI-compatible gateway at /v1/ai. When you initialise a project with vibiz init "Store App" --resources ai, your development environment receives VIBIZ_AI_BASE_URL and VIBIZ_AI_API_KEY (with standard aliases OPENAI_BASE_URL and OPENAI_API_KEY).
The standard OpenAI SDK can be used directly without custom plugins:
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL,
apiKey: process.env.VIBIZ_AI_API_KEY,
});
async function generateStudioShot(referenceUrl: string) {
const response = await openai.images.generate({
model: 'vibiz/image-pro',
prompt: 'Place the product bottle upright on a clean beige travertine stone pedestal, soft morning directional sunlight, crisp shadows, luxury cosmetic studio photography, 8k resolution',
response_format: 'url',
// thelastapi accepts image_url directly in image requests
image_url: referenceUrl,
} as never);
const photo = response.data[0];
console.log('Permanent CDN URL:', photo.url);
return photo.url;
}
generateStudioShot('https://thelastapi.dev/f/Qm9x1234567890abcdef1234567890ab/bottle-raw.png');Because response_format: "url" is passed, photo.url contains the permanent project link. You do not need to convert base64 payloads or re-host the resulting buffer.
Step 3: Generating photos using curl or HTTP
If your ecommerce backend is written in Python, Go, or PHP, you can call the gateway using plain HTTP:
curl https://thelastapi.dev/v1/ai/images/generations \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/image-pro",
"prompt": "Matte black ceramic coffee mug on a natural oak table next to a linen napkin, soft warm lighting, professional catalog photography",
"response_format": "url"
}'The gateway answers with an OpenAI-shaped JSON response enriched with thelastapi metadata:
{
"created": 1714567890,
"data": [
{
"url": "https://thelastapi.dev/f/Qm9x456789012345678901234567890c/2026-10-28-matte-black-ceramic-coffee-mug.png",
"file_id": "file_01k987654321",
"file_url": "https://thelastapi.dev/f/Qm9x456789012345678901234567890c/2026-10-28-matte-black-ceramic-coffee-mug.png"
}
],
"cost_micro_usd": 34000,
"served_model": "google/nano-banana-2.1"
}The cost_micro_usd property reports the exact cost of the generation (34,000 micro-USD is $0.034), and served_model indicates the underlying model executed. If a model encounters an outage, the API returns a 503 model_unavailable or 503 provider_unavailable error rather than silently substituting a different model.
Quick prototyping from the terminal
You can test photography prompts and verify output quality directly from your terminal using the CLI:
# Generate a new product visual from scratch
vibiz image "Minimalist leather sneaker resting on an architectural concrete block, diffused daylight, product catalog photograph" -o sneaker.png --model vibiz/image-pro
# Restyle an existing product packshot into a lifestyle setting
vibiz image "Place this sneaker on an autumn city sidewalk with fallen leaves in the background, commercial depth of field" -o sneaker-lifestyle.png --from-image https://thelastapi.dev/f/Qm9x123/sneaker-isolated.pngTo review the latest images generated across your project, use:
vibiz files --type image --source ai --limit 5Managing production costs and budgets
Automated image pipelines can accumulate expenses quickly if a batch process loops unexpectedly. thelastapi enforces guardrails at both the account and project level:
- Account ceiling: Accounts have a default daily spend ceiling of $5 across all AI and actions combined, which account owners can adjust in Billing.
- Project budget: Projects default to a $1 daily AI budget. You can inspect or update this value via the CLI:Terminal
vibiz ai budget 15 --project prj_123 - Budget enforcement: If a project reaches its daily budget, subsequent calls return HTTP
429withdetails.reason: "project_budget". - Alert notifications: Account owners receive automated notification emails when spend reaches 80% and 100% of the daily limit.
If your company has existing Google Cloud credits, you can add your own Gemini API key using GEMINI_API_KEY=... vibiz ai keys set google. When your Google key is active, calls to vibiz/image and vibiz/image-pro run on your own Google account at no charge on thelastapi, while non-Google models continue billing normally.
Next steps
Once you have generated a catalog of product photos, you can offer them directly to customers by reading how to sell a one-time product with a hosted checkout link, or build video promotions around your visual assets using our walkthrough on an automated short-video pipeline with one API. Detailed configuration and rate limit parameters are available in the AI docs.
Frequently asked questions
Where are the generated product photos hosted?
Every image created using a project key is automatically saved in your project's Files storage with a permanent, non-expiring public URL. You can retrieve files using `url` in the API response or query them later with `vibiz files latest --type image`.
Can I provide more than one reference image to combine props or models with my product?
Yes. You can pass up to 8 image links in the `image_urls` array on `POST /v1/ai/images/generations` when using models like `vibiz/image` and `vibiz/image-pro`.
What image dimensions can I generate?
Image generation requests support side dimensions between 256 px and 2,048 px, with up to 4 images generated per request.
What happens if an image model experiences downtime?
thelastapi never silently substitutes another model. If the requested model is unavailable, the gateway returns a `503 model_unavailable` or `503 provider_unavailable` error with a retry hint.