Skip to content

Commit 48d667b

Browse files
authored
Merge pull request #222 from gohoski/patch-1
Implement hCaptcha solving via 2Captcha [URGENT MERGE]
2 parents 3bffec1 + 48a39a7 commit 48d667b

File tree

26 files changed

+11002
-157
lines changed

26 files changed

+11002
-157
lines changed

.env.example

Lines changed: 7 additions & 2 deletions
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`, although `chromium` is highly recommended
5+
BROWSER_GHOST_CURSOR=false
6+
BROWSER_LOCALE=en
7+
BROWSER_HEADLESS=true

Dockerfile

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
# syntax=docker/dockerfile:1
2-
3-
FROM node:lts-alpine AS builder
4-
WORKDIR /src
5-
COPY package*.json ./
6-
RUN npm install
7-
COPY . .
8-
RUN npm run build
9-
10-
FROM node:lts-alpine
11-
WORKDIR /app
12-
COPY package*.json ./
13-
14-
ARG SUNO_COOKIE
15-
RUN if [ -z "$SUNO_COOKIE" ]; then echo "SUNO_COOKIE is not set" && exit 1; fi
1+
# syntax=docker/dockerfile:1
2+
3+
FROM node:lts-bookworm AS builder
4+
WORKDIR /src
5+
COPY package*.json ./
6+
RUN npm install
7+
COPY . .
8+
RUN npm run build
9+
10+
FROM node:lts-bookworm
11+
WORKDIR /app
12+
COPY package*.json ./
13+
14+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libnss3 \
15+
libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
16+
libgbm1 libxkbcommon0 libasound2 libcups2 xvfb
17+
18+
ARG SUNO_COOKIE
19+
RUN if [ -z "$SUNO_COOKIE" ]; then echo "Warning: SUNO_COOKIE is not set. You will have to set the cookies in the Cookie header of your requests."; fi
1620
ENV SUNO_COOKIE=${SUNO_COOKIE}
21+
# Disable GPU acceleration, as with it suno-api won't work in a Docker environment
22+
ENV BROWSER_DISABLE_GPU=true
1723

18-
RUN npm install --only=production
19-
COPY --from=builder /src/.next ./.next
20-
EXPOSE 3000
21-
CMD ["npm", "run", "start"]
24+
RUN npm install --only=production
25+
26+
# Install all supported browsers, else switching browsers requires an image rebuild
27+
RUN npx playwright install chromium
28+
# RUN npx playwright install firefox
29+
30+
COPY --from=builder /src/.next ./.next
31+
EXPOSE 3000
32+
CMD ["npm", "run", "start"]

README.md

Lines changed: 55 additions & 24 deletions
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,46 +23,60 @@
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+
> [!NOTE]
68+
> 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.
69+
70+
> [!TIP]
71+
> If you want as few CAPTCHAs as possible, it is recommended to use a macOS system. macOS systems usually get fewer CAPTCHAs than Linux and Windows—this is due to its unpopularity in the web scraping industry. Running suno-api on Windows and Linux will work, but in some cases, you could get a pretty large number of CAPTCHAs.
72+
73+
### 3. Clone and deploy this project
5974

6075
You can choose your preferred deployment method:
6176

6277
#### Deploy to Vercel
6378

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)
79+
[![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)
6580

6681
#### Run locally
6782

@@ -70,24 +85,38 @@ git clone https://github.com/gcui-art/suno-api.git
7085
cd suno-api
7186
npm install
7287
```
88+
#### Docker
89+
>[!IMPORTANT]
90+
> GPU acceleration will be disabled in Docker. If you have a slow CPU, it is recommended to [deploy locally](#run-locally).
7391
74-
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/)
92+
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/). However, follow the step below before running.
7593

7694
```bash
7795
docker compose build && docker compose up
7896
```
7997

80-
### 3. Configure suno-api
98+
### 4. Configure suno-api
8199

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.
100+
- If deployed to Vercel, please add the environment variables in the Vercel dashboard.
83101

84102
- If you’re running this locally, be sure to add the following to your `.env` file:
85-
103+
#### Environment variables
104+
- `SUNO_COOKIE` — the `Cookie` header you obtained in the first step.
105+
- `TWOCAPTCHA_KEY` — your 2Captcha API key from the second step.
106+
- `BROWSER` — the name of the browser that is going to be used to solve the CAPTCHA. Only `chromium` and `firefox` supported.
107+
- `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.
108+
- `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)
109+
- `BROWSER_HEADLESS` — run the browser without the window. You probably want to set this to `true`.
86110
```bash
87-
SUNO_COOKIE=<your-cookie>
111+
SUNO_COOKIE=<>
112+
TWOCAPTCHA_KEY=<>
113+
BROWSER=chromium
114+
BROWSER_GHOST_CURSOR=false
115+
BROWSER_LOCALE=en
116+
BROWSER_HEADLESS=true
88117
```
89118

90-
### 4. Run suno api
119+
### 5. Run suno-api
91120

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

109138
it means the program is running normally.
110139

111-
### 5. Use Suno API
140+
### 6. Use Suno API
112141

113142
You can check out the detailed API documentation at :
114143
[suno.gcui.ai/docs](https://suno.gcui.ai/docs)
@@ -132,18 +161,20 @@ Suno API currently mainly implements the following APIs:
132161
- `/api/concat`: Generate the whole song from extensions
133162
```
134163
164+
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.
165+
135166
For more detailed documentation, please check out the demo site:
136167
[suno.gcui.ai/docs](https://suno.gcui.ai/docs)
137168
138-
## API Integration Code Example
169+
## API Integration Code Examples
139170
140171
### Python
141172
142173
```python
143174
import time
144175
import requests
145176

146-
# replace your vercel domain
177+
# replace with your suno-api URL
147178
base_url = 'http://localhost:3000'
148179

149180

@@ -208,7 +239,7 @@ if __name__ == '__main__':
208239

209240
```
210241
211-
### Js
242+
### JavaScript
212243
213244
```js
214245
const axios = require("axios");
@@ -304,18 +335,18 @@ You can integrate Suno AI as a tool/plugin/action into your AI agent.
304335
305336
There are four ways you can support this project:
306337
307-
1. Fork and Submit Pull Requests: We welcome any PRs that enhance the component or editor.
338+
1. Fork and Submit Pull Requests: We welcome any PRs that enhance 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!
308339
2. Open Issues: We appreciate reasonable suggestions and bug reports.
309340
3. Donate: If this project has helped you, consider buying us a coffee using the Sponsor button at the top of the project. Cheers!
310341
4. Spread the Word: Recommend this project to others, star the repo, or add a backlink after using the project.
311342
312343
## Questions, Suggestions, Issues, or Bugs?
313344
314-
We use GitHub Issues to manage feedback. Feel free to open an issue, and we'll address it promptly.
345+
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.
315346
316347
## License
317348
318-
LGPL-3.0 or later
349+
The license of this project is LGPL-3.0 or later. See [LICENSE](LICENSE) for more information.
319350
320351
## Related Links
321352

README_CN.md

Lines changed: 4 additions & 3 deletions
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)