This is an unofficial Python client for Suno AI, allowing you to generate music, fetch song details, and manage your account programmatically.
pip install suno-apiTo use this library, you need to obtain your session cookie from the browser.
- Log in to Suno.com.
- Open Developer Tools (F12) -> Network tab.
- Refresh the page.
- Find a request to
client?_clerk_js_version=...(or any request tosuno.com). - Copy the
Cookieheader value.
from suno.client import SunoClient
import time
# Initialize client
cookie = "YOUR_COOKIE_HERE"
client = SunoClient(cookie)
# Generate a song
print("Generating song...")
clips = client.generate(
prompt="A chill lofi beat about coding in the rain",
tags="lofi, hip hop, chill",
title="Coding in the Rain"
)
for clip in clips:
print(f"Generated Clip ID: {clip['id']}")
# Wait for generation (simple polling example)
# Note: In a real app, you would poll status
time.sleep(10)
# Get feed/songs
songs = client.get_songs()
for song in songs[:5]:
print(f"{song['title']} - {song['audio_url']}")- Generate Music: Create songs with prompts, tags, and titles.
- Fetch Songs: Retrieve your generated songs and their metadata (audio URLs, images).
- Credit Usage: Check your remaining credits.
- Automatic Token Refresh: Handles JWT token refreshing using your session cookie.
This is an unofficial library and is not affiliated with Suno AI. Use responsibly and in accordance with Suno's Terms of Service.