Guide · 2026-10-10
Images from Python
Create a template, render it with variables, download the file. Three requests, no SDK needed.
Setup
pip install requests
export IMAGEAPIS_KEY=... # from https://dash.imageapis.com/
import os, requests
API = "https://api.imageapis.com"
H = {"X-API-Key": os.environ["IMAGEAPIS_KEY"]}
1. Save a template
template = {
"name": "Event card", "width": 1200, "height": 630, "background": "#0b1220",
"layers": [
{"name": "tag", "type": "text", "x": 72, "y": 72, "width": 600, "height": 32,
"text": "{{city}} · {{date}}", "font": "Inter", "weight": 600, "size": 22, "color": "#a5b4fc", "transform": "uppercase", "letter_spacing": 2},
{"name": "title", "type": "text", "x": 72, "y": 130, "width": 1056, "height": 300,
"text": "{{title}}", "font": "Space Grotesk", "weight": 700, "size": 84, "color": "#ffffff", "fit": "shrink", "max_lines": 3},
{"name": "seats", "type": "bar", "x": 72, "y": 500, "width": 500, "height": 12, "value": 0, "fill": "#22c55e", "track": "#1f2937", "radius": 6},
{"name": "seats_label", "type": "text", "x": 72, "y": 524, "width": 500, "height": 30, "text": "{{sold}} of {{capacity}} seats taken", "font": "Inter", "size": 20, "color": "#94a3b8"},
],
}
tpl = requests.post(f"{API}/v1/templates", headers=H, json=template).json()
print(tpl["id"]) # tpl_…
Creating, listing and updating templates cost nothing.
2. Render it
event = {"title": "Postgres at scale: what we learned running 40 TB", "city": "Austin", "date": "Nov 4", "sold": 212, "capacity": 300}
img = requests.post(f"{API}/v1/images", headers=H, json={
"template": tpl["id"],
"variables": event,
"modifications": [{"name": "seats", "value": round(100 * event["sold"] / event["capacity"])}],
"scale": 2,
}).json()
print(img["url"], img["units"]) # https://img.imageapis.com/i/img_….png 1
variables fill {{placeholders}}; modifications change any layer property by name, here the bar's value. The title is 50 characters, so the text layer shrinks from 84 px until three lines fit.
3. Download, or just link
png = requests.get(img["url"]).content
open("event.png", "wb").write(png)
Or skip the hosted file and get the bytes straight back:
r = requests.post(f"{API}/v1/images", headers=H, json={"template": tpl["id"], "variables": event, "response": "binary"})
open("event.png", "wb").write(r.content) # r.headers["X-Image-Url"] still has the hosted copy
Batches
For a few hundred renders, send webhook_url and the API answers 202 immediately, then POSTs the finished record to you. Watch X-Gw-Remaining on each response to pace against your plan.