> ## Documentation Index
> Fetch the complete documentation index at: https://docs.melius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Generate your first image with the Melius API in a few minutes.

## 1. Get an API key

In the Melius app, go to **Team settings → Integrations**, create a key, and copy it — it's shown once. See [Authentication](https://docs.melius.com/api/authentication.md) for details.

## 2. Make your first request

Paste your key into the snippet below and run it. It creates a project and canvas, adds an image node with your prompt, runs it, waits for the generation to finish, and prints the URL of the generated image.

```bash cURL theme={null}
KEY="mel_..."
BASE="https://api.melius.com/api/v1"
AUTH=(-H "Authorization: Bearer $KEY" -H "Content-Type: application/json")

PROJECT=$(curl -s "${AUTH[@]}" -d '{"title":"My first project"}' $BASE/projects | jq -r .id)
CANVAS=$(curl -s "${AUTH[@]}" -d '{"title":"My first canvas"}' $BASE/projects/$PROJECT/canvases | jq -r .id)

NODE=$(uuidgen | tr 'A-Z' 'a-z')
curl -s "${AUTH[@]}" -d "{\"id\":\"$NODE\",\"nodeType\":\"image\",\"geometry\":{\"x\":0,\"y\":0,\"w\":380,\"h\":632},\"textPrompt\":\"a golden retriever puppy in a field\"}" $BASE/canvases/$CANVAS/direct/nodes > /dev/null

RUN_KEY=$(uuidgen)
RUN=$(curl -s "${AUTH[@]}" -H "Idempotency-Key: $RUN_KEY" -d "{\"canvasId\":\"$CANVAS\"}" $BASE/nodes/$NODE/runs | jq -r .id)

while true; do
  STATUS=$(curl -s "${AUTH[@]}" $BASE/node-runs/$RUN | jq -r .status)
  [ "$STATUS" = "finished" ] && break
  [ "$STATUS" = "failed" ] && { echo "generation failed"; exit 1; }
  sleep 2
done

curl -s "${AUTH[@]}" -d '{}' $BASE/node-runs/$RUN/download | jq -r .url
```

```python Python theme={null}
import time, uuid, requests

KEY = "mel_..."
BASE = "https://api.melius.com/api/v1"
auth = {"Authorization": f"Bearer {KEY}"}

project = requests.post(f"{BASE}/projects", headers=auth, json={"title": "My first project"}).json()
canvas = requests.post(f"{BASE}/projects/{project['id']}/canvases", headers=auth, json={"title": "My first canvas"}).json()

node_id = str(uuid.uuid4())
requests.post(f"{BASE}/canvases/{canvas['id']}/direct/nodes", headers=auth, json={
    "id": node_id,
    "nodeType": "image",
    "geometry": {"x": 0, "y": 0, "w": 380, "h": 632},
    "textPrompt": "a golden retriever puppy in a field",
})

run_key = str(uuid.uuid4())
run = requests.post(f"{BASE}/nodes/{node_id}/runs", headers={**auth, "Idempotency-Key": run_key}, json={"canvasId": canvas["id"]}).json()

while True:
    status = requests.get(f"{BASE}/node-runs/{run['id']}", headers=auth).json()["status"]
    if status in ("finished", "failed"):
        break
    time.sleep(2)

result = requests.post(f"{BASE}/node-runs/{run['id']}/download", headers=auth, json={}).json()
print(result["url"])
```

