Skip to content

About

MAGI-2 API examples in cURL, Node.js, and Python for text-to-video, first/last frame, and reference-to-video with native audio through PoYo. $0.08 per second at 1080p.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

MAGI-2 API: cURL, Python, and Node.js Examples

MAGI-2 on PoYo API docs Check

Runnable examples for Sand AI MAGI-2 through PoYo's async video API: 4–30 second 1080p videos with synchronized dialogue, sound effects, and ambience, from text, first and last frames, or image, video, and audio references.

Answer: To use the MAGI-2 API, send a server-side request to POST https://api.poyo.ai/api/generate/submit with model magi-2 and a PoYo API key, then poll GET https://api.poyo.ai/api/generate/status/{task_id}. The examples in this repository run with Python 3.9+, Node.js 22+, or cURL.

Last verified against the live PoYo schema and pricing on November 28, 2026.

MAGI-2 at a glance

  • Model ID: magi-2 on POST https://api.poyo.ai/api/generate/submit
  • Output: one 1080p MP4, 4–30 seconds (default 5), H.264 at 25 fps with an AAC stereo audio track
  • Audio: dialogue, sound effects, and ambience generated together with the picture; generate_audio: false returns a video-only file
  • Modes: text-to-video, first frame or first and last frames, and reference-to-video
  • References: up to 10 images, 5 videos, and 5 audio clips in one task
  • Aspect ratios: 16:9 (default), 9:16, 1:1, 4:3, 3:4, 21:9; first-frame tasks follow the first frame
  • Prompts: up to 15,000 characters, enough for a full script or shot list
  • Price: 16 credits ($0.08) per second at 1080p, so a 5-second clip costs 80 credits ($0.40)

Quickstart

  1. Create a key in the PoYo dashboard.
  2. Copy .env.example to .env and replace the placeholder.
  3. Run one of the examples. Each submits the task and polls until finished or failed.
POYO_API_KEY=YOUR_POYO_API_KEY_HERE
POYO_BASE_URL=https://api.poyo.ai

Python

python python/generate.py
python python/generate.py payloads/magi-2-reference-to-video.json

python/generate.py uses only the Python standard library.

Node.js

node node/index.mjs
node node/index.mjs payloads/magi-2-first-frame.json

cURL

curl -X POST "https://api.poyo.ai/api/generate/submit" \
  -H "Authorization: Bearer $POYO_API_KEY" \
  -H "Content-Type: application/json" \
  -d @payloads/magi-2-text-to-video.json

Status polling and the other modes are in curl/generate.md.

Example requests

Every file in payloads/ is a complete request body with public input media, so it runs as-is.

File Mode Settings Credits
magi-2-text-to-video.json Text-to-video with a spoken line 5 s, 16:9 80 ($0.40)
magi-2-first-frame.json First frame to video 5 s, aspect ratio from the frame 80 ($0.40)
magi-2-reference-to-video.json Character image + music reference 8 s, 16:9 128 ($0.64)

Input modes

Mode Selected when Aspect ratio
Text-to-video Only prompt (no media fields) aspect_ratio, default 16:9
First and last frames image_urls has 1 image (opening frame) or 2 images (opening and closing frames) Follows the first frame; omit aspect_ratio or send auto
Reference-to-video Any mix of reference_image_urls, reference_video_urls, and reference_audio_urls, including audio on its own aspect_ratio, default 16:9

Each task uses one of the two media modes: image_urls for frames, or the reference_* fields for references. In reference mode, say in the prompt how each reference is used (the character from the image, the melody from the audio, the camera move from the video).

Request fields

Field Requirement Meaning
prompt required Scene, subjects, motion, camera, and sound, up to 15,000 characters. Put spoken lines in quotes.
duration optional Whole seconds from 4 to 30. Default 5.
resolution optional 1080p.
aspect_ratio optional 16:9 (default), 9:16, 1:1, 4:3, 3:4, or 21:9 for text and reference modes; auto for first and last frames.
image_urls optional 1–2 public JPG, PNG, or WEBP URLs: the opening frame and an optional closing frame.
reference_image_urls optional Up to 10 images for characters, objects, scenes, or style.
reference_video_urls optional Up to 5 MP4 or MOV videos, each 2–30 seconds and up to 30 seconds in total.
reference_audio_urls optional Up to 5 MP3 or WAV clips, each 2–30 seconds and up to 30 seconds in total.
generate_audio optional true (default) generates synchronized audio; false returns a video-only file.
seed optional Integer from 0 to 2147483647. Reuse it with the same inputs for similar results.

Pricing

Billing is per second of video. 1 credit = $0.005.

Model Resolution Price
magi-2 1080p 16 credits ($0.08) per second

Cost per clip

Duration Credits USD
4 s (minimum) 64 $0.32
5 s (default) 80 $0.40
10 s 160 $0.80
15 s 240 $1.20
30 s (maximum) 480 $2.40

Credits are charged only when the task succeeds. Confirm current prices on the model page before a production rollout.

Writing MAGI-2 prompts

  • Write the sound too: describe music, ambience, and effects ("rain patters on the wet pavement") as well as the picture.
  • Quote the dialogue: put each spoken line in quotes and say who says it; the character speaks it in the generated audio.
  • Use the long prompt: up to 15,000 characters fits a shot list with timing, camera moves, and lines for a 30-second take.
  • Name your references: in reference mode, refer to "the character from the reference image" or "the melody from the reference audio" so the model knows what each file is for.
  • Frames set the shot: with image_urls, describe the motion between the opening and closing frames rather than the frames themselves.

Async production flow

submit -> persist data.task_id -> poll during development -> receive callback_url webhook in production

Treat finished and failed as terminal states. A finished task returns one MP4 file. Copy outputs to your own storage after the task finishes.

FAQ

How much does the MAGI-2 API cost? 16 credits ($0.08) per second at 1080p: 80 credits ($0.40) for the default 5 seconds and 480 credits ($2.40) for the 30-second maximum.

Does MAGI-2 generate audio? Yes. Dialogue, sound effects, and ambience are generated with the picture by default. Set generate_audio to false for a video-only file.

How long can a MAGI-2 video be? 4 to 30 seconds in one generation, in whole seconds.

Can I set both the first and the last frame? Yes. Send two images in image_urls: the first is the opening frame, the second the closing frame.

Can I combine frames and references? No. A task uses either image_urls or the reference_* fields.

Repository map

Related repositories

Links

License

MIT

About

MAGI-2 API examples in cURL, Node.js, and Python for text-to-video, first/last frame, and reference-to-video with native audio through PoYo. $0.08 per second at 1080p.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages