Code recipe · REPRODUCIBLE GUIDE

GPT Image API with Python: Environment-Safe Example

Generate an image from Python without hard-coding credentials, then record the request as a benchmark fixture.

One API gateway for multiple AI models.

APIMart is a multi-model AI API gateway with an OpenAI-compatible endpoint. Use one account to access supported image models, compare current pricing, and choose a cost-efficient option for each workload.

Create an APIMart account ↗
Browse all guides
WHY THIS GUIDE EXISTS

Test the workflow,
not the marketing claim.

An implementation-first recipe for Python developers building repeatable image generation jobs.

Advertising

Midnight watch campaign

Luxury watch advertising key visual at midnight, brushed steel watch emerging from black water, razor-thin cyan rim light, restrained reflections, centered composition, generous negative space for headline.
Luxury campaign visual16:9
Technical

Exploded running shoe

Exploded technical view of a running shoe with upper, laces, foam midsole, plate and outsole separated vertically, clean off-white background, precise alignment, soft studio shadows, no labels.
Product explanation visual3:2
Ecommerce

Minimal coffee packaging

Premium whole-bean coffee pouch standing on dark walnut, uncoated cream paper with a small black label area, morning side light, restrained props, realistic folds, front panel fully visible, no invented text.
Packaging concept3:4
PYTHON QUICKSTART

Keep the request reproducible.

Store credentials in the environment. Record the exact model identifier, dimensions, test date, and retry count with the resulting asset.

import os
from openai import OpenAI

client = OpenAI(
  api_key=os.environ["APIMART_API_KEY"],
  base_url="https://api.apimart.ai/v1",
)

result = client.images.generate(
  model="gpt-image-1-official",
  prompt=PROMPT,
  size="1024x1024",
  n=1,
)
REVIEW CHECKLIST

Before you publish a result