```typescript TypeScript theme={null}
const KEY = "mel_...";
const BASE = "https://api.melius.com/api/v1";
const headers = {
    Authorization: `Bearer ${KEY}`,
    "Content-Type": "application/json",
};
const post = <T>(
    path: string,
    body: unknown,
    idempotencyKey?: string,
): Promise<T> =>
    fetch(`${BASE}${path}`, {
        method: "POST",
        headers: {
            ...headers,
            ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),
        },
        body: JSON.stringify(body),
    }).then((r) => r.json());
const get = <T>(path: string): Promise<T> =>
    fetch(`${BASE}${path}`, { headers }).then((r) => r.json());

async function main() {
    const project = await post<{ id: string }>("/projects", {
        title: "My first project",
    });
    const canvas = await post<{ id: string }>(
        `/projects/${project.id}/canvases`,
        { title: "My first canvas" },
    );

    const nodeId = crypto.randomUUID();
    await post(`/canvases/${canvas.id}/direct/nodes`, {
        id: nodeId,
        nodeType: "image",
        geometry: { x: 0, y: 0, w: 380, h: 632 },
        textPrompt: "a golden retriever puppy in a field",
    });

    const runKey = crypto.randomUUID();
    const run = await post<{ id: string }>(
        `/nodes/${nodeId}/runs`,
        {
            canvasId: canvas.id,
        },
        runKey,
    );

    let status: string;
    do {
        await new Promise((r) => setTimeout(r, 2000));
        ({ status } = await get<{ status: string }>(`/node-runs/${run.id}`));
    } while (status !== "finished" && status !== "failed");

    const result = await post<{ url: string }>(
        `/node-runs/${run.id}/download`,
        {},
    );
    console.log(result.url);
}

main();
```

```php PHP theme={null}
<?php
$KEY = "mel_...";
$BASE = "https://api.melius.com/api/v1";

function call($method, $path, $body = null, $idempotencyKey = null) {
    global $KEY, $BASE;
    $headers = ["Authorization: Bearer $KEY", "Content-Type: application/json"];
    if ($idempotencyKey !== null) {
        $headers[] = "Idempotency-Key: $idempotencyKey";
    }
    $ch = curl_init("$BASE$path");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POSTFIELDS => $body === null ? null : json_encode($body),
    ]);
    return json_decode(curl_exec($ch), true);
}

function uuidv4() {
    $d = random_bytes(16);
    $d[6] = chr(ord($d[6]) & 0x0f | 0x40);
    $d[8] = chr(ord($d[8]) & 0x3f | 0x80);
    return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($d), 4));
}

$project = call("POST", "/projects", ["title" => "My first project"]);
$canvas = call("POST", "/projects/{$project['id']}/canvases", ["title" => "My first canvas"]);

$nodeId = uuidv4();
call("POST", "/canvases/{$canvas['id']}/direct/nodes", [
    "id" => $nodeId,
    "nodeType" => "image",
    "geometry" => ["x" => 0, "y" => 0, "w" => 380, "h" => 632],
    "textPrompt" => "a golden retriever puppy in a field",
]);

$runKey = uuidv4();
$run = call("POST", "/nodes/$nodeId/runs", ["canvasId" => $canvas["id"]], $runKey);

do {
    sleep(2);
    $status = call("GET", "/node-runs/{$run['id']}")["status"];
} while ($status !== "finished" && $status !== "failed");

$result = call("POST", "/node-runs/{$run['id']}/download", new stdClass());
echo $result["url"] . "\n";
```

```go Go theme={null}
package main

import (
	"bytes"
	"crypto/rand"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"time"
)

const key = "mel_..."
const base = "https://api.melius.com/api/v1"

func call(method, path string, body any, idempotencyKeys ...string) map[string]any {
	var buf io.Reader
	if body != nil {
		b, _ := json.Marshal(body)
		buf = bytes.NewReader(b)
	}
	req, _ := http.NewRequest(method, base+path, buf)
	req.Header.Set("Authorization", "Bearer "+key)
	req.Header.Set("Content-Type", "application/json")
	if len(idempotencyKeys) > 0 {
		req.Header.Set("Idempotency-Key", idempotencyKeys[0])
	}
	resp, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()
	data, _ := io.ReadAll(resp.Body)
	var out map[string]any
	json.Unmarshal(data, &out)
	return out
}

func uuidv4() string {
	b := make([]byte, 16)
	rand.Read(b)
	b[6] = (b[6] & 0x0f) | 0x40
	b[8] = (b[8] & 0x3f) | 0x80
	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16])
}

func main() {
	project := call("POST", "/projects", map[string]any{"title": "My first project"})
	canvas := call("POST", fmt.Sprintf("/projects/%s/canvases", project["id"]), map[string]any{"title": "My first canvas"})

	nodeID := uuidv4()
	call("POST", fmt.Sprintf("/canvases/%s/direct/nodes", canvas["id"]), map[string]any{
		"id":         nodeID,
		"nodeType":   "image",
		"geometry":   map[string]any{"x": 0, "y": 0, "w": 380, "h": 632},
		"textPrompt": "a golden retriever puppy in a field",
	})

	runKey := uuidv4()
	run := call("POST", fmt.Sprintf("/nodes/%s/runs", nodeID), map[string]any{"canvasId": canvas["id"]}, runKey)

	status := ""
	for status != "finished" && status != "failed" {
		time.Sleep(2 * time.Second)
		status, _ = call("GET", fmt.Sprintf("/node-runs/%s", run["id"]), nil)["status"].(string)
	}

	result := call("POST", fmt.Sprintf("/node-runs/%s/download", run["id"]), map[string]any{})
	fmt.Println(result["url"])
}
```

