Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/anil-matcha/open-generative-ai/llms.txt

Use this file to discover all available pages before exploring further.

Open Generative AI communicates with the Muapi.ai REST API through a JavaScript client library — muapi.js — which lives in packages/studio/src/muapi.js. Every image, video, audio, lip sync, clipping, and workflow generation in the studio is routed through this file’s named exports. Developers can import these functions directly into their own applications by depending on the studio package, giving them the same API surface that powers the studio UI.

Base URL

The base URL is selected automatically by muapi.js at runtime based on the JavaScript environment:
EnvironmentBase URLWhy
Browser (HTTP/HTTPS)/apiA Next.js proxy route re-issues the request server-side, bypassing the api.muapi.ai CORS restriction
Electron desktop apphttps://api.muapi.aiThe renderer runs on file://, which is not HTTP, so requests go directly to the upstream
SSR / Node.jshttps://api.muapi.aiThere is no window object in server-side rendering, so the upstream URL is used directly
This logic is encoded in a single constant at the top of muapi.js:
const BASE_URL =
  typeof window !== 'undefined' && window.location?.protocol?.startsWith('http')
    ? '/api'
    : 'https://api.muapi.ai';
You do not need to set the base URL manually. Whether you are running the Next.js web version, the Electron desktop app, or calling the functions from server-side code, muapi.js picks the correct target automatically.

Submit-and-Poll Pattern

All AI generation endpoints on the Muapi.ai API are asynchronous. You submit a job and receive a request_id, then poll a separate result endpoint until the job finishes. muapi.js implements this pattern internally inside submitAndPoll and pollForResult, so callers just await a single function call — but understanding the underlying flow is useful when calling the API directly or debugging.
1

Submit the generation job

POST to https://api.muapi.ai/api/v1/{model-endpoint} with your prompt, parameters, and API key in the x-api-key header. The response is a JSON object containing a request_id (or id) that identifies the queued job.
2

Receive the request ID

The API immediately returns:
{ "request_id": "abc123xyz..." }
Store this value — you will need it to check the job status.
3

Poll the result endpoint

GET https://api.muapi.ai/api/v1/predictions/{request_id}/result repeatedly, waiting 2 seconds between each attempt. The response includes a status field that reflects the current state of the job.
4

Read the output URL

When data.status (lowercased) is completed, succeeded, or success, the generation is done. The output URL is resolved by checking data.outputs?.[0], then data.url, then data.output?.url (in that order). If status is failed or error, throw immediately using data.error.

Polling limits

Generation typeMax poll attemptsMax wait time
Image generation (generateImage, generateI2I)60~2 minutes
Video, audio, workflow, and all other functions900~30 minutes
5xx errors during polling are silently retried. 4xx errors throw immediately.

Minimal JavaScript example

// Step 1 — Submit the job
const res = await fetch('https://api.muapi.ai/api/v1/flux-schnell-image', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': YOUR_API_KEY
  },
  body: JSON.stringify({ prompt: 'a serene mountain lake at sunrise' })
});
const { request_id } = await res.json();

// Steps 2–4 — Poll until done
let output;
while (true) {
  await new Promise(r => setTimeout(r, 2000));
  const poll = await fetch(
    `https://api.muapi.ai/api/v1/predictions/${request_id}/result`,
    { headers: { 'x-api-key': YOUR_API_KEY } }
  );
  const data = await poll.json();
  const status = data.status?.toLowerCase();

  if (['completed', 'succeeded', 'success'].includes(status)) {
    output = data.outputs?.[0] || data.url || data.output?.url;
    break;
  }
  if (['failed', 'error'].includes(status)) {
    throw new Error(data.error || 'Generation failed');
  }
}

console.log('Generated output URL:', output);
When using the muapi.js functions (e.g. generateImage, generateVideo), the entire submit-and-poll loop runs inside the function call. You await the result and receive { ...pollData, url: outputUrl } directly — no manual polling required.

Available API Functions

