Suno Music Generation API Tutorial

AI music creation platform to generate original songs and background music in one click

AI composition

Intelligent music creation

Lyrics generation

Auto lyrics and vocals

Multiple styles

Supports 9+ genres

Instant preview

Real-time generation preview

1. Basic music generation

Getting Started

import requests
import json

# Suno AI music generation API
def generate_music(prompt: str, style: str = "pop"):
    url = "https://api.n1n.ai/v1/audio/music/generate"
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }
    
    data = {
        "prompt": prompt,
        "model": "suno-v3.5",
        "style": style,  # pop, rock, jazz, classical, electronic
        "duration": 30,  # seconds
        "instrumental": False,  # instrumental only?
        "lyrics": None  # Custom lyrics (optional)
    }
    
    response = requests.post(url, headers=headers, json=data)
    
    if response.status_code == 200:
        result = response.json()
        return result["audio_url"], result["task_id"]
    else:
        raise Exception(f"Generation failed: {response.text}")

# Generate a song with lyrics
def create_song_with_lyrics(title: str, lyrics: str, genre: str):
    data = {
        "model": "suno-v3.5",
        "title": title,
        "lyrics": lyrics,
        "genre": genre,
        "mood": "uplifting",  # Mood: uplifting, melancholic, energetic
        "tempo": "medium",  # Tempo: slow, medium, fast
        "voice_type": "female"  # Voice type
    }
    
    response = requests.post(
        "https://api.n1n.ai/v1/audio/music/create-song",
        headers=headers,
        json=data
    )
    
    return response.json()

# Usage example
audio_url, task_id = generate_music(
    prompt="Compose an upbeat song about summer beaches",
    style="tropical house"
)

print(f"Generating music... Task ID: {task_id}")
print(f"Audio URL: {audio_url}")

2. Supported music styles

Pop

Pop music

Catchy, strong rhythm

Rock

Rock

Electric guitar, strong beat

Jazz

Jazz

Improvisation, complex chords

Classical

Classical music

Symphony, orchestral

Electronic

Electronic music

EDM, synth sounds

Hip-Hop

Hip-hop

Rap, strong rhythm

R&B

Rhythm and blues

Soulful, expressive

Country

Country music

Guitars, strong storytelling

Ambient

Ambient music

Spacious, meditative

3. Advanced music features

Professional creation tools

# Advanced music generation features
class MusicGenerator:
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.base_url = "https://api.n1n.ai/v1/audio/music"
    
    def remix(self, audio_url: str, style: str):
        """Remix an existing song"""
        response = requests.post(
            f"{self.base_url}/remix",
            headers=self._get_headers(),
            json={
                "source_audio": audio_url,
                "target_style": style,
                "preserve_vocals": True,
                "mix_ratio": 0.7  # Original track mix ratio
            }
        )
        return response.json()
    
    def extend_music(self, audio_url: str, duration: int):
        """Extend music duration"""
        response = requests.post(
            f"{self.base_url}/extend",
            headers=self._get_headers(),
            json={
                "source_audio": audio_url,
                "additional_duration": duration,
                "seamless_loop": True
            }
        )
        return response.json()
    
    def generate_variations(self, task_id: str, count: int = 3):
        """Generate multiple variations"""
        response = requests.post(
            f"{self.base_url}/variations",
            headers=self._get_headers(),
            json={
                "original_task_id": task_id,
                "variation_count": count,
                "diversity": 0.8  # Variation degree
            }
        )
        return response.json()
    
    def custom_instrumental(self, instruments: list, bpm: int, key: str):
        """Custom instrumental arrangement"""
        response = requests.post(
            f"{self.base_url}/instrumental",
            headers=self._get_headers(),
            json={
                "instruments": instruments,  # ["piano", "guitar", "drums"]
                "bpm": bpm,  # Beats per minute
                "key": key,  # Musical key, e.g., "C major"
                "structure": ["intro", "verse", "chorus", "verse", "chorus", "outro"]
            }
        )
        return response.json()

# Batch-generate background music
def batch_generate_bgm(scenes: list):
    generator = MusicGenerator(API_KEY)
    results = []
    
    for scene in scenes:
        result = generator.generate_music(
            prompt=scene["description"],
            style=scene["style"],
            duration=scene["duration"]
        )
        results.append(result)
    
    return results

4. Use cases

🎬 Content creation

  • ✅ Video soundtracks
  • ✅ Podcast intros
  • ✅ Game background music
  • ✅ Ad soundtracks

🎵 Music production

  • ✅ Demo creation
  • ✅ Arrangement inspiration
  • ✅ Background tracks
  • ✅ Music education