```ruby Ruby theme={null}
require "net/http"
require "json"
require "securerandom"

KEY = "mel_..."
BASE = "https://api.melius.com/api/v1"

def call(method, path, body = nil, idempotency_key: nil)
  uri = URI("#{BASE}#{path}")
  req = (method == "GET" ? Net::HTTP::Get : Net::HTTP::Post).new(uri)
  req["Authorization"] = "Bearer #{KEY}"
  req["Content-Type"] = "application/json"
  req["Idempotency-Key"] = idempotency_key if idempotency_key
  req.body = body.to_json if body
  res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
  JSON.parse(res.body)
end

project = call("POST", "/projects", { title: "My first project" })
canvas = call("POST", "/projects/#{project['id']}/canvases", { title: "My first canvas" })

node_id = SecureRandom.uuid
call("POST", "/canvases/#{canvas['id']}/direct/nodes", {
  id: node_id,
  nodeType: "image",
  geometry: { x: 0, y: 0, w: 380, h: 632 },
  textPrompt: "a golden retriever puppy in a field",
})

run_key = SecureRandom.uuid
run = call("POST", "/nodes/#{node_id}/runs", { canvasId: canvas["id"] }, idempotency_key: run_key)

status = nil
until ["finished", "failed"].include?(status)
  sleep 2
  status = call("GET", "/node-runs/#{run['id']}")["status"]
end

result = call("POST", "/node-runs/#{run['id']}/download", {})
puts result["url"]
```

No model is specified, so Melius picks one for you. To choose a specific model, add a `modelConfig` to the node from [List generative models](https://docs.melius.com/api/overview.md). The `x-team-id` header is optional — requests default to the team your key belongs to.

Save the run key and request before submission. If starting the run times out or returns `5xx`, resend only that run request with the same key, body and acting context. The server replays the accepted status and response without starting another run. For `409` with `IDEMPOTENCY_REQUEST_IN_PROGRESS`, wait at least the `Retry-After` value of one second before retrying. `IDEMPOTENCY_KEY_REUSED` means the request changed; use a fresh key only when you intend a new run.

Rerunning the entire snippet creates a new project, canvas, node and run. Those setup mutations are outside idempotency coverage. See [Retry a submission safely](https://docs.melius.com/api/overview.md#retry-a-submission-safely) for key scope, conflicts and retention.

## Next steps

> [card] [Authentication](https://docs.melius.com/api/authentication.md)
>
> Keys, the `x-team-id` header, and how keys are scoped.

> [card] [API overview](https://docs.melius.com/api/overview.md)
>
> The base URL, how generations work, rate limits, and credits.

## Run with media URLs

Send `mediaUrls` on `POST /nodes/{nodeId}/runs` to run an image or video node directly from public media files:

```json theme={null}
{
    "canvasId": "YOUR_CANVAS_ID",
    "mediaUrls": {
        "imageUrls": ["https://example.com/start.png"],
        "endImageUrls": ["https://example.com/end.png"]
    }
}
```

Inside `mediaUrls`, `imageUrls` supplies start frames, `endImageUrls` supplies the end frame, `referenceImageUrls` supplies reference images, `videoUrls` supplies input clips, and `audioUrls` supplies audio. Send the roles your chosen model supports. The start-frame role is independent of the canvas's generic `image` handle.

Use this option on a node with text inputs only, and omit top-level `imageUrls`, `endImageUrls` and `draftVersionId`. Melius checks each URL and reads the file's dimensions, size and duration before billing. Each file can be up to 50 MB; the model's own limits still apply. Unsupported roles and clips that require automatic trimming are rejected.

The explicit URL path also rejects images outside the model’s dimension and aspect-ratio limits; resize or crop them before submitting.

These references are used for this run. They stay outside your asset library and receive no automatic captions. Keep the URLs accessible until the run finishes: the generation provider fetches them asynchronously. For reusable references on your canvas, use [uploads](https://docs.melius.com/uploads/overview.md) and connect the resulting file nodes. Completing an upload stores the file; create the file node with the `s3Key`, `s3Bucket` and `contentType` the upload used, then connect it. Connect a start frame to the `starting_image` handle: on a model with a reference mode, the generic `image` handle takes a reference image ([video input handles](https://docs.melius.com/canvas/video.md#input-handles)).

Reference-to-video and video editing have different duration rules. Wan 3.0 reference-to-video accepts the requested output duration, subject to its reference and output limits. Modes that derive their length from a source clip use that clip’s duration. Image-to-video modes can derive the output shape from the start frame. Check the selected mode’s catalog settings before validating an output against your requested duration or aspect ratio.

## Input limits for each mode

Call `GET /generation/models?category=video` to read the inputs and limits of every video mode before you build a request. Each entry in a model's `variants` describes one mode:

| Field | What it tells you |
| - | - |
| `requiredInputs`, `optionalInputs` | The inputs the mode takes. `image_url` is a start frame, `end_image_url` an end frame and `reference_image_url` a reference image. |
| `maxReferenceImageInputs` | The most reference images the mode takes. |
| `maxReferenceImagesWithStartImage`, `maxReferenceImagesWithEndImage` | The lower reference-image limit when you also send a start frame or an end frame. |
| `maxVideoInputs` | The most input clips the mode takes. |
| `maxInputVideoDurationSeconds`, `maxCombinedInputVideoDurationSeconds` | The longest input clip, and the longest total across all input clips. |
| `startFrameSetsAspectRatio` | `true` when a start frame sets the output aspect ratio in place of the one you send. |

For example, Kling 4's `reference-to-video` mode takes 10 reference images on their own, 9 with a start frame and 8 with an end frame, and its start frame sets the aspect ratio. Wan 3.0's `reference-to-video` mode takes no start or end frame.

A mode that lists `duration` renders the length you request, except Seedance 2.5 with exactly one input clip and no other references, which sets its own length. A mode that doesn't list `duration` sets its own length: an editing or lip-sync mode renders at its input clip's length, and other modes at the model's fixed length or their audio's length.

## Exact settings and video end frames

Set `strictSettings: true` when creating a node and when starting its run to reject unsupported aspect ratios, durations and resolutions with HTTP 400. The error message names the unsupported setting. A refused run does not start generation or spend credits. Requests that omit `strictSettings` retain normalization of unsupported settings.

A run started with `strictSettings: true` also refuses its connected inputs with HTTP 400 instead of adjusting them:

* A connected image or video the selected mode can't take. The error names the input's node.
* Input clips longer in total than the mode's combined limit. Without `strictSettings`, the last clip is trimmed to fit.

Supply the settings you require in the run request. Run settings take precedence over the saved node settings. Setting `strictSettings` only at run time cannot recover a setting an earlier non-strict create already normalized.

A video run can take a start frame in `imageUrls` and one end frame in `endImageUrls`:

```json theme={null}
{
    "strictSettings": true,
    "modelConfig": { "model": "kling-o3", "variant": "image-to-video" },
    "textPrompt": "A smooth transition between the two frames",
    "outputResolution": "1080p",
    "outputDuration": 5,
    "imageUrls": ["https://example.com/start.png"],
    "endImageUrls": ["https://example.com/end.png"]
}
```

Send this body to `POST /nodes/{nodeId}/runs` for a video node. Use publicly reachable image URLs. A start or end frame URL that cannot be read as an image returns HTTP 400 before the run is charged. A connected start frame takes precedence over `imageUrls`; an end-frame URL can also accompany that connected start frame. A request with both an end-frame URL and a connected end frame is refused. End-frame URLs require a model that supports start/end frames and cannot be combined with reference-image inputs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.