Generation APIs/Audio

Generate Audio

POST

Overview

Submit an audio generation task through API Mall. This route is currently backed by the same implementation as the music endpoints and returns a task ID that you should poll through the audio task 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/audio/generate
  • Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
prompt
stringOptional

Prompt or lyric instruction. Required unless `customMode` provides a full structured workflow.

style
stringOptional

Style tags or genre description used in custom mode.

title
stringOptional

Track title used in custom mode.

customMode
booleanOptional

Enable the structured custom Suno workflow.

instrumental
booleanOptional

Generate an instrumental track without vocals.

model
string
V4V4_5V4_5PLUS
Optional

Model identifier for this endpoint.

Default: V5

negativeTags
stringOptional

Negative tags used to exclude unwanted styles or content.

vocalGender
string
mf
Optional

Preferred vocal gender when vocals are enabled.

styleWeight
numberOptional

Weight assigned to the `style` prompt.

weirdnessConstraint
numberOptional

Creativity control for the model.

audioWeight
numberOptional

Weight assigned to any audio-conditioning input.

personaId
stringOptional

Optional persona ID for compatible provider workflows.

Request Example

{
  "model": "V5",
  "prompt": "An uplifting synth-pop track about late-night coding.",
  "instrumental": false
}

Response Example

{
  "success": true,
  "data": {
    "task_id": "aud_01HQ9MB2J3RWB1V8Y5B9H8M2QK",
    "request_id": "suno_req_01HQ9MBE2M6R6A0Z8KQ2P7P4FV",
    "credits_used": 12,
    "remaining_credits": 108,
    "model": "V5"
  },
  "request_id": "req_01HQ9M7J7X9P7Y8T6W5V4U3S2R"
}

cURL Example

curl --request POST 'https://gateway.apimall.ai/api/v1/audio/generate' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "V5",
  "prompt": "An uplifting synth-pop track about late-night coding.",
  "instrumental": false
}'

JavaScript Example

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

const payload = {
  "model": "V5",
  "prompt": "An uplifting synth-pop track about late-night coding.",
  "instrumental": 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/audio/${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/audio/{task_id}

Path Parameters

ParameterTypeRequiredDescription
task_id
stringRequired

Audio task identifier returned by `POST /api/v1/audio/generate`.

Request Example

GET https://gateway.apimall.ai/api/v1/audio/aud_01HQ9MB2J3RWB1V8Y5B9H8M2QK

cURL Example

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

Response Example

{
  "success": true,
  "data": {
    "task_id": "aud_01HQ9MB2J3RWB1V8Y5B9H8M2QK",
    "model": "V5",
    "status": "completed",
    "output": {
      "tracks": [
        {
          "audioUrl": "https://cdn.apimall.ai/generated/audio-01.mp3",
          "imageUrl": "https://cdn.apimall.ai/generated/audio-cover-01.webp"
        }
      ]
    },
    "audio_url": "https://cdn.apimall.ai/generated/result.mp3",
    "image_url": "https://cdn.apimall.ai/generated/cover.webp",
    "error_message": null,
    "credits_used": 12,
    "credits_refunded": 0,
    "created_at": "2026-03-12T09:40:00.000Z",
    "updated_at": "2026-03-12T09:41:30.000Z",
    "completed_at": "2026-03-12T09:41:30.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.tracks
array

Generated track metadata returned by the upstream audio provider payload.

data.output.tracks[].audioUrl
string

Primary audio URL for a generated track in the provider payload.

data.output.tracks[].imageUrl
string

Cover image URL for a generated track in the provider payload.

data.audio_url
string

Hosted audio result URL.

data.image_url
string

Hosted image 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/audio/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/audio/{task_id}` until `data.status` reaches `completed` or `failed`.
  4. Read the generated audio 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.audio_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 Audio - API Reference | API Mall | API Mall