MAGI-2 API quickstart
Submit a five-second 1080p video job, follow its status, and download the MP4 using the Higgsfield API.
1. Create an API key and check your balance
Sign in and create a key on the Higgsfield API keys page. Save the key ID and secret as a single server-side environment variable named HF_CREDENTIALS in the form KEY_ID:KEY_SECRET. Higgsfield’s self-serve API uses a prepaid dollar balance. The published minimum top-up is $5, and this five-second request is estimated to use $0.40 from that balance. Higgsfield billing · MAGI-2 API parameters
2. Submit a request and download the result
The following example uses Python’s standard library. Save it as magi2.py and run python magi2.py in the same terminal that has the environment variable. It sends one generation request, prints its ID, and checks that job until it can download the video. Save the ID so you can resume after an interruption.
import argparse
import json
import os
import time
from urllib.parse import quote
from urllib.request import Request, urlopen, urlretrieve
base = "https://api.higgsfield.ai"
headers = {
"Authorization": "Key " + os.environ["HF_CREDENTIALS"],
"Content-Type": "application/json",
}
def call(path, payload=None, idempotency_key=None):
body = json.dumps(payload).encode("utf-8") if payload is not None else None
request_headers = headers.copy()
if idempotency_key is not None:
request_headers["Idempotency-Key"] = idempotency_key
request = Request(base + path, data=body, headers=request_headers)
with urlopen(request, timeout=30) as response:
return json.load(response)
parser = argparse.ArgumentParser()
mode = parser.add_mutually_exclusive_group()
mode.add_argument("--request-id", help="Resume an existing job without submitting a new one")
mode.add_argument("--idempotency-key", help="Reuse the key for an identical submission")
args = parser.parse_args()
request_id = args.request_id
if request_id is None:
job = call("/sand/magi-2/text-to-video", {
"prompt": "Track a paper boat past a rain-dark stone wall. Hear water tapping on the paper.",
"duration": 5,
"resolution": "1080p",
"aspect_ratio": "16:9",
"generate_audio": True,
}, idempotency_key=args.idempotency_key)
request_id = job["request_id"]
print("Request ID:", request_id)
status_path = "/requests/" + quote(request_id, safe="") + "/status"
deadline = time.monotonic() + 20 * 60
while time.monotonic() < deadline:
result = call(status_path)
state = result["status"]
if state == "completed":
urlretrieve(result["video"]["url"], "magi-2.mp4")
print("Saved magi-2.mp4")
break
if state in {"failed", "nsfw", "canceled"}:
raise RuntimeError(f"Request {request_id} ended with status {state}")
time.sleep(5)
else:
raise TimeoutError(f"Check the status of existing request {request_id} before retrying.")
MAGI-2 takes a prompt, an integer duration from 4 to 30 seconds, 1080p resolution, and an aspect ratio. generate_audio controls whether it includes synchronized audio. The documented ratios for this endpoint are 21:9, 16:9, 4:3, 1:1, 3:4, and 9:16. To change the prompt or clip settings, build a matching body in the MAGI-2 Request Builder. Text-to-video reference
3. Check the existing job before trying again
If the script stopped during polling or a download failed, run python magi2.py --request-id YOUR_REQUEST_ID with the ID it printed. This resumes status checks and saves the result when available. It uses the same five-second poll interval as a new run. Stopping the script leaves the provider’s job running.
If you want to recover a lost submission response, create a unique key before the first run. Use python -c "import uuid; print(uuid.uuid4())" to generate one and save it. Start with python magi2.py --idempotency-key YOUR_SAVED_KEY. If a timeout or server error hides the response, run the exact same command with the saved key and unchanged request. Higgsfield returns the original job ID if it accepted the first submission. Once you have that ID, switch to --request-id for status checks. If you submitted without a saved key and received no ID, verify the original submission before trying again. Higgsfield idempotent requests
Higgsfield runs one MAGI-2 job at a time per account across text, image and reference modes. The script stops on failure, content rejection or cancellation. Higgsfield job lifecycle · How providers handle failed jobs
Use an image or reference media
For a starting image or a first and last frame, use Higgsfield’s image-to-video endpoint. For separate video, audio or image files to guide the shot, use reference to video. The API takes public HTTPS URLs for these inputs. Higgsfield documents MP4 or MOV for reference video, up to 200 MB per file and 30 seconds of video references total. To try the modes before changing your code, use the Playground links by input.
Turn a local file into an API reference
- From your server, send
POST /files/generate-upload-urlto the Higgsfield API with the file’s MIME type. A JPEG uses{"content_type":"image/jpeg"}. - Send the raw file bytes in a
PUTto the returnedupload_url. Use every header inupload_headersfor the storage request and keep your API key on the server. - After the upload succeeds, use the returned
public_urlasimage_urlfor a first frame orend_image_urlfor a last frame. For reference-to-video, put each URL in the matchingimage_urls,video_urlsoraudio_urlsarray.
Higgsfield file upload walkthrough · MAGI-2 reference request fields
Choose the API you want to use
| API | Where to start | What to check |
|---|---|---|
| Sand AI Platform | Use the published magi-2 quickstart. |
Your organization needs the model enabled. The pricing page currently shows top-ups as unavailable. |
| Higgsfield API | Use the request and polling example above or open the provider’s API playground. | Check your balance and the one-job concurrency limit. |
| NanoAPI | Choose text, frames or references. Pass webhook_url for a notification, or poll for status. |
NanoAPI says a four-second clip can take 13–17 minutes. Its docs suggest polling no more than once every 15 seconds. |
| Kie.ai | Submit magi-2/text-to-video through Kie’s shared task endpoint. It accepts callBackUrl for completion notifications. |
Kie uses its own credit balance and result format. |
| SandBase | Use the Sand AI Ark-compatible request format with a SandBase key and base URL. | Send frames or reference media in the content array. Use one of those modes per job. |
Compare first top-ups and clip costs · Find a browser generator