REST API Documentation

Integrate AI Music generation into your application with our RESTful API

Looking for MCP Documentation?

Base URL

1https://www.musicmcp.ai/api

Authentication

All 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.

Credits Consumption

Different API endpoints consume different amounts of credits. Music generation endpoints deduct credits upon successful request.

Music Generation Endpoints

Each request generates 2 songs

5 Credits
POST/music/generate/inspiration
POST/music/generate/custom

Free Endpoints

No credits required

FREE
POST/music/generate/query- Query music status
GET/credit- Check credit balance
GET/health- Health check

⚠️ Important: Credits are only deducted when music generation is successful. Failed requests do not consume credits.

API Endpoints

Error Codes

401

Unauthorized

Invalid or missing API key. Check your api-key header.

402

Payment Required

Insufficient credits. Purchase more credits from your dashboard.

503

Service Unavailable

The music generation service is temporarily unavailable. Please try again later.

Rate Limits

API requests are subject to rate limiting to ensure service stability:

  • Standard tier: 60 requests per minute
  • Pro tier: 120 requests per minute
  • Enterprise: Custom limits available

Code Examples

Python

1import requests
2import time
3
4API_KEY = "your_api_key_here"
5BASE_URL = "https://www.musicmcp.ai/api"
6
7def generate_custom_music():
8 headers = {
9 "api-key": API_KEY,
10 "Content-Type": "application/json"
11 }
12
13 # Step 1: Submit generation request
14 payload = {
15 "title": "Summer Vibes",
16 "lyric": "Walking on sunshine, feeling so free",
17 "tags": "pop, upbeat",
18 "instrumental": False
19 }
20
21 response = requests.post(
22 f"{BASE_URL}/music/generate/custom",
23 headers=headers,
24 json=payload
25 )
26
27 if response.status_code != 200:
28 print(f"Error: {response.status_code}")
29 print(response.json())
30 return
31
32 # Extract song IDs from response
33 result = response.json()
34 song_ids = result['data']['ids']
35 print(f"Generation started. Song IDs: {song_ids}")
36
37 # Step 2: Poll for completion
38 while True:
39 query_response = requests.post(
40 f"{BASE_URL}/music/generate/query",
41 headers=headers,
42 json={"ids": song_ids}
43 )
44
45 if query_response.status_code == 200:
46 query_result = query_response.json()
47 songs = query_result['data']['songs']
48
49 # Check if all songs are completed (status = 1)
50 all_completed = all(song['status'] == 1 for song in songs)
51
52 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 break
60 else:
61 print("Generation in progress...")
62 time.sleep(2) # Wait 2 seconds before next poll
63 else:
64 print(f"Query error: {query_response.status_code}")
65 break
66
67generate_custom_music()

JavaScript (Node.js)

1const axios = require('axios');
2
3const API_KEY = 'your_api_key_here';
4const BASE_URL = 'https://www.musicmcp.ai/api';
5
6async function generateInspirationMusic() {
7 try {
8 // Step 1: Submit generation request
9 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 );
23
24 // Extract song IDs
25 const songIds = response.data.data.ids;
26 console.log('Generation started. Song IDs:', songIds);
27
28 // Step 2: Poll for completion
29 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 );
40
41 const songs = queryResponse.data.data.songs;
42
43 // Check if all songs are completed (status = 1)
44 const allCompleted = songs.every(song => song.status === 1);
45
46 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 2s
58 }
59 }
60 } catch (error) {
61 console.error('Error:', error.response?.data || error.message);
62 }
63}
64
65generateInspirationMusic();

cURL

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": false
10 }'
11# Response: {"code": 200, "data": {"ids": ["id1", "id2"]}}
12
13# 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 Progress
21# Poll every 2 seconds until all songs have status=1
22
23# Check credit balance
24curl -X GET https://www.musicmcp.ai/api/credit \
25 -H "api-key: YOUR_API_KEY"
26
27# Check service health
28curl -X GET https://www.musicmcp.ai/api/health