SunoAI Unofficial Python API Library and REST API for Suno.ai โ Create Music with Generative AI ! โจ
MIT License
๐ SunoAI API Library is an unofficial Python client for interacting with Suno AI's music generator. This library facilitates generating music using Suno's Chirp v3 model and includes main functions of Suno AI with a built-in music downloader. It can be deployed as a REST API using FastAPI, Local, Docker, on a PaaS provider like Heroku.
๐ Before using the library or REST API, you must sign up on the suno.ai website and obtain your cookie as shown in this screenshot.
๐ก You can find cookie from the Web Browser's Developer Tools -> Network Tab
Just right click & open Inspect. Filter : _clerk_js_version
Set this cookie as SUNO_COOKIE
environment variable or initialize the library as shown below.
from suno import Suno, ModelVersions
client = Suno(
cookie='YOUR_COOKIE_HERE',
model_version=ModelVersions.CHIRP_V3_5)
Install the library using pip:
pip install SunoAI
Set SUNO_COOKIE
as an Environmental variable before deploy. - Instructions
export SUNO_COOKIE="YOUR_COOKIE_HERE"
git clone [email protected]:Malith-Rukshan/Suno-API.git
pip3 install -r requirements.txt
cd Suno-API
fastapi run api.py --port 8080
๐ Available at : http://127.0.0.1:8080
โก๏ธ Quick Start :
from suno import Suno, ModelVersions
client = Suno(
cookie='YOUR_COOKIE_HERE',
model_version=ModelVersions.CHIRP_V3_5)
# Generate a song
songs = client.generate(prompt="A serene landscape", is_custom=False, wait_audio=True)
# Download generated songs
for song in songs:
file_path = client.download(song=song)
print(f"Song downloaded to: {file_path}")
Suno()
<- Initializing
chirp-v3-5
, chirp-v3-0
, chirp-v2-0
default is chirp-v3-5
. | Detailed view
generate()
Clip
objects containing song data with IDs.clips = client.generate(
prompt="A peaceful melody reflecting a serene landscape",
is_custom=False,
wait_audio=True
)
print(clips)
clips = client.generate(
prompt="I found a love, for me\nDarling, just dive right in and follow my lead\nWell, I found a girl, beautiful and sweet\nOh, I never knew you were the someone waiting for me...",
tags="English men voice",
title="Perfect by Malith-Rukshan/Suno-API",
make_instrumental= False,
is_custom=True,
wait_audio=True
)
print(clips)
โ๏ธ Usage Note :
is_custom
to True
, ensure that the prompt parameter contains the lyrics of the song you wish to generate. Conversely, if is_custom
is set to False
, provide a descriptive prompt detailing the essence of the song you want.wait_audio
is set to True, the request will take longer as it waits for the audio URLs to be ready. If not set, the response will return without audio_url
but with audio IDs. In such cases, you'll need to call the get_songs or get_song method after a short interval to retrieve the response with the audio_url
included, once the generation process is complete.get_songs()
Clip
objects representing the retrieved songs.songs = client.get_songs(song_ids="123,456")
print(songs)
set_visibility()
response = client.set_visibility(song_id="uuid-type-songid-1234", is_public=False)
print(response)
get_credits()
CreditsInfo
object.credits_info = client.get_credits()
print(credits_info)
download()
# Using a song ID
file_path = client.download(song="uuid-type-songid-1234")
print(f"Song downloaded to: {file_path}")
# Using a Clip object
clip = client.get_song("uuid-type-songid-1234")
file_path = client.download(song=clip)
print(f"Song downloaded to: {file_path}")
Models provided by Suno AI to Generate music.
chirp-v3-5
: Newest model, better song structure, max 4 minutes.chirp-v3-0
: Broad, versatile, max 2 minutes.chirp-v2-0
: Vintage Suno model, max 1.3 minutes.Example How to use:
from suno import Suno, ModelVersions
client = Suno(model_version=ModelVersions.CHIRP_V3_5)
or
from suno import Suno
client = Suno(model_version='chirp-v3-5')
Clip Model:
The Clip class encapsulates the details of a music track generated by the Suno AI. Each attribute of this class provides specific information about the track:
CreditsInfo Model:
The CreditsInfo class provides information about the user's credit balance and usage within the Suno AI system.
1. Generate Music
POST /generate
Request Body:
{
"prompt": "A serene melody about the ocean",
"is_custom": false,
"tags": "relaxing, instrumental",
"title": "Ocean Waves",
"make_instrumental": true,
"model_version": "chirp-v3-5",
"wait_audio": true
}
Response:
[
{
"id": "124b735f-7fb0-42b9-8b35-761aed65a7f6",
"video_url": "",
"audio_url": "https://audiopipe.suno.ai/item_id=124b735f-7fb0-42b9-8b35-761aed65a7f6",
"image_url": "https://cdn1.suno.aiimage_124b735f-7fb0-42b9-8b35-761aed65a7f6.png",
"image_large_url": "https://cdn1.suno.aiimage_large_124b735f-7fb0-42b9-8b35-761aed65a7f.png",
"is_video_pending": False,
"major_model_version": "v3",
"model_name": "chirp-v3",
"metadata": {
"tags": "English men voice",
"prompt": "I found a love, for me\nDarling,just dive right in and follow mylead\nWell, I found a girl, beautiful andsweet\nOh, I never knew you were thesomeone waiting for me\n\nโฒCause we werejust kids when we fell in love\nNot knowingwhat it was\nI will not give you up thistime\nBut darling, just kiss me slow\nYourheart is all I own\nAnd in your eyes,you're holding mine\n\nBaby, Iโฒm dancing inthe dark\nWith you between myarms\nBarefoot on the grass\nListening toour favourite song\nWhen you said youlooked a mess\nI whispered underneath mybreath\nBut you heard it\nDarling, you lookperfect tonight",
"gpt_description_prompt": None,
"audio_prompt_id": None,
"history": None,
"concat_history": None,
"type": "gen",
"duration": None,
"refund_credits": None,
"stream": True,
"error_type": None,
"error_message": None
},
"is_liked": False,
"user_id":"2340653f-32cb-4343-artb-09203ty749e9",
"display_name": "Snonymous",
"handle": "anonymous",
"is_handle_updated": False,
"is_trashed": False,
"reaction": None,
"created_at": "2024-05-05T11:54:09.356Z",
"status": "streaming",
"title": "Perfect by Malith-Rukshan/Suno-API",
"play_count": 0,
"upvote_count": 0,
"is_public": False
}
]
2. Retrieve Songs
POST /songs
{
"song_ids": "uuid-format-1234,4567-abcd"
}
/generate
Response3. Get a Specific Song
POST /get_song
{
"song_id": "uuid-song-id"
}
/generate
Response but Only ClipPOST /set_visibility
{
"song_id": "uuid-song-id",
"is_public": true
}
{
"is_public": true
}
4. Retrieve Credit Information
GET /credits
{
"credits_left": 50,
"period": "2024-05",
"monthly_limit": 100,
"monthly_usage": 25
}
According to Suno.ai Each song generation consumes 5 credits, thus a total of 10 credits is necessary for each successful call.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
All content and music generated through this library are credited to Suno AI. This unofficial API provides a convenient way to interact with Suno AI's services but does not claim any ownership or rights over the music generated. Please respect the terms of service of Suno AI when using their platform โค๏ธ.
This library is intended primarily for educational and development purposes. It aims to enhance and simplify access to Suno AI's music generation capabilities. If you enjoy the music generated, consider supporting Suno AI directly. Logo Credit : @rejaul43
This project is distributed under the MIT License. This license allows everyone to use, modify, and redistribute the code. However, it comes with no warranties regarding its functionality. For more details, see the LICENSE file in the repository.
If you found this project helpful, don't forget to give it a โญ on GitHub. This helps others find and use the project too! ๐ซถ
Join our Telegram channels,
If you have any questions, feedback, or just want to say hi, you can reach out to me:
๐งโ๐ป Built with ๐ by Single Developers </>