Image and video generation API
Base URL: https://getmegabrain.com/api/gateway/v1. Your key is on the API key page of your account; send it in the header Authorization: Bearer <key>. The same key works with the text models API. Generations are paid from your balance.
export MEGABRAIN_API_KEY="your key"Model catalog
The list of models with the price per unit in dollars (pricing.usd). The unit is image, megapixel or second (of video). The same models with examples are in the generation model catalog.
curl https://getmegabrain.com/api/gateway/v1/media/modelsQueue: submit a job
The request body is the model's own input parameters (prompt, image_size, num_images, image_urls for editing, start_image_url for image-to-video, duration…). The price is calculated before the job runs and charged right away; if your balance is too low, you get 402.
curl -X POST https://getmegabrain.com/api/gateway/v1/queue/kling-video/v3/standard/text-to-video \
-H "Authorization: Bearer $MEGABRAIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "a drone flies over a snowy mountain lake at sunrise", "duration": "5", "generate_audio": false}'{
"request_id": "6c1f…",
"model": "kling-video/v3/standard/text-to-video",
"status": "IN_QUEUE",
"status_url": "https://getmegabrain.com/api/gateway/v1/queue/requests/6c1f…/status",
"response_url": "https://getmegabrain.com/api/gateway/v1/queue/requests/6c1f…",
"refunded": false,
…
}Status and result
GET status_url returns IN_QUEUE, IN_PROGRESS, COMPLETED or FAILED. GET response_url returns the model's output (for example {"video": {"url": …}} or {"images": [{"url": …}]}), and 202 while the job is still running. Poll every 2–5 seconds.
curl https://getmegabrain.com/api/gateway/v1/queue/requests/$REQUEST_ID/status -H "Authorization: Bearer $MEGABRAIN_API_KEY"
curl https://getmegabrain.com/api/gateway/v1/queue/requests/$REQUEST_ID -H "Authorization: Bearer $MEGABRAIN_API_KEY"The same in Python: submit a job and wait for the result.
import os
import time
import requests
BASE = "https://getmegabrain.com/api/gateway/v1"
headers = {"Authorization": f"Bearer {os.environ['MEGABRAIN_API_KEY']}"}
job = requests.post(
f"{BASE}/queue/nano-banana-pro",
headers=headers,
json={"prompt": "nesting dolls on a frosty windowsill, photo"},
).json()
# Poll the status until the job finishes
while True:
status = requests.get(job["status_url"], headers=headers).json()["status"]
if status in ("COMPLETED", "FAILED"):
break
time.sleep(3)
result = requests.get(job["response_url"], headers=headers).json()
print(result) # {"images": [{"url": ...}]} or an error descriptionRefunds
If the provider fails the job, the status becomes FAILED and the full price is returned to your balance ("refunded": true). If the model rejects the input on submit (422), nothing is charged.
OpenAI-compatible images
POST /images/generations accepts the OpenAI body (model, prompt, n, size) and waits up to ~110 seconds for the finished image. If the image is not ready in time, you get 202 with queue links, as above. Other fields are passed to the model as is.
import os
from openai import OpenAI
client = OpenAI(base_url="https://getmegabrain.com/api/gateway/v1", api_key=os.environ["MEGABRAIN_API_KEY"])
img = client.images.generate(
model="nano-banana-pro",
prompt="infographic: how the generation API works",
size="1024x1024",
)
print(img.data[0].url)History
Your last 50 jobs with their statuses and links.
curl https://getmegabrain.com/api/gateway/v1/media/generations -H "Authorization: Bearer $MEGABRAIN_API_KEY"Errors
400— invalid request (for example,durationoutside the allowed values).401— missing or invalid key.402— not enough funds; add to your balance on the Balance page.404— the model is not served or the job was not found.422— the model rejected the input or the job failed (funds returned).503— the provider is temporarily unavailable; try again later.