legnext
Installation
SKILL.md
Legnext API Integration
Legnext (https://api.legnext.ai) gives you Midjourney image and video generation through a synchronous REST API: you submit a task, it runs asynchronously, and you collect the result by polling or webhook. This skill is the integration methodology — the API reference lives at https://docs.legnext.ai and is linked from each section below. Read the reference files in references/ on demand; do not load them all up front.
The integration loop
Every generation is three steps:
- Submit —
POST /api/v1/diffusionwith{ "text": "<prompt>", "callback": "<optional webhook>" }and thex-api-keyheader. Returns a job object withstatus: "pending"and ajob_id. Credits are frozen (reserved) at submit time — seereferences/task-lifecycle.md. - Wait — either poll
GET /api/v1/job/{job_id}untilstatusiscompletedorfailed, or receive a POST to yourcallbackURL when the job finishes. Pick one — see Webhook vs polling below. - Fetch & store — on
completed, readoutput.image_url(primary) andoutput.image_urls(grid). Download to permanent storage immediately — result URLs expire (seereferences/task-lifecycle.md).
Auth is a single header on every request: x-api-key: $LEGNEXT_API_KEY. Base URL: https://api.legnext.ai. Task endpoints live under /api/v1/{endpoint}; account under /api/account/.
Decisions to make before writing code
Webhook vs polling
- Webhook (pass
callbackon submit): lower latency, no polling cost. Use when you have a publicly reachable HTTPS endpoint. Respond2xxfast; the canonical result is stillGET /api/v1/job/{job_id}— fetch it rather than trusting only the webhook body. Dedupe deliveries byjob_id(a callback may arrive more than once). - Polling (
GET /api/v1/job/{job_id}): use when there is no public endpoint — local dev, CLIs, batch jobs behind NAT. Poll every 5–10s. Most fast-mode images finish in under a minute, but complex/slow jobs can run ~5 minutes; cap your poll loop at ~10–15 min and treat that as a failure/timeout to investigate.