Developer documentation

CandyMuse API

Create images from a required text prompt, optionally guided by a reference image, or generate native-audio videos through one durable asynchronous task contract.

https://candymuse.ai/apiBase URL

Create your first task

Send a required text prompt. A reference image is optional. The response is a task; generation continues after the request returns.

Create an image from a prompt
curl -X POST https://candymuse.ai/api/create_image \
  -H "API-KEY: $API_KEY" \
  -H "Idempotency-Key: your-unique-request-id" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A cinematic night portrait with soft neon light",
    "quality": "low"
  }'
Use an idempotency key.

It is optional for compatibility, but an exact retry with the same key returns the original task and never charges twice.

Send your API key as a header

Create, task polling, balance, and canonical result requests require the same API-KEY header. The completed task's short-lived output_url does not require that header. Keep both credentials server-side.

HeaderRequiredValue
API-KEYYesYour CandyMuse API key
Content-TypeCreate onlyapplication/json
Idempotency-KeyRecommended8–128 characters; start alphanumeric, then letters, digits, ., _, :, or -
Never expose your key in browser code.

Calls should originate from your backend. Result capability URLs are short-lived bearer credentials and should also be treated as private.

Prompt-based image generation

POST/api/create_image

A prompt is required. Include input_image_base64 only when a reference should guide the generated image. Image requests do not select a preset.

Prompt-only image
curl -X POST https://candymuse.ai/api/create_image \
  -H "API-KEY: $API_KEY" \
  -H "Idempotency-Key: your-unique-request-id" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A cinematic night portrait with soft neon light",
    "quality": "low"
  }'

Guide the result with a reference

Add a PNG, JPEG, or WebP reference while keeping the prompt. The reference is optional for both quality levels.

Optional reference · high quality
curl -X POST https://candymuse.ai/api/create_image \
  -H "API-KEY: $API_KEY" \
  -H "Idempotency-Key: your-unique-request-id" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Use the reference subject in a cinematic night portrait with soft neon light",
    "input_image_base64": "<BASE64_IMAGE>",
    "quality": "high"
  }'
FieldTypeContract
promptstringRequired. After trimming, 1–1,000 characters.
input_image_base64stringOptional. PNG, JPEG, or WebP; raw base64 or a matching data URL.
qualitystringOptional; defaults to low. Accepted values are low and high.

These are the complete Image API fields. Any additional field is rejected.

$0.020 / $0.025 low / high per accepted task; a terminal failure is refunded once in full.

Native-audio video generation

POST/api/create_video
POST/api/create_audio_video

Both paths address the same production pipeline. Every completed result contains H.264 video and native AAC audio.

Create a native-audio video
curl -X POST https://candymuse.ai/api/create_video \
  -H "API-KEY: $API_KEY" \
  -H "Idempotency-Key: your-unique-request-id" \
  -H "Content-Type: application/json" \
  -d '{
    "input_image_base64": "...",
    "preset_name": "default",
    "quality": "low",
    "video_length": "5s",
    "age_check": true
  }'
FieldTypeContract
input_image_base64stringRequired. PNG, JPEG, or WebP; raw base64 or a matching data URL.
preset_namestringRequired. One published preset listed below.
qualitystringOptional; only low is accepted.
video_lengthstringOptional; only 5s is accepted.
promptstringNot accepted for published video presets.
age_checkbooleanOptional; explicit false is rejected.
defaultblowjob_povcumshotfront_doggystylemissionary_povsquatting_cowgirl
Video preset names are case-sensitive.

Use one of the six public values above. Image requests do not use presets.

$0.150 charged when accepted; a terminal failure is refunded once in full.

Poll once, download privately

GET/api/task/{task_id}

Poll every 6–10 seconds and respect Retry-After. Stop when the task reaches COMPLETED or FAILED.

Poll a task
curl https://candymuse.ai/api/task/$TASK_ID \
  -H "API-KEY: $API_KEY"
NEWPROCESSINGCOMPLETEDFAILED is terminal and may occur from either active state.
Completed task response
{
  "id": "job_...",
  "created_at": "2026-08-14T01:23:45.000000Z",
  "updated_at": "2026-08-14T01:24:08.000000Z",
  "status": "COMPLETED",
  "task_message": null,
  "preset_name": null,
  "prompt": null,
  "input_image_url": null,
  "input_image2_url": null,
  "output_url": "https://candymuse.ai/api/result-cap/...",
  "tasks_in_queue": null,
  "cost_symbol": "USD",
  "cost_amount": "0.020",
  "quality": "low",
  "input_image_provided": false
}

The response always includes the fields shown above. prompt is never echoed, an image task returns preset_name as null, later task reads normally return input_image_url as null, output_url appears only after completion, and a failed task carries its error in task_message.

Download the result

A completed task includes a 6-hour output_url bearer credential. It supports bare GET, HEAD, and one HTTP byte range. Do not log or share the complete URL. Fetching the completed task again signs a fresh 6-hour URL without rerunning or recharging the task.

For a stable authenticated path, use GET or HEAD /api/result/{task_id} with API-KEY; a single byte Range is also supported. Results are streamed through CandyMuse, so private storage keys are never exposed.

Predictable JSON errors

Error response
{
  "error": {
    "code": "invalid_request",
    "message": "Request fields are invalid."
  }
}

Validation and operation errors use the envelope above. Missing or invalid keys on create, task, and balance routes currently use FastAPI's {"detail":"..."} authentication response.

StatusMeaning
401 / 403Missing or invalid API key.
402Insufficient balance.
404Task not found, or a result capability is invalid or expired.
409Idempotency, upload, or result-state conflict.
413 / 415 / 422Body, content type, image, field, preset, or quality validation failed.
416Invalid, unsatisfiable, or multiple byte ranges.
429Rate or active-job limit. Respect Retry-After.
502 / 503Storage or GPU worker is temporarily unavailable.
  • Maximum JSON request body: 22,020,096 bytes.
  • Maximum decoded image size: 15 MiB (15,728,640 bytes).
  • Minimum image dimensions: 64 pixels on each side.
  • Maximum decoded image area: 16,000,000 pixels.
  • Controlled beta default: 12 create, task-poll, or balance requests per key per fixed minute.
  • Authenticated invalid requests also consume that fixed-window request allowance.
  • Controlled beta default: 2 active jobs per key and 4 per account.

Supporting endpoints

GET/api/balance

Returns symbol, available_amount, and frozen_amount as decimal strings.

GET/api/healthz

Unauthenticated service health. A healthy production response reports S3 storage.

Controlled compatibility beta

The documented image qualities, video presets, and video duration are the complete supported contract today. Unsupported combinations fail explicitly and are not billed.