The following named exports are available from packages/studio/src/muapi.js (or from the studio package). All generation functions accept (apiKey, params) and internally handle the submit-and-poll lifecycle. Generation functions — all accept (apiKey, params) and run the full submit-and-poll lifecycle internally:
FunctionDescription
generateImageText-to-image generation (50+ models). Also accepts an image_url or images_list for image-conditioned models. Max 60 poll attempts.
generateI2IImage-to-image transformation. Accepts one or more reference images; uses the model’s configured imageField to route them correctly. Max 60 poll attempts.
generateVideoText-to-video generation (40+ models). Supports aspect ratio, duration, resolution, quality, and optional image_url. Max 900 poll attempts.
generateI2VImage-to-video animation. Animates a start-frame image (or image list) into a video. Supports an optional last_image for models that accept end-frame conditioning. Max 900 poll attempts.
generateMarketingStudioAdMarketing video generation using omni-reference models. Accepts prompt, aspect_ratio, duration, images_list, and video_files. Max 900 poll attempts.
processV2VVideo-to-video transformation. Routes the video_url (and optional image_url or prompt) through the model’s configured fields. Max 900 poll attempts.
processRecastVideo recast / style transfer. Accepts video_url, optional image_url, prompt, and aspect_ratio. Max 900 poll attempts.
processLipSyncAudio-driven lip sync. Accepts audio_url and either an image_url (portrait) or video_url (existing video). Max 900 poll attempts.
generateAudioAudio generation. Passes all non-internal params through to the model endpoint. Max 900 poll attempts.
runClippingAI video clipping and highlight extraction. Accepts video_url, num_highlights, aspect_ratio, and return_coordinates_only. Endpoint: ai-clipping. Max 900 poll attempts.
runMotionGraphicsMotion graphics generation from a text prompt. Accepts prompt, aspect_ratio, and duration_seconds. Endpoint: motion-graphics. Max 900 poll attempts.
runMotionGraphicsEditEdit an existing motion graphics result. Accepts request_id, edit_prompt, aspect_ratio, and duration_seconds. Endpoint: motion-graphics-edit. Max 900 poll attempts.
File upload:
FunctionDescription
uploadFileUpload a reference image or file via multipart/form-data to POST /api/v1/upload_file. Returns the hosted file URL as a string. Accepts an optional onProgress callback.
Account:
FunctionDescription
getUserBalanceFetch the current API credit balance. Returns the full JSON response from GET /api/v1/account/balance.
calculateDynamicCostCalculate the credit cost for a given task before running it. POSTs to POST /api/v1/app/calculate_dynamic_cost.
Workflow management — CRUD and execution of Muapi workflows:
FunctionDescription
getTemplateWorkflowsFetch available template workflows from GET /workflow/get-template-workflows.
getUserWorkflowsFetch the authenticated user’s saved workflow definitions from GET /workflow/get-workflow-defs.
getPublishedWorkflowsFetch publicly published workflows from GET /workflow/get-published-workflows.
getWorkflowDataFetch the full definition of a single workflow by ID from GET /workflow/get-workflow-def/{workflowId}.
createWorkflowCreate a new workflow definition via POST /workflow/create.
updateWorkflowNameRename a workflow via POST /workflow/update-name/{workflowId}.
deleteWorkflowDelete a workflow definition via DELETE /workflow/delete-workflow-def/{workflowId}.
getWorkflowInputsFetch the API-exposed input schema for a workflow from GET /workflow/{workflowId}/api-inputs.
executeWorkflowExecute a saved workflow by workflowId. POSTs to /workflow/{workflowId}/api-execute with an inputs object, then polls /workflow/run/{runId}/api-outputs until completion.
getAllNodeSchemasFetch all node schemas for a workflow from GET /workflow/{workflowId}/node-schemas.
getNodeSchemasFetch API-exposed node schemas for a workflow from GET /workflow/{workflowId}/api-node-schemas.
runSingleNodeExecute a single node within a workflow via POST /workflow/{workflowId}/node/{nodeId}/run.
deleteNodeRunDelete a node run record via DELETE /workflow/node-run/{nodeRunId}.
getNodeStatusCheck the status of a workflow run via GET /workflow/run/{runId}/status.
Agent management:
FunctionDescription
getTemplateAgentsFetch available template agents from GET /agents/templates/agents.
getUserAgentsFetch the authenticated user’s agents from GET /agents/user/agents.
getPublishedAgentsFetch featured/published agents from GET /agents/featured/agents.
getUserConversationsFetch the user’s conversation history across all agents from GET /agents/user/conversations.
Proxy helpers (server-side use):
FunctionDescription
handleProxyRequestLow-level proxy helper that forwards a request to a given prefix/path on the upstream API, injecting x-api-key. Used by server-side routes.
handleServerSideProxyHigher-level Next.js route handler that extracts the path from params.path, reads the request body, and delegates to handleProxyRequest.
App interest:
FunctionDescription
registerAppInterestRegister user interest in an app feature via POST /app/interest.
getAppInterestsRetrieve the current user’s registered app interests from GET /app/interests.

Error Handling

muapi.js applies a consistent error strategy across all functions:
  • 4xx errors (client errors) throw immediately with the HTTP status and response body included in the error message.
  • 5xx errors (server errors) are silently skipped during polling and retried on the next interval.
  • 401 / 403 errors additionally dispatch a muapi:auth-required custom event on window (when available), which the studio UI listens to in order to show the API key entry modal.
window.addEventListener('muapi:auth-required', (event) => {
  console.log('Auth failed:', event.detail.status, event.detail.message);
  // Show your API key UI here
});
  • If submitAndPoll or pollWorkflowResult exhausts all polling attempts without a terminal status, they throw: 'Generation timed out after polling.'

Build docs developers (and LLMs) love