Generation APIs/Videos

Generate Videos

POST

Overview

Submit a unified video generation task through API Mall. This endpoint is the real public contract for Sora, Veo, Wan, Kling, Hailuo, Seedance, and other supported video models, exposed as a single model-driven API.

Authentication

All API requests require a Bearer token in the request header.

Authorization: Bearer YOUR_API_KEY

Create and manage API keys from API Keys or use https://www.apimall.ai/api-keys.

1. Create Generation Task

API Information

  • URL: POST https://gateway.apimall.ai/api/v1/videos/generate
  • Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
model
string
sora2sora2-stablesora2-pro
Required

Model identifier for this endpoint.

Default: sora2

type
string
text-to-videoimage-to-videovideo-to-video
Optional

Task mode for the selected model.

Default: text-to-video

prompt
stringOptional

Prompt or edit instruction for the video generation task.

input_image
stringOptional

Single reference image URL for image-to-video workflows.

image_urls
arrayOptional

Reference image URLs for image-to-video or multi-image workflows.

image_url
stringOptional

Legacy single-image alias used by some provider adapters.

video_url
stringOptional

Source video URL for video-to-video or edit workflows.

audio_url
stringOptional

Audio track URL for avatar or audio-conditioned video workflows.

end_image_url
stringOptional

Optional ending frame URL for supported models.

hailuo_model
stringOptional

Explicit Hailuo provider model override.

origin_task_id
stringOptional

Original task ID for follow-up or character continuation workflows.

character_user_name
stringOptional

Character name used by Sora character continuation workflows.

character_prompt
stringOptional

Character creation prompt used by Sora character workflows.

safety_instruction
stringOptional

Additional safety instruction passed to supported providers.

upload_method
string
s3oss
Optional

Provider-side storage target for compatible models.

aspect_ratio
stringOptional

Aspect ratio or layout preset for supported models.

mode_option
string
normalfunspicy
Optional

Sora creative mode option.

n_frames
string
51015
Optional

Sora frame count option.

size
string
standardhigh
Optional

Provider-specific quality or size tier.

remove_watermark
booleanOptional

Remove provider watermark when supported.

character_id_list
arrayOptional

Character branch IDs for Sora continuation workflows.

progress_callback_url
stringOptional

Optional callback URL for intermediate progress updates.

  • API Mall will POST JSON progress events to this URL when available
  • To ensure callback security, see Webhook Verification Guide for signature verification implementation
progressCallBackUrl
stringOptional

Optional callback URL for intermediate progress updates.

  • API Mall will POST JSON progress events to this URL when available
  • To ensure callback security, see Webhook Verification Guide for signature verification implementation
generation_type
string
FIRST_AND_LAST_FRAMES_2_VIDEOREFERENCE_2_VIDEO
Optional

Veo generation mode for frame-conditioned jobs.

watermark
boolean | stringOptional

Provider watermark control where supported.

seeds
integer | arrayOptional

Optional deterministic seed or list of seeds.

enable_fallback
booleanOptional

Allow fallback generation behavior when supported.

enable_translation
booleanOptional

Enable prompt translation for providers that support it.

duration
stringOptional

Video duration in seconds.

resolution
stringOptional

Requested resolution tier for supported models.

negative_prompt
stringOptional

Negative prompt passed to models that support it.

enable_prompt_expansion
booleanOptional

Let the provider expand the prompt before generation.

seed
integerOptional

Optional random seed for supported models.

sound
booleanOptional

Enable synced sound generation for supported video models.

quality
stringOptional

Kling quality tier.

audio
booleanOptional

Enable audio synthesis when supported.

cfg_scale
numberOptional

Guidance scale for supported edit workflows.

Range: 0 - 1

character_orientation
string
imagevideo
Optional

Kling avatar orientation mode.

multi_shots
booleanOptional

Enable multi-shot generation for supported Kling models.

fixed_lens
booleanOptional

Lock the camera lens for supported Seedance models.

generate_audio
booleanOptional

Generate audio together with the video on supported models.

Request Example

{
  "model": "sora2",
  "type": "text-to-video",
  "prompt": "A cinematic drone shot of a futuristic city at sunrise.",
  "aspect_ratio": "landscape",
  "n_frames": "10",
  "remove_watermark": false
}

Response Example

{
  "success": true,
  "data": {
    "task_id": "vid_01HQ9MA3M6V6HC6S5R9V7N4Q4D",
    "request_id": "provider_req_01HQ9MAGWQJZ0RZN6G40YRMN6E",
    "credits_used": 30,
    "remaining_credits": 90,
    "model": "sora2"
  },
  "request_id": "req_01HQ9M7J7X9P7Y8T6W5V4U3S2R"
}

cURL Example

curl --request POST 'https://gateway.apimall.ai/api/v1/videos/generate' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "sora2",
  "type": "text-to-video",
  "prompt": "A cinematic drone shot of a futuristic city at sunrise.",
  "aspect_ratio": "landscape",
  "n_frames": "10",
  "remove_watermark": false
}'

JavaScript Example

const API_KEY = process.env.APIMALL_API_KEY;
const CREATE_URL = 'https://gateway.apimall.ai/api/v1/videos/generate';

const payload = {
  "model": "sora2",
  "type": "text-to-video",
  "prompt": "A cinematic drone shot of a futuristic city at sunrise.",
  "aspect_ratio": "landscape",
  "n_frames": "10",
  "remove_watermark": false
};

async function createTask() {
  const response = await fetch(CREATE_URL, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(payload),
  });

  if (!response.ok) {
    throw new Error(`Create task failed: ${response.status} ${response.statusText}`);
  }

  const json = await response.json();
  const taskId = json.data?.task_id;

  if (!taskId) {
    throw new Error('Missing task_id in create response');
  }

  return taskId;
}

async function getTask(taskId) {
  const response = await fetch(`https://gateway.apimall.ai/api/v1/videos/${encodeURIComponent(String(taskId))}`, {
    headers: {
      Authorization: `Bearer ${API_KEY}`,
    },
  });

  if (!response.ok) {
    throw new Error(`Query task failed: ${response.status} ${response.statusText}`);
  }

  const json = await response.json();
  return {
    ...json,
  };
}

async function waitForTask(taskId) {
  while (true) {
    const task = await getTask(taskId);
    const state = task.data?.status;

    if (state === 'completed') {
      return task;
    }

    if (state === 'failed') {
      throw new Error(task.data?.failMsg || 'Task failed');
    }

    await new Promise((resolve) => setTimeout(resolve, 3000));
  }
}

(async () => {
  const taskId = await createTask();
  const result = await waitForTask(taskId);
  console.log(result);
})().catch(console.error);

Response Parameters

ParameterTypeDescription
success
boolean

Whether the request completed successfully.

data.task_id
string

Task ID used to query task status and results.

data.request_id
string

Provider-side request identifier for tracing.

data.credits_used
integer

Credits consumed by this request.

data.remaining_credits
integer

Credits remaining after the request.

data.model
string

Model name used for the task.

request_id
string

Request identifier for debugging and support.

Error Response Example

{
  "success": false,
  "error": {
    "code": "insufficient_credits",
    "message": "Insufficient credits"
  },
  "request_id": "req_01HQ9M7J7X9P7Y8T6W5V4U3S2R"
}

2. Query Task Status

API Information

  • URL: GET https://gateway.apimall.ai/api/v1/videos/{task_id}

Path Parameters

ParameterTypeRequiredDescription
task_id
stringRequired

Video task identifier returned by `POST /api/v1/videos/generate`.

Request Example

GET https://gateway.apimall.ai/api/v1/videos/vid_01HQ9MA3M6V6HC6S5R9V7N4Q4D

cURL Example

curl --request GET 'https://gateway.apimall.ai/api/v1/videos/vid_01HQ9MA3M6V6HC6S5R9V7N4Q4D' \
  --header 'Authorization: Bearer YOUR_API_KEY'

Response Example

{
  "success": true,
  "data": {
    "task_id": "vid_01HQ9MA3M6V6HC6S5R9V7N4Q4D",
    "model": "sora2",
    "status": "completed",
    "output": {
      "resultUrls": [
        "https://cdn.apimall.ai/generated/video-01.mp4"
      ]
    },
    "video_url": "https://cdn.apimall.ai/generated/result.mp4",
    "error_message": null,
    "credits_used": 30,
    "credits_refunded": 0,
    "created_at": "2026-03-12T09:35:00.000Z",
    "updated_at": "2026-03-12T09:36:48.000Z",
    "completed_at": "2026-03-12T09:36:48.000Z"
  },
  "request_id": "req_01HQ9M7J7X9P7Y8T6W5V4U3S2R"
}

Response Parameters

ParameterTypeDescription
success
boolean

Whether the request completed successfully.

data.task_id
string

Task ID used to query task status and results.

data.model
string

Model name used for the task.

data.status
string

Current status value returned by the API. Generation task endpoints use normalized values such as `pending`, `processing`, `completed`, `failed`, or `unknown`; management endpoints may return resource states such as `created`, `revoked`, or `active`.

data.output.resultUrls
array

Generated result URLs returned by the upstream provider payload.

data.video_url
string

Hosted video result URL.

data.error_message
string

Failure reason returned when the music task does not complete successfully.

data.credits_used
integer

Credits consumed by this request.

data.credits_refunded
integer

Credits refunded after failure or partial refund handling.

data.created_at
string

Creation timestamp for the returned resource or task record.

data.updated_at
string

Last update timestamp for the returned resource or task record.

data.completed_at
string

Completion timestamp for the task when available.

request_id
string

Request identifier for debugging and support.

Usage Flow

  1. Create a generation task by calling `POST https://gateway.apimall.ai/api/v1/videos/generate`.
  2. Persist `data.task_id` from the create response so you can resume polling later.
  3. Poll `GET https://gateway.apimall.ai/api/v1/videos/{task_id}` until `data.status` reaches `completed` or `failed`.
  4. Read the generated video URLs from the final task payload.

Integration Notes

  • Store your API key on the server side only.
  • Persist the returned `data.task_id` immediately so you can resume polling after restarts.
  • Use an `Idempotency-Key` header when retrying create requests from your backend.
  • Poll the task endpoint every few seconds with backoff until `data.status` reaches `completed` or `failed`.
  • Use `data.video_url` as the final hosted asset URL.

Error Codes

Common Error Codes

Status CodeDescription
200Request successful
400Invalid request parameters
401API key required or invalid API key
402Insufficient credits
403API access not approved or request made on a non-gateway host
409Idempotency-Key conflict
429Rate limit exceeded or too many concurrent jobs
503Upstream provider is busy or temporarily unavailable
451Prompt blocked by content moderation
500Internal server error
Generate Videos - API Reference | API Mall | API Mall