import requests
url = "https://api.musicgpt.com/api/public/v1/image_to_song"
headers = {"Authorization": "<API_KEY>"}
data = {
"image_url": "https://mybucket.s3.amazonaws.com/image.png",
"prompt": "Generate a relaxing acoustic track inspired by this scene.",
"lyrics": "Let the colors of the sunset fill your heart.",
"make_instrumental": False,
"vocal_only": False,
"key": "C major",
"bpm": 120,
"webhook_url": "https://example.com/webhook",
"voice_id": "voice_123"
}
# Option 1: Using image URL
response = requests.post(url, headers=headers, data=data)
print(response.json())
# Option 2: Uploading a local image file
# with open("image.png", "rb") as f:
# files = {"image_file": f}
# response = requests.post(url, headers=headers, data=data, files=files)
# print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/image_to_song \
--header 'Authorization: <api-key>' \
--header 'Content-Type: multipart/form-data' \
--form 'image_file=<string>' \
--form image_url=https://mybucket.s3.amazonaws.com/image.png \
--form 'prompt=Generate a relaxing acoustic track inspired by this scene.' \
--form 'lyrics=Let the colors of the sunset fill your heart.' \
--form 'negative_tags=no heavy metal, avoid loud drums' \
--form make_instrumental=false \
--form vocal_only=false \
--form 'key=C major' \
--form bpm=0 \
--form webhook_url=https://example.com/webhook \
--form 'voice_id=<string>' \
--form 0.image_file='@example-file' \
--form 1.image_file='@example-file'const form = new FormData();
form.append('image_file', '<string>');
form.append('image_url', 'https://mybucket.s3.amazonaws.com/image.png');
form.append('prompt', 'Generate a relaxing acoustic track inspired by this scene.');
form.append('lyrics', 'Let the colors of the sunset fill your heart.');
form.append('negative_tags', 'no heavy metal, avoid loud drums');
form.append('make_instrumental', 'false');
form.append('vocal_only', 'false');
form.append('key', 'C major');
form.append('bpm', '0');
form.append('webhook_url', 'https://example.com/webhook');
form.append('voice_id', '<string>');
form.append('0.image_file', '{
"fileName": "example-file"
}');
form.append('1.image_file', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: '<api-key>'}};
options.body = form;
fetch('https://api.musicgpt.com/api/public/v1/image_to_song', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.musicgpt.com/api/public/v1/image_to_song",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.musicgpt.com/api/public/v1/image_to_song"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.musicgpt.com/api/public/v1/image_to_song")
.header("Authorization", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/image_to_song")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Message Published To Queue",
"task_id": "task_12345",
"conversion_id_1": "conv_12345",
"conversion_id_2": "conv_54321",
"eta": 300,
"credit_estimate": 150.5
}{
"success": false,
"error": "image_file or image_url is required."
}{
"success": false,
"error": "Internal Server Error"
}Image to Song
Generate a song from an image by analyzing it and creating music based on visual content. The process can optionally include custom lyrics, voice conversion, and various musical parameters.
import requests
url = "https://api.musicgpt.com/api/public/v1/image_to_song"
headers = {"Authorization": "<API_KEY>"}
data = {
"image_url": "https://mybucket.s3.amazonaws.com/image.png",
"prompt": "Generate a relaxing acoustic track inspired by this scene.",
"lyrics": "Let the colors of the sunset fill your heart.",
"make_instrumental": False,
"vocal_only": False,
"key": "C major",
"bpm": 120,
"webhook_url": "https://example.com/webhook",
"voice_id": "voice_123"
}
# Option 1: Using image URL
response = requests.post(url, headers=headers, data=data)
print(response.json())
# Option 2: Uploading a local image file
# with open("image.png", "rb") as f:
# files = {"image_file": f}
# response = requests.post(url, headers=headers, data=data, files=files)
# print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/image_to_song \
--header 'Authorization: <api-key>' \
--header 'Content-Type: multipart/form-data' \
--form 'image_file=<string>' \
--form image_url=https://mybucket.s3.amazonaws.com/image.png \
--form 'prompt=Generate a relaxing acoustic track inspired by this scene.' \
--form 'lyrics=Let the colors of the sunset fill your heart.' \
--form 'negative_tags=no heavy metal, avoid loud drums' \
--form make_instrumental=false \
--form vocal_only=false \
--form 'key=C major' \
--form bpm=0 \
--form webhook_url=https://example.com/webhook \
--form 'voice_id=<string>' \
--form 0.image_file='@example-file' \
--form 1.image_file='@example-file'const form = new FormData();
form.append('image_file', '<string>');
form.append('image_url', 'https://mybucket.s3.amazonaws.com/image.png');
form.append('prompt', 'Generate a relaxing acoustic track inspired by this scene.');
form.append('lyrics', 'Let the colors of the sunset fill your heart.');
form.append('negative_tags', 'no heavy metal, avoid loud drums');
form.append('make_instrumental', 'false');
form.append('vocal_only', 'false');
form.append('key', 'C major');
form.append('bpm', '0');
form.append('webhook_url', 'https://example.com/webhook');
form.append('voice_id', '<string>');
form.append('0.image_file', '{
"fileName": "example-file"
}');
form.append('1.image_file', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: '<api-key>'}};
options.body = form;
fetch('https://api.musicgpt.com/api/public/v1/image_to_song', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.musicgpt.com/api/public/v1/image_to_song",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.musicgpt.com/api/public/v1/image_to_song"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.musicgpt.com/api/public/v1/image_to_song")
.header("Authorization", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/image_to_song")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\nhttps://mybucket.s3.amazonaws.com/image.png\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\nGenerate a relaxing acoustic track inspired by this scene.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"lyrics\"\r\n\r\nLet the colors of the sunset fill your heart.\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"negative_tags\"\r\n\r\nno heavy metal, avoid loud drums\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"make_instrumental\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"vocal_only\"\r\n\r\nfalse\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"key\"\r\n\r\nC major\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bpm\"\r\n\r\n0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://example.com/webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"voice_id\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.image_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Message Published To Queue",
"task_id": "task_12345",
"conversion_id_1": "conv_12345",
"conversion_id_2": "conv_54321",
"eta": 300,
"credit_estimate": 150.5
}{
"success": false,
"error": "image_file or image_url is required."
}{
"success": false,
"error": "Internal Server Error"
}Endpoint
POST /v1/image_to_song
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
image_file | UploadFile | Optional | Upload the image to analyze. Required if image_url is not provided. |
image_url | String | Optional | Public or S3 URL to the input image. Required if image_file is not provided. |
prompt | String | Optional | Additional text to guide the song generation (max 300 characters). |
lyrics | String | Optional | Custom lyrics to include in the generated audio (max 3000 characters). |
negative_tags | String | Optional | Tags or themes to avoid in the song. |
make_instrumental | Boolean | Optional | If true, generates an instrumental version. Defaults to false. |
vocal_only | Boolean | Optional | If true, generates a vocal-only version. Defaults to false. |
key | String | Optional | Musical key for the song (e.g., “C major”, “A minor”). |
bpm | Integer | Optional | Tempo in beats per minute. Defaults to 0 (auto-selected). |
webhook_url | String | Optional | Callback URL for async result delivery. |
voice_id | String | Optional | Voice ID for converting generated audio. Cannot be used with vocal_only mode. |
💡 Note: You must provide eitheraudio_fileoraudio_url— at least one is required.
content-type: multipart/form-data
Try it Yourself
Visit the image_to_song Endpoint Explorer to play around — set your payload, hit send, and listen to the generated results live.Sample Request
cURL
curl -X POST "https://api.musicgpt.com/api/public/v1/image_to_song" \
-H "accept: application/json" \
-H "Authorization: <api_key>" \
-F "image_file=@/path/to/image.png" \
-F "prompt=Generate a relaxing acoustic track inspired by this scene." \
-F "lyrics=Let the colors of the sunset fill your heart." \
-F "make_instrumental=false" \
-F "vocal_only=false" \
-F "key=C major" \
-F "bpm=120" \
-F "webhook_url=https://example.com/webhook" \
-F "voice_id=voice_123"
Python
import requests
url = "https://api.musicgpt.com/api/public/v1/image_to_song"
headers = {"Authorization": "<API_KEY>"}
data = {
"prompt": "Generate a relaxing acoustic track inspired by this scene.",
"lyrics": "Let the colors of the sunset fill your heart.",
"make_instrumental": False,
"vocal_only": False,
"key": "C major",
"bpm": 120,
"webhook_url": "https://example.com/webhook",
"voice_id": "voice_123"
}
# Option 1: image_url
files = {}
data["image_url"] = "https://mybucket.s3.amazonaws.com/image.png"
response = requests.post(url, headers=headers, data=data, files=files)
# Option 2: File Upload
# with open("image.png", "rb") as f:
# files = {"image_file": f}
# response = requests.post(url, headers=headers, data=data, files=files)
print(response.json())
🔐 Replace{path_to_your_audio_file},api_key, andwebhook_urlbefore executing.
Sample Response
Success (200 OK)
{
"success": true,
"message": "Message Published To Queue",
"task_id": "task-xyz-123",
"conversion_id_1": "image-abc",
"conversion_id_2": "image-def",
"eta": 40,
"credit_estimate": 45
}
Webhook Delivery
Once the generation is complete, webhooks will be triggered to deliver the following:Standard Requests :
- 2 (webhooks) x conversion details (one per version)
- 2 (webhooks) x Lyrics with timestamp data
- 1 Album Cover Image
Webhook responses include detailed metadata including task_id, conversion_id, audio files (conversion_path), lyrics etc.
Common Errors
- 422 Unprocessable Entity: Missing required fields like
prompt,replace_start_at, orreplace_end_at, or neitheraudio_filenoraudio_urlprovided. - 500 Internal Server Error: An unexpected error occurred during processing.
The response provides a downloadable audio file.
Authorizations
Body
- Option 1
- Option 2
Image file to upload and analyze. Supported formats: JPEG, PNG, GIF, BMP, WEBP.
URL of the image to analyze. Either this or image_file must be provided.
"https://mybucket.s3.amazonaws.com/image.png"
Additional prompt to guide the song generation from the image.
300"Generate a relaxing acoustic track inspired by this scene."
Custom lyrics to include in the generated audio.
3000"Let the colors of the sunset fill your heart."
Tags or themes to avoid in the song.
"no heavy metal, avoid loud drums"
Generate instrumental output only. Lyrics will be ignored.
Generate vocal-only output.
Musical key for the song.
"C major"
Beats per minute for the song tempo. Defaults to 0 (auto-selected).
Optional callback URL for async processing results.
"https://example.com/webhook"
Voice ID for converting the generated audio. Cannot be used with vocal_only mode.