karleeovHow MiniMax API authentication works — Bearer tokens, regional base URLs, and the create → poll → download async flow you need before generating your first AI video.
Before you generate a single frame with MiniMax, you need to understand how the API authenticates, where it lives, and why everything is asynchronous. This is the foundation — the same material from the first module of my MiniMax AI generation course.
Grab your key from the MiniMax Platform. Treat it like a password — never hardcode it, never commit it.
export MINIMAX_API_KEY="your-api-key"
Every request sends the key as a Bearer token in the Authorization header:
import os
headers = {
"Authorization": f"Bearer {os.environ['MINIMAX_API_KEY']}",
"Content-Type": "application/json",
}
🔒 DevKing rule: load secrets from the environment. If you ever paste a key straight into source, delete it from history and rotate it immediately.
| Region | Base URL |
|---|---|
| Mainland China | https://api.minimaxi.com |
| Overseas / International | https://api.minimax.io |
All examples below use the China endpoint (api.minimaxi.com). Swap it out if you're on the international plan.
Video generation is not instant — it's a background job. Understand this loop and everything else is trivial.
1. Create task → POST /v1/video_generation → returns task_id
2. Poll status → GET /v1/query/video_generation → returns status + file_id
3. Get download → GET /v1/files/retrieve → returns download_url
Preparing → Queueing → Processing → Success ✅ (or Fail ❌)
import time, requests
API_BASE = "https://api.minimaxi.com/v1"
def poll_until_done(task_id):
while True:
data = requests.get(
f"{API_BASE}/query/video_generation",
headers=headers,
params={"task_id": task_id},
).json()
status = data["status"]
if status == "Success":
return data["file_id"]
if status == "Fail":
raise RuntimeError(f"Generation failed: {data}")
print(f"Waiting... {status}")
time.sleep(10) # recommended interval
headers dict with Bearer tokenNext up in the course: text-to-video generation. Follow along and I'll publish each module as a post.
If this kind of post is useful, the easiest way to support the work is to: