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_KEYExample 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
/api/music_generateGenerate music from a text prompt using Vertex AI music models. Ideal for background scores, jingles, and creative experiments.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| prompt | string (formData or JSON) | Required | Text prompt describing the desired music (genre, mood, instruments, etc.). |
| durationSeconds | integer (formData or JSON) | Optional | Desired duration of the music in seconds (1–300). Defaults to 30. |
| sampleCount | integer (formData or JSON) | Optional | Number of music samples to generate (1–4). Defaults to 1. |
| body | object (JSON body) | Optional | Optional JSON body with prompt, durationSeconds, and sampleCount when sending multipart requests. |
Task Status Endpoint
/api/task-status/{task_id}Get the status of a task and retrieve the processed image URL.
| Name | Type | Required | Description |
|---|---|---|---|
| task_id | string (path) | Required | The 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 Code | Description |
|---|---|
| 200 | Successfully retrieved task status. |
| 400 | Bad request. |
| 401 | Unauthorized. |
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
/api/music_generate_lyriaGenerate instrumental music tracks from text using the Lyria 2 model. Designed for high‑quality, expressive instrumentals.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| prompt | string (JSON body) | Required | Main text prompt describing the desired instrumental track (melody, emotion, instruments, etc.). |
| negative_prompt | string (JSON body) | Optional | Optional negative prompt describing what to avoid (for example, "dissonant, minor key"). |
| sampleCount | integer (JSON body) | Optional | Number of music samples to generate (1–4). Defaults to 1. |
| body | object (JSON body) | Required | Top-level JSON object containing prompt, negative_prompt, sampleCount, and seed (see example body below). |
Task Status Endpoint
/api/task-status/{task_id}Get the status of a task and retrieve the processed image URL.
| Name | Type | Required | Description |
|---|---|---|---|
| task_id | string (path) | Required | The 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 Code | Description |
|---|---|
| 200 | Successfully retrieved task status. |
| 400 | Bad request. |
| 401 | Unauthorized. |
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"))