Integrate AI Music generation into your application with our RESTful API
Looking for MCP Documentation?1https://www.musicmcp.ai/apiAll API requests require authentication using an API key. Include your API key in the request header:
1curl -X POST https://www.musicmcp.ai/api/music/generate/custom \2 -H "api-key: YOUR_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{"title": "My Song", "lyric": "...", "tags": "pop", "instrumental": false}'💡 Get your API key: Sign in to your dashboard at musicmcp.ai and navigate to the API Keys section.
Different API endpoints consume different amounts of credits. Music generation endpoints deduct credits upon successful request.
Each request generates 2 songs
/music/generate/inspiration/music/generate/customNo credits required
/music/generate/query- Query music status/credit- Check credit balance/health- Health check⚠️ Important: Credits are only deducted when music generation is successful. Failed requests do not consume credits.
Invalid or missing API key. Check your api-key header.
Insufficient credits. Purchase more credits from your dashboard.
The music generation service is temporarily unavailable. Please try again later.
API requests are subject to rate limiting to ensure service stability:
1import requests2import time34API_KEY = "your_api_key_here"5BASE_URL = "https://www.musicmcp.ai/api"67def generate_custom_music():8 headers = {9 "api-key": API_KEY,10 "Content-Type": "application/json"11 }1213 # Step 1: Submit generation request14 payload = {15 "title": "Summer Vibes",16 "lyric": "Walking on sunshine, feeling so free",17 "tags": "pop, upbeat",18 "instrumental": False19 }2021 response = requests.post(22 f"{BASE_URL}/music/generate/custom",23 headers=headers,24 json=payload25 )2627 if response.status_code != 200:28 print(f"Error: {response.status_code}")29 print(response.json())30 return3132 # Extract song IDs from response33 result = response.json()34 song_ids = result['data']['ids']35 print(f"Generation started. Song IDs: {song_ids}")3637 # Step 2: Poll for completion38 while True:39 query_response = requests.post(40 f"{BASE_URL}/music/generate/query",41 headers=headers,42 json={"ids": song_ids}43 )4445 if query_response.status_code == 200:46 query_result = query_response.json()47 songs = query_result['data']['songs']4849 # Check if all songs are completed (status = 1)50 all_completed = all(song['status'] == 1 for song in songs)5152 if all_completed:53 print(f"\nGenerated {len(songs)} songs successfully!")54 for i, song in enumerate(songs, 1):55 print(f"\nSong {i}:")56 print(f" Title: {song['songName']}")57 print(f" URL: {song['songUrl']}")58 print(f" Duration: {song['duration']}s")59 break60 else:61 print("Generation in progress...")62 time.sleep(2) # Wait 2 seconds before next poll63 else:64 print(f"Query error: {query_response.status_code}")65 break6667generate_custom_music()1const axios = require('axios');23const API_KEY = 'your_api_key_here';4const BASE_URL = 'https://www.musicmcp.ai/api';56async function generateInspirationMusic() {7 try {8 // Step 1: Submit generation request9 const response = await axios.post(10 `${BASE_URL}/music/generate/inspiration`,11 {12 prompt: 'Create a relaxing ambient track for meditation',13 instrumental: true,14 style: 'ambient'15 },16 {17 headers: {18 'api-key': API_KEY,19 'Content-Type': 'application/json'20 }21 }22 );2324 // Extract song IDs25 const songIds = response.data.data.ids;26 console.log('Generation started. Song IDs:', songIds);2728 // Step 2: Poll for completion29 while (true) {30 const queryResponse = await axios.post(31 `${BASE_URL}/music/generate/query`,32 { ids: songIds },33 {34 headers: {35 'api-key': API_KEY,36 'Content-Type': 'application/json'37 }38 }39 );4041 const songs = queryResponse.data.data.songs;4243 // Check if all songs are completed (status = 1)44 const allCompleted = songs.every(song => song.status === 1);4546 if (allCompleted) {47 console.log(`\nGenerated ${songs.length} songs successfully!`);48 songs.forEach((song, index) => {49 console.log(`\nSong ${index + 1}:`);50 console.log(` Title: ${song.songName}`);51 console.log(` URL: ${song.songUrl}`);52 console.log(` Duration: ${song.duration}s`);53 });54 break;55 } else {56 console.log('Generation in progress...');57 await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2s58 }59 }60 } catch (error) {61 console.error('Error:', error.response?.data || error.message);62 }63}6465generateInspirationMusic();1# Step 1: Generate custom music (returns song IDs)2curl -X POST https://www.musicmcp.ai/api/music/generate/custom \3 -H "api-key: YOUR_API_KEY" \4 -H "Content-Type: application/json" \5 -d '{6 "title": "My Song",7 "lyric": "Beautiful lyrics here",8 "tags": "pop, romantic",9 "instrumental": false10 }'11# Response: {"code": 200, "data": {"ids": ["id1", "id2"]}}1213# Step 2: Query music status (poll until completed)14curl -X POST https://www.musicmcp.ai/api/music/generate/query \15 -H "api-key: YOUR_API_KEY" \16 -H "Content-Type: application/json" \17 -d '{18 "ids": ["id1", "id2"]19 }'20# Response includes songs with status: 0=Failed, 1=Completed, 2=In Progress21# Poll every 2 seconds until all songs have status=12223# Check credit balance24curl -X GET https://www.musicmcp.ai/api/credit \25 -H "api-key: YOUR_API_KEY"2627# Check service health28curl -X GET https://www.musicmcp.ai/api/health