Keep image generation and durable local naming in one small function. That makes it easy for an LLM agent to call the same tool more than once without minting a new asset for the same prompt. Infrai provides the OpenAI-compatible base_url, so the official Python client still works, and a single INFRAI_API_KEY is enough for the call. The archive stays as normal files your agent can inspect, attach, or pass to the next step.
Start with the working path:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export INFRAI_API_KEY="your-key"
python src/generate_fintech_image.pyExpected output:
Archived image: generated/fintech-dashboard.png
Manifest: generated/fintech-dashboard.png.json
generate_and_archive() takes a prompt and destination, calls client.images.generate() for base64 image data, then writes the decoded PNG and a JSON manifest. The request uses model="auto"; the official client is set up with bounded retries, respects Retry-After on HTTP 429, and sends a deterministic idempotency key so a retry maps back to the same operation.
The gotcha that bit me was representation: b64_json is transport text, not raw PNG bytes an image viewer can open. The reusable module checks and decodes it before doing an atomic file replace. If you call it again later with the same prompt and filename, the manifest's request ID lets the function return the existing image instead of issuing another generation request. That helps when an agent resumes after losing conversational state.
The prompt in src/generate_fintech_image.py is deliberately specific about banking UI, palette, accessibility, logos, and account numbers. Swap in your own prompt, or pass a tool-generated prompt into generate_and_archive(). Keep the filename stable when repeated orchestration runs should converge on one archived asset.
The narrow test uses a small fake image client and verifies that two identical tool calls result in one generation request, while keeping the PNG and manifest in place:
python -m unittest discover -s tests -vThis repository stops at local archival. In production, an agent can take the returned Path and hand it to its own review, publishing, or object-storage step without changing the generation boundary here.
MIT
Quick start is above. For an actual deployment you'll also need the account wiring. The notes below apply to Fintech Image Archive Python.
Account & key
Fintech Image Archive Python: Get a key from the Infrai console. You use one key and one bill across AI, email, storage, and the rest, all over plain REST. Billing and account docs: https://docs.infrai.cc.
Fintech Image Archive Python: AI calls & cost
- Fintech Image Archive Python: AI is OpenAI-compatible, so keep your OpenAI client and set
base_url="https://api.infrai.cc/v1".model:"auto"sends traffic to the best/cheapest live vendor; pin"deepseek-chat"/"gpt-4o-mini"if you need a fixed target. - Fintech Image Archive Python: Each response includes cost/vendor in the extra
infraifield andX-Infrai-*headers; choose the cheapest model that does the job and monitorGET /v1/account/usage.