Skip to content

Commit 7da7ac6

Browse files
committed
Implement hCaptcha solving via 2Captcha & other stuff
- implement hCaptcha solving via paid service 2Captcha and browser automation library Playwright with rebrowser-patches - implement sunoApi instances caching so sessions won't be constantly updated - add support for entering cookies not only in SUNO_COOKIE, but also the Cookie HTTP header - update docs and add Russian docs
1 parent 3bffec1 commit 7da7ac6

File tree

24 files changed

+10838
-139
lines changed

24 files changed

+10838
-139
lines changed

.env.example

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
SUNO_COOKIE=<your-suno-cookie>
2-
1+
# For more information, please see the README.md
2+
SUNO_COOKIE=
3+
TWOCAPTCHA_KEY= # Obtain from 2captcha.com
4+
BROWSER=chromium # chromium or firefox
5+
BROWSER_GHOST_CURSOR=false
6+
BROWSER_LOCALE=en
7+
BROWSER_HEADLESS=true

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ WORKDIR /app
1212
COPY package*.json ./
1313

1414
ARG SUNO_COOKIE
15-
RUN if [ -z "$SUNO_COOKIE" ]; then echo "SUNO_COOKIE is not set" && exit 1; fi
15+
ARG BROWSER
16+
RUN if [ -z "$SUNO_COOKIE" ]; then echo "Warning: SUNO_COOKIE is not set"; fi
1617
ENV SUNO_COOKIE=${SUNO_COOKIE}
18+
RUN if [ -z "$BROWSER" ]; then echo "Warning: BROWSER is not set; will use chromium by default"; fi
19+
ENV BROWSER=${BROWSER:-chromium}
1720

1821
RUN npm install --only=production
22+
RUN npx playwright install $BROWSER
1923
COPY --from=builder /src/.next ./.next
2024
EXPOSE 3000
2125
CMD ["npm", "run", "start"]

README.md

+50-25
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
<p align="center">
99
<a target="_blank" href="./README.md">English</a>
1010
| <a target="_blank" href="./README_CN.md">简体中文</a>
11+
| <a target="_blank" href="./README_RU.md">русский</a>
1112
| <a target="_blank" href="https://suno.gcui.ai">Demo</a>
1213
| <a target="_blank" href="https://suno.gcui.ai/docs">Docs</a>
13-
| <a target="_blank" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api">Deploy with Vercel</a>
14+
| <a target="_blank" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE,TWOCAPTCHA_KEY,BROWSER,BROWSER_GHOST_CURSOR,BROWSER_LOCALE,BROWSER_HEADLESS&project-name=suno-api&repository-name=suno-api">Deploy with Vercel</a>
1415
</p>
1516
<p align="center">
1617
<a href="https://www.producthunt.com/products/gcui-art-suno-api-open-source-sunoai-api/reviews?utm_source=badge-product_review&utm_medium=badge&utm_souce=badge-gcui&#0045;art&#0045;suno&#0045;api&#0045;open&#0045;source&#0045;sunoai&#0045;api" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/product_review.svg?product_id=577408&theme=light" alt="gcui&#0045;art&#0047;suno&#0045;api&#0058;Open&#0045;source&#0032;SunoAI&#0032;API - Use&#0032;API&#0032;to&#0032;call&#0032;the&#0032;music&#0032;generation&#0032;AI&#0032;of&#0032;suno&#0046;ai&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
@@ -22,72 +23,94 @@
2223

2324
## Introduction
2425

25-
Suno.ai v3 is an amazing AI music service. Although the official API is not yet available, we couldn't wait to integrate its capabilities somewhere.
26+
Suno is an amazing AI music service. Although the official API is not yet available, we couldn't wait to integrate its capabilities somewhere.
2627

2728
We discovered that some users have similar needs, so we decided to open-source this project, hoping you'll like it.
2829

30+
This implementation uses the paid [2Captcha](https://2captcha.com/about) service (a.k.a. ruCaptcha) to solve the hCaptcha challenges automatically and does not use any already made closed-source paid Suno API implementations.
31+
2932
## Demo
3033

3134
We have deployed an example bound to a free Suno account, so it has daily usage limits, but you can see how it runs:
3235
[suno.gcui.ai](https://suno.gcui.ai)
3336

3437
## Features
3538

36-
- Perfectly implements the creation API from app.suno.ai
39+
- Perfectly implements the creation API from suno.ai.
3740
- Automatically keep the account active.
41+
- Solve CAPTCHAs automatically using [2Captcha](https://2captcha.com) and [Playwright](https://playwright.dev) with [rebrowser-patches](https://github.com/rebrowser/rebrowser-patches).
3842
- Compatible with the format of OpenAI’s `/v1/chat/completions` API.
39-
- Supports Custom Mode
40-
- One-click deployment to Vercel
43+
- Supports Custom Mode.
44+
- One-click deployment to [Vercel](#deploy-to-vercel) & [Docker](#docker).
4145
- In addition to the standard API, it also adapts to the API Schema of Agent platforms like GPTs and Coze, so you can use it as a tool/plugin/Action for LLMs and integrate it into any AI Agent.
4246
- Permissive open-source license, allowing you to freely integrate and modify.
4347

4448
## Getting Started
4549

46-
### 1. Obtain the cookie of your app.suno.ai account
50+
### 1. Obtain the cookie of your Suno account
4751

48-
1. Head over to [app.suno.ai](https://app.suno.ai) using your browser.
52+
1. Head over to [suno.com/create](https://suno.com/create) using your browser.
4953
2. Open up the browser console: hit `F12` or access the `Developer Tools`.
50-
3. Navigate to the `Network tab`.
54+
3. Navigate to the `Network` tab.
5155
4. Give the page a quick refresh.
52-
5. Identify the request that includes the keyword `client?_clerk_js_version`.
56+
5. Identify the latest request that includes the keyword `?__clerk_api_version`.
5357
6. Click on it and switch over to the `Header` tab.
5458
7. Locate the `Cookie` section, hover your mouse over it, and copy the value of the Cookie.
5559

5660
![get cookie](https://github.com/gcui-art/suno-api/blob/main/public/get-cookie-demo.gif)
5761

58-
### 2. Clone and deploy this project
62+
### 2. Register on 2Captcha and top up your balance
63+
[2Captcha](https://2captcha.com/about) is a paid CAPTCHA solving service that uses real workers to solve the CAPTCHA and has high accuracy. It is needed because of Suno constantly requesting hCaptcha solving that currently isn't possible for free by any means.
64+
65+
[Create](https://2captcha.com/auth/register?userType=customer) a new 2Captcha account, [top up](https://2captcha.com/pay) your balance and [get your API key](https://2captcha.com/enterpage#recognition).
66+
67+
If you are located in Russia or Belarus, use the [ruCaptcha](https://rucaptcha.com) interface instead of 2Captcha. It's the same service, but it supports payments from those countries.
68+
69+
### 3. Clone and deploy this project
5970

6071
You can choose your preferred deployment method:
6172

6273
#### Deploy to Vercel
6374

64-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api)
75+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE,TWOCAPTCHA_KEY,BROWSER,BROWSER_GHOST_CURSOR,BROWSER_LOCALE,BROWSER_HEADLESS&project-name=suno-api&repository-name=suno-api)
6576

6677
#### Run locally
6778

6879
```bash
6980
git clone https://github.com/gcui-art/suno-api.git
7081
cd suno-api
7182
npm install
83+
npx playwright install chromium
7284
```
73-
74-
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/)
85+
#### Docker
86+
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/). However, follow the step below before running.
7587

7688
```bash
7789
docker compose build && docker compose up
7890
```
7991

80-
### 3. Configure suno-api
92+
### 4. Configure suno-api
8193

82-
- If deployed to Vercel, please add an environment variable `SUNO_COOKIE` in the Vercel dashboard, with the value of the cookie obtained in the first step.
94+
- If deployed to Vercel, please add the environment variables in the Vercel dashboard.
8395

8496
- If you’re running this locally, be sure to add the following to your `.env` file:
85-
97+
#### Environment variables
98+
- `SUNO_COOKIE` — the `Cookie` header you obtained in the first step.
99+
- `TWOCAPTCHA_KEY` — your 2Captcha API key from the second step.
100+
- `BROWSER` — the name of the browser that is going to be used to solve the CAPTCHA. Only `chromium` and `firefox` supported.
101+
- `BROWSER_GHOST_CURSOR` — use ghost-cursor-playwright to simulate smooth mouse movements. Please note that it doesn't seem to make any difference in the rate of CAPTCHAs, so you can set it to `false`. Retained for future testing.
102+
- `BROWSER_LOCALE` — the language of the browser. Using either `en` or `ru` is recommended, since those have the most workers on 2Captcha. [List of supported languages](https://2captcha.com/2captcha-api#language)
103+
- `BROWSER_HEADLESS` — run the browser without the window. You probably want to set this to `true`.
86104
```bash
87-
SUNO_COOKIE=<your-cookie>
105+
SUNO_COOKIE=<>
106+
TWOCAPTCHA_KEY=<>
107+
BROWSER=chromium
108+
BROWSER_GHOST_CURSOR=false
109+
BROWSER_LOCALE=en
110+
BROWSER_HEADLESS=true
88111
```
89112

90-
### 4. Run suno api
113+
### 5. Run suno-api
91114

92115
- If you’ve deployed to Vercel:
93116
- Please click on Deploy in the Vercel dashboard and wait for the deployment to be successful.
@@ -108,7 +131,7 @@ SUNO_COOKIE=<your-cookie>
108131

109132
it means the program is running normally.
110133

111-
### 5. Use Suno API
134+
### 6. Use Suno API
112135

113136
You can check out the detailed API documentation at :
114137
[suno.gcui.ai/docs](https://suno.gcui.ai/docs)
@@ -132,18 +155,20 @@ Suno API currently mainly implements the following APIs:
132155
- `/api/concat`: Generate the whole song from extensions
133156
```
134157
158+
You can also specify the cookies in the `Cookie` header of your request, overriding the default cookies in the `SUNO_COOKIE` environment variable. This comes in handy when, for example, you want to use multiple free accounts at the same time.
159+
135160
For more detailed documentation, please check out the demo site:
136161
[suno.gcui.ai/docs](https://suno.gcui.ai/docs)
137162
138-
## API Integration Code Example
163+
## API Integration Code Examples
139164
140165
### Python
141166
142167
```python
143168
import time
144169
import requests
145170

146-
# replace your vercel domain
171+
# replace with your suno-api URL
147172
base_url = 'http://localhost:3000'
148173

149174

@@ -208,7 +233,7 @@ if __name__ == '__main__':
208233

209234
```
210235
211-
### Js
236+
### JavaScript
212237
213238
```js
214239
const axios = require("axios");
@@ -304,18 +329,18 @@ You can integrate Suno AI as a tool/plugin/action into your AI agent.
304329
305330
There are four ways you can support this project:
306331
307-
1. Fork and Submit Pull Requests: We welcome any PRs that enhance the component or editor.
332+
1. Fork and Submit Pull Requests: We welcome any PRs that enhances the functionality, APIs, response time and availability. You can also help us just by translating this README into your language—any help for this project is welcome!
308333
2. Open Issues: We appreciate reasonable suggestions and bug reports.
309334
3. Donate: If this project has helped you, consider buying us a coffee using the Sponsor button at the top of the project. Cheers!
310335
4. Spread the Word: Recommend this project to others, star the repo, or add a backlink after using the project.
311336
312337
## Questions, Suggestions, Issues, or Bugs?
313338
314-
We use GitHub Issues to manage feedback. Feel free to open an issue, and we'll address it promptly.
339+
We use [GitHub Issues](https://github.com/gcui-art/suno-api/issues) to manage feedback. Feel free to open an issue, and we'll address it promptly.
315340
316341
## License
317342
318-
LGPL-3.0 or later
343+
The license of this project is LGPL-3.0 or later. See [LICENSE](LICENSE) for more information.
319344
320345
## Related Links
321346

README_CN.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
</div>
88
<p align="center">
99
<a target="_blank" href="./README.md">English</a>
10-
| <a target="_blank" href="./README_CN.md">简体中文</a>
10+
| <a target="_blank" href="./README_CN.md">简体中文</a>
11+
| <a target="_blank" href="./README_RU.md">русский</a>
1112
| <a target="_blank" href="https://suno.gcui.ai">Demo</a>
1213
| <a target="_blank" href="https://suno.gcui.ai/docs">文档</a>
13-
| <a target="_blank" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api">一键部署到 Vercel</a>
14+
| <a target="_blank" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE,TWOCAPTCHA_KEY,BROWSER,BROWSER_GHOST_CURSOR,BROWSER_LOCALE,BROWSER_HEADLESS&project-name=suno-api&repository-name=suno-api">一键部署到 Vercel</a>
1415

1516
</p>
1617
<p align="center">
@@ -61,7 +62,7 @@ Suno.ai v3 是一个令人惊叹的 AI 音乐服务,虽然官方还没有开
6162

6263
#### 部署到 Vercel
6364

64-
[![部署到 Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api)
65+
[![部署到 Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE,TWOCAPTCHA_KEY,BROWSER,BROWSER_GHOST_CURSOR,BROWSER_LOCALE,BROWSER_HEADLESS&project-name=suno-api&repository-name=suno-api)
6566

6667
#### 本地运行
6768

0 commit comments

Comments
 (0)