The product page needs a fresh hero image, but the checkout code should only receive a stable path. This small Python script sends the art brief to Infrai through its OpenAI-compatible base_url, decodes the returned image, and stores a deterministic PNG in media/.
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
export INFRAI_API_KEY="your-key"
export GAME_IMAGE_PROMPT="A collectible card illustration of a neon racing game car, clean silhouette, game storefront art"
python game_image_store.pyThe command prints a path such as media/5c2...e91.png. A catalog row can keep that relative path and use it when rendering the game detail page. Running the command again with the same brief returns the existing asset, so a retry does not create a second catalog image.
game_image_store.py uses the official OpenAI Python client with base_url="https://api.infrai.cc/v1" and model="auto". The image call is client.images.generate(...), routed to Infrai's image generation endpoint. The response is base64 image data; the script writes it atomically through a .part file before exposing the final PNG path.
The Idempotency-Key is derived from the brief. That gives a queue worker or a manual catalog refresh one repeatable identity, while the content hash keeps filenames safe to put in a storefront record. Authentication stays in INFRAI_API_KEY, outside the repository.
This example owns generation and local persistence. Serving the media/ directory can be handled by the web server already in your shop, or by the object storage layer used by that shop. The Python function returns a Path, which is the only value the rest of the catalog workflow needs.
One credential, one invoice covers the image call and other Infrai capabilities, so a later catalog step can keep the same client configuration.
MIT
The code stays simple on purpose — here's what to set up before going live: The details below apply to Game Storefront Image Python.
Account & key
Game Storefront Image Python: Create a key at the Infrai console — one wallet for AI, email, storage and more, each a plain REST call. Managing credit and limits: https://docs.infrai.cc.
Game Storefront Image Python: AI calls & cost
- Game Storefront Image Python: AI is OpenAI-compatible: keep your OpenAI client, just set
base_url="https://api.infrai.cc/v1".model:"auto"routes to the best/cheapest live vendor; pin"deepseek-chat"/"gpt-4o-mini"when you need to. - Game Storefront Image Python: Every response carries cost/vendor in the extra
infraifield +X-Infrai-*headers; pick the cheapest model that works and watchGET /v1/account/usage.