our logo

Music Generation API Documentation

These endpoints let you generate short music clips directly from text prompts. Use them for background scores, product soundtracks, or creative tools inside your own apps.

Introduction

The Music Generation APIs use Vertex AI music models to turn natural‑language descriptions into fully rendered audio. You can choose the standard model or the Lyria 2 model for more expressive instrumentals.

Common use cases include:

  • Automatically generating background music for videos and social posts.
  • Adding custom loops or stingers to games and interactive experiences.
  • Building creative music toys or inspiration tools for artists.

Base URL

https://taiapi.aiphotocraft.com/

Authentication

All music endpoints require an API key. You can create and manage keys in the Developer Dashboard.

API Key Header

Include your key in the following header:

X-Api-Key: YOUR_API_KEY

Example Request

curl -X POST "https://taiapi.aiphotocraft.com/api/music_generate" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "uplifting electronic track with soft piano and warm pads"
  }'

Best practices

Music generation can take a few seconds. Consider running requests asynchronously and streaming progress to your users.

Music generation

Music Generate

POST/api/music_generate

Generate music from a text prompt using Vertex AI music models. Ideal for background scores, jingles, and creative experiments.

Parameters

NameTypeRequiredDescription
promptstring (formData or JSON)RequiredText prompt describing the desired music (genre, mood, instruments, etc.).
durationSecondsinteger (formData or JSON)OptionalDesired duration of the music in seconds (1–300). Defaults to 30.
sampleCountinteger (formData or JSON)OptionalNumber of music samples to generate (1–4). Defaults to 1.
bodyobject (JSON body)OptionalOptional JSON body with prompt, durationSeconds, and sampleCount when sending multipart requests.

Task Status Endpoint

GET/api/task-status/{task_id}

Get the status of a task and retrieve the processed image URL.

NameTypeRequiredDescription
task_idstring (path)RequiredThe ID of the task to get the status for.

Example Request

curl -X GET "https://taiapi.aiphotocraft.com/api/task-status/{task_id}"-H "accept: application/json"-H "X-Api-Key: YOUR_API_KEY"

Example Response

{
  "image_url": "https://taiapi.aiphotocraft.com/results/swapped_image.jpg"
}

Response Status Codes

Status CodeDescription
200Successfully retrieved task status.
400Bad request.
401Unauthorized.

Examples

import requests

url = "https://taiapi.aiphotocraft.com/api/music_generate"
headers = {
    "X-Api-Key": "YOUR_API_KEY",
    "accept": "application/json",
    "Content-Type": "application/json",
}

payload = {
    "prompt": "uplifting electronic track with soft piano and warm pads",
    "durationSeconds": 30,
    "sampleCount": 1,
}

response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
data = response.json()
print("Music URL:", data.get("audio_url"))

Music Generate Lyria

POST/api/music_generate_lyria

Generate instrumental music tracks from text using the Lyria 2 model. Designed for high‑quality, expressive instrumentals.

Parameters

NameTypeRequiredDescription
promptstring (JSON body)RequiredMain text prompt describing the desired instrumental track (melody, emotion, instruments, etc.).
negative_promptstring (JSON body)OptionalOptional negative prompt describing what to avoid (for example, "dissonant, minor key").
sampleCountinteger (JSON body)OptionalNumber of music samples to generate (1–4). Defaults to 1.
bodyobject (JSON body)RequiredTop-level JSON object containing prompt, negative_prompt, sampleCount, and seed (see example body below).

Task Status Endpoint

GET/api/task-status/{task_id}

Get the status of a task and retrieve the processed image URL.

NameTypeRequiredDescription
task_idstring (path)RequiredThe ID of the task to get the status for.

Example Request

curl -X GET "https://taiapi.aiphotocraft.com/api/task-status/{task_id}"-H "accept: application/json"-H "X-Api-Key: YOUR_API_KEY"

Example Response

{
  "image_url": "https://taiapi.aiphotocraft.com/results/swapped_image.jpg"
}

Response Status Codes

Status CodeDescription
200Successfully retrieved task status.
400Bad request.
401Unauthorized.

Examples

import requests

url = "https://taiapi.aiphotocraft.com/api/music_generate_lyria"
headers = {
    "X-Api-Key": "YOUR_API_KEY",
    "accept": "application/json",
    "Content-Type": "application/json",
}

payload = {
    "prompt": "An uplifting and hopeful orchestral piece with soaring strings.",
    "negative_prompt": "dissonant, minor key",
    "sampleCount": 1,
    "seed": 0,
}

response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
data = response.json()
print("Lyria music URL:", data.get("audio_url"))