Quickstart

Create an API key, choose a model contract, submit an image task, and download its result safely.

This guide makes one image through an asynchronous model task. Choose the endpoint from the live model contract: image output does not imply /v1/images/generations. The commands require Bash, cURL, OpenSSL and jq. Running the generation POST uses your balance; reading documentation is free.

1. Create your account and API key

Sign up, then open Balance to check or top up your balance. In API keys, create a key with the required model permissions and sufficient quota. Save it securely; keep it in a server environment variable, never in browser code or a public repository.

export MUSESPAN_API_BASE="https://api.musespan.com"
export MUSESPAN_API_KEY="your-api-key-here"

Replace the placeholder key before calling. MUSESPAN_API_BASE is the generation API origin, without /v1. On the public service it is https://api.musespan.com; the environment block above and the selected OpenAPI servers are authoritative for this deployment. The website hosts the model catalog, discovery JSON, and agent index. Do not confuse the website origin with the generation API origin.

Send Authorization: Bearer <API_KEY> to the platform API. Never forward your key to a provider or an arbitrary result URL.

2. Choose the exact model and contract

Open Models and select the capability you need. Copy the entry's id from GET /v1/models into model; do not invent it or substitute a provider endpoint. A group.id that differs from id is only a grouping identifier. Public discovery needs no key; supplying a Bearer key validates it but returns the same public catalog, not a permission-filtered list.

Use ?category=text-to-image to filter; for a long catalog use ?limit=100 and the returned next_cursor as after. Follow model_url for the model page and openapi_url for its exact endpoint, input constraints, output and price. ?expand=input_schema expands image-endpoint contracts; model-task inputs must be read from their own OpenAPI or model llms.txt.

The example below was checked against the public production catalog on October 20, 2026, using a listed image model and its OpenAPI. Check that it is still listed before running.

These links open in the environment you are currently viewing. Staging or private deployments may have a different catalog; this example's model page or OpenAPI can return 404 if the capability is not listed there. In that case, choose a suitable capability from this environment's catalog, follow its model_url and openapi_url, and use its complete request example, polling endpoint and output schema. Keep the API base URL and key in the same environment. Other models may require different fields, reference images or endpoints: changing only model is not enough. If no suitable capability is listed, skip the generation steps.

3. Submit your first image task

Use a new working directory for each new generation. Save this request as input.json:

{
  "model": "bytedance/seedream-5-flash/text-to-image",
  "input": {
    "prompt": "A small ceramic vase on a wooden table, soft morning light",
    "image_size": "square_hd",
    "num_images": 1,
    "output_format": "png"
  }
}

Create and save a request ID once. Rerunning this block keeps the saved ID. Keep input.json unchanged during retries.

if [ ! -s request-id.txt ]; then openssl rand -hex 16 > request-id.txt; fi
TASK_ID="$(cat request-id.txt)"
curl --fail-with-body --connect-timeout 10 --max-time 300 \
  "$MUSESPAN_API_BASE/v1/model-tasks" \
  -H "Authorization: Bearer $MUSESPAN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Request-Id: $TASK_ID" \
  --data-binary @input.json

HTTP 202 means the task is accepted; its id equals TASK_ID. A request ID is 1–128 letters, digits, _ or - (a UUID also works). Use the same key, request ID and byte-identical request body when retrying a lost response, connection failure, 429 or 5xx. This returns the existing task rather than generating or charging twice. Explicit authentication, balance or validation errors must be fixed first. A different body or key with the same ID can return 409 request_id_conflict.

4. Poll and download

With the same API key, run this GET every 5 seconds until a terminal status. Save the latest response as task.json:

TASK_ID="$(cat request-id.txt)"
curl --fail-with-body --connect-timeout 10 --max-time 30 \
  "$MUSESPAN_API_BASE/v1/model-tasks/$TASK_ID" \
  -H "Authorization: Bearer $MUSESPAN_API_KEY" \
  -o task.json && \
jq '{id, status, queue_position, error, output}' task.json
StatusWhat to do
queuedKeep polling. queue_position, when present, is an estimate (1 means next).
runningKeep polling the same task.
completedRead output using the selected model's output schema and download its declared files.
failedStop polling and inspect error.code, message and any issues. Retrying the same ID returns the same failed task; a new generation requires a new ID.

A model task waiting in the platform queue for 5 minutes fails with queue_timeout. After dispatch, no result within 15 minutes of acceptance, or an unconfirmed submission after 15 minutes, ends with generation_timeout; the hold is refunded in full. Set a finite client waiting budget of 25 minutes. Reaching that budget is not proof of failure: keep the saved ID and query it later. A GET 404 task_not_found means no task is visible to this key; verify the key and ID, then resend the unchanged POST with the same ID if submission may not have arrived.

For this model, completed output has output.images[]. Each image's url points to an authenticated platform artifact endpoint. The following downloads every declared image, accepting only this task's artifact paths on the configured API origin; it does not forward credentials to other origins:

jq -e '.status == "completed"' task.json >/dev/null && \
jq -r '.output.images[].url' task.json | while IFS= read -r url; do
  case "$url" in
    "$MUSESPAN_API_BASE"/v1/model-tasks/"$TASK_ID"/artifacts/*) path="${url#"$MUSESPAN_API_BASE"}" ;;
    /v1/model-tasks/"$TASK_ID"/artifacts/*) path="$url" ;;
    *) echo "Unexpected artifact URL" >&2; exit 1 ;;
  esac
  index="${path##*/}"
  case "$index" in ''|*[!0-9]*) echo "Invalid artifact index" >&2; exit 1 ;; esac
  [ "$path" = "/v1/model-tasks/$TASK_ID/artifacts/$index" ] || exit 1
  curl --fail-with-body --connect-timeout 10 --max-time 120 \
    "$MUSESPAN_API_BASE$path" \
    -H "Authorization: Bearer $MUSESPAN_API_KEY" \
    -o "output-$index.png" || exit 1
done

This example requests PNG, so it saves .png; other models can return different media or nested output shapes. Model-task files arrive as application/octet-stream: inspect file headers when the format is not known. Download promptly. An expired or unavailable download does not mean generation failed or justify a new POST. Do not assume image-task retention guarantees apply to model tasks.

5. Endpoint differences and safe retries

Use only an endpoint declared by a currently listed capability. These are different contracts, not interchangeable ways to call every model:

ContractRequest and resultRetry policy
/v1/model-tasks{model, input}; poll /v1/model-tasks/{id}; read model-specific output and authenticated artifacts. Used by this tutorial and current image/speech model tasks.Required X-Request-Id; resend identical bytes with the same key and ID.
/v1/images/tasksImage parameters at the top level; poll its own task endpoint; completed images in data[].url.Idempotent with the same key, ID and request.
/v1/images/generationsSynchronous image parameters at the top level; successful response has data[].No request-ID deduplication. Do not automatically resend a POST.
/v1/videosVideo-specific request; save returned ID, poll /v1/videos/{id}, then download /content with the same key.No request-ID deduplication. Do not automatically resend a POST.

For image editing, supply reference images in the format and quantity the selected schema permits. For speech, use the declared text field within input; do not reuse this image request. If the catalog has no listed capability for an endpoint, do not use it. Model pages provide the complete generated examples for their own contract.

For image tasks specifically, pending states include submitting, queued, in_progress and submission_unknown; phase: "result_processing" means results are being stored. Poll for up to 20 minutes, then retain the ID for later checks. New stored image-task results have a 7-day availability guarantee (result_expires_at), signed links last up to 60 minutes, and task/idempotency records are retained at least 30 days (retention_guaranteed_until). Re-query a completed task to refresh links within its result lifetime. result_availability: "expired" keeps status completed but removes download URLs; historical legacy results do not have this storage guarantee. Image tasks cannot currently be cancelled. Model tasks can be cancelled only while waiting in the queue via POST /v1/model-tasks/{id}/cancel.

6. Balance, settlement and next steps

Read current pricing before submitting. A prepayment holds balance; it is not a final bill or a cap on the final charge. Successful requests settle on actual usage: unused funds are released and excess usage is debited, possibly making the balance negative. New requests are paused until a top-up covers the debt. Confirmed failed generations are not charged; client timeouts and lost responses are not confirmed failures. Completion and settlement can occur at different times.

See Errors & billing for recovery and hold calculations. Check Usage logs before repeating a non-idempotent request. Keep the task ID for support and redact your API key and signed result URLs.

We use necessary cookies to run the site. With your consent we also use optional analytics. Privacy Policy