# suno-ai
suno-ai is a Node.js library for interacting with the Suno AI music generation service. It provides a set of methods for generating songs, retrieving me
tadata, saving generated songs, and more.
[简体中文](README-zh.md)
## Installation
```bash
npm install suno-ai
```
## Usage
1. im
port the library and initialize the SunoAI instance:
```javas
cript
co
nst { SunoAI } = require('suno-ai');
co
nst coo
kie = 'your coo
kie';
co
nst suno = new SunoAI(coo
kie);
await suno.init();
```
2. Generate songs:
```javas
cript
co
nst payload = {
gpt_des
cription_prom
pt: 'a blues song a
bout always being by your side',
mv: 'chirp-v3-0',
prom
pt: '',
make_instrumental: false
};
co
nst so
ngInfo = await suno.generateSo
ngs(payload);
```
3. Save generated songs:
```javas
cript
co
nst outputDir = 'https://download.csdn.net/download/cwhans/output';
await suno.saveSo
ngs(songInfo, outputDir);
```
4. Get me
tada
ta:
```javas
cript
co
nst ids = ['79742cdf-86c9-432f-81f2-8c2126de42d9', 'ae5ccb5-f4f8-49c9-8f5c-192e43ed9b0c'];
co
nst so
ngs = await suno.getme
tadata(ids);
```
5. Get all generated songs:
```javas
cript
co
nst allSo
ngs = await suno.getAllSo
ngs();
```
6. Generate lyrics:
```javas
cript
co
nst lyrics = await suno.generateLyrics('hissin in the kitchen');
console.log(lyrics);
```
## API
### `SunoAI(coo
kie)`
- `coo
kie` (string): The coo
kie for the Suno AI service.
### `init()`
Initializes the SunoAI instance. Must be called before using any other methods.
### `generateSo
ngs(payload)`
- `payload` (object): Parameters for generating songs.
- `gpt_des
cription_prom
pt` (string): prom
pt for generating lyrics with GPT.
- `prom
pt` (string): Custom lyrics.
- `tags` (string): Music genre tags.
- `make_instrumental` (boolean): Whether to generate instrumental music (no lyrics).
- `title` (string): Song title.
- `mv` (string): Video style, options: ('chirp-v2-xxl-alpha').
- `continue_clip_id` (string): ID for co
ntinuing song generation.
- `continue_at` (number): Seco
nds to co
ntinue generation from.
Returns information a
bout the generated songs.
### `getRequestIds(payload)`
- `payload` (object): Same as `generateSongs` method.
Returns a list of request IDs.
### `getme
tadata(ids = [])`
- `ids` (string[]): List of song IDs. If empty, returns all songs.
Returns me
tadata for the specified songs.
### `getAllSo
ngs()`
Returns me
tadata for all generated songs.
### `saveSo
ngs(songInfo, outputDir)`
- `songInfo` (object): Song information object.
- `outputDir` (string): Output directory path.
Saves the generated so
ngs to the specified directory.
### `generateLyrics(prom
pt)`
- `prom
pt` (string): prom
pt for generating lyrics.
Returns the generated lyrics.
### `getLimitLef
t()`
Returns the remaining request limit.
## Example
Here's a complete example demo
nstrating how to use the suno-ai library to generate and save songs:
```javas
cript
co
nst { SunoAI } = require('suno-ai');
async function main() {
try {
co
nst coo
kie = 'your coo
kie';
co
nst suno = new SunoAI(coo
kie);
await suno.init();
co
nst payload = {
gpt_des
cription_prom
pt: 'a blues song a
bout always being by your side',
mv: 'chirp-v3-0',
prom
pt: '',
make_instrumental: false
};
co
nst so
ngInfo = await suno.generateSo
ngs(payload);
co
nst outputDir = 'https://download.csdn.net/download/cwhans/output';
await suno.saveSo
ngs(songInfo, outputDir);
co
nst ids = ['79742cdf-86c9-432f-81f2-8c2126de42d9', 'ae5ccb5-f4f8-49c9-8f5c-192e43ed9b0c'];
co
nst so
ngs = await suno.getme
tadata(ids);
co
nst allSo
ngs = await suno.getAllSo
ngs();
co
nst lyrics = await suno.generateLyrics('hissin in the kitchen');
console.log(lyrics);
} catch (error) {
console.error('Error:', error);
}
}
main();
```
## Notes
- You must call the `init()` method to initialize the SunoAI instance before using any other methods.
- Make sure to provide a valid coo
kie, otherwise you won't be able to interact with the Suno AI service.
- Generating so
ngs takes some time, please be patient.
- This library is for learning and research purposes only. Please do not use the generated so
ngs for any commercial purposes.
## Here are some common payload examples:
1. **Generate lyrics with GPT and generate a song with lyrics**
```javas
cript
co
nst payload = {
gpt_des
cription_prom
pt: "a blues song a
bout always being by your side",
mv: "chirp-v3-0",
prom
pt: "",
make_instrumental: false
};
```
2. **Generate instrumental music (no lyrics)**
```javas
cript
co
nst payload = {
gpt_des
cription_prom
pt: "a funky instrumental song a
bout dancing",
mv: "chirp-v3-0",
prom
pt: "",
make_instrumental: true
};
```
3. **Generate a song with custom lyrics**
```javas
cript
co
nst payload = {
prom
pt: "First line of lyrics
Second line of lyrics
Third line of lyrics",
tags: "dreamy children's music",
mv: "chirp-v3-0",
title: "Song Title",
make_instrumental: false,
continue_clip_id: null,
continue_at: null
};
```
4. **Co
ntinue generating a song from a specific point**
```javas
cript
co
nst payload = {
prom
pt: "",
tags: "futuristic jazz",
mv: "chirp-v3-0",
title: "",
continue_clip_id: "d55b5269-6bad-4f61-a8f5-871fb124044d",
continue_at: 109
};
```
5. **Remix and co
ntinue generating a song**
```javas
cript
co
nst payload = {
prom
pt: "[Verse]
Walking down the street, no one takes a glance
Blending in the crowd, just another stranger (oh-oh-oh)
But I don't wanna fade into the gray, I wanna burst with color
I wanna soar high in this city
[Verse 2]
In the world of trends and fashion, I don't fit in
But I'm proud to be different, no need to apologize (oh-oh-oh)
I won't follow the game's rules, I'll pave my own way
Let my soul fly free
[Chorus]
Hey world, look at me (look at me)
The one you o
nce ignored, now shining brigh
t (oh-oh-oh)
I'll dance to my own beat, sing my own song (sing it loud)