In short: send the request to POST /v1/media/generations, with the model and, in input, the description. The answer comes straight back, with the id. Then call GET /v1/media/generations/{id} every 5 seconds until the status is no longer processing. Image links are not permanent: download the files. See also the AI images page.
What you need
| 2 |
AI credits in your account, for the prod_ key. You buy them in All in One AI.
|
|
| 3 |
The model id. On the «Models» tab, the «Copy the id» button copies it.
|
|
The two steps
An image takes from a few seconds to a few minutes. So there are two steps: the request, which answers at once, and the status check, which you repeat until the image is done. The OpenAI SDK does not have these operations: use plain HTTP requests.
| Step |
Operation |
What you get |
| 1. The request |
POST /v1/media/generations |
Code 202, with the id, the status processing and the reserved credits in credits_reserved. |
| 2. The check |
GET /v1/media/generations/{id} |
completed: the files in outputs and the real cost in credits_charged. failed: the reason in error, and nothing is charged. |
A complete example, in Python
Keep the key in the INTERWEB_API_KEY environment variable and run:
import os, time, requests
API = "https://api.interweb.co.mz/v1"
H = {"Authorization": "Bearer " + os.environ["INTERWEB_API_KEY"]}
job = requests.post(API + "/media/generations", headers=H, timeout=30, json={
"model": "openai/gpt-image-2/text-to-image",
"input": {"prompt": "A bright, modern office with plants and soft morning light", "size": "1024x1024"},
}).json()["data"]
while job["status"] == "processing":
time.sleep(5)
job = requests.get(API + "/media/generations/" + job["id"], headers=H, timeout=30).json()["data"]
print(job["status"], job["outputs"], job["credits_charged"])
The input fields change from model to model. GET /v1/models/{id} shows them, with the accepted values and the default for each one. Starting files, such as a photo to edit, go as public addresses (URLs).
Saving the files
The links in outputs are not permanent. Have your program download the images as soon as the generation finishes, and keep them on your server or your computer.
|
The key stays on the server. Never put it in code that runs in the browser or in a mobile app: anyone who sees it can spend your credits. See how to create an API key.
|
|
Want AI images in your own program? See the AI images page.
See AI images
|