This is a Python/FastAPI port of the original Suno API (previously implemented in Go). It provides endpoints to submit and fetch Suno music/lyrics generation tasks, as well as a chat-completion interface using OpenAI tools with Server-Sent Events (SSE) support.
- FastAPI web framework
- SQLAlchemy (SQLite/PostgreSQL/MySQL) with Alembic migrations
- Background task queue for polling Suno task status
- HTTP client using httpx with default Suno headers
- SSE streaming for chat completions via
sse-starlette
- Pydantic-based request/response schemas
- Configuration via
.env
andpython-dotenv
- Logging with loguru
- Integrated tests using pytest
git clone <repo_url>
cd suno-api-python
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
Copy .env
(provided) and set your values:
# .env
PORT=8000
DEBUG=false
SECRET_TOKEN=your_secret_token # optional
SESSION_ID=... # your Suno session ID
COOKIE=... # your Suno cookie string
DATABASE_URL=sqlite:///./api.db # or any SQLAlchemy URL
BASE_URL=https://studio-api.suno.ai
EXCHANGE_TOKEN_URL=https://clerk.suno.com/v1/client/sessions/{}/tokens?_clerk_js_version=4.73.2
CHAT_OPENAI_MODEL=gpt-4o
CHAT_OPENAI_BASE=https://api.openai.com
CHAT_OPENAI_KEY=sk-...
CHAT_TEMPLATE_DIR=./template
CHAT_TIME_OUT=600
PROXY= # optional HTTP proxy
LOG_DIR=./logs
ROTATE_LOGS=false
By default the app uses SQLite (api.db
). To create/migrate tables:
# Apply Alembic migrations (recommended)
alembic upgrade head
# Or let FastAPI auto-create tables on startup (init_db())
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
GET /ping
→ Health checkPOST /suno/submit/{music|lyrics}
→ Submit taskGET /suno/fetch/{id}
→ Fetch single taskPOST /suno/fetch
→ Fetch multiple tasksGET /suno/account
→ Account & billing infoPOST /v1/chat/completions
→ Chat-completion with SSE streaming (uses OpenAI + Suno tool)
Authentication: If SECRET_TOKEN
is set, requests must send Authorization: Bearer <SECRET_TOKEN>
header.
pytest
.
├── app/
│ ├── config.py # env vars loader
│ ├── database.py # SQLAlchemy setup
├── logger.py # loguru setup
├── models/ # SQLAlchemy models
├── routers/ # FastAPI routers
├── schemas/ # Pydantic schemas
├── services/ # business logic (Suno, account, tasks)
└── utils/ # HTTP client, templates, auth
├── alembic/ # Alembic migrations
├── requirements.txt
├── main.py # app entrypoint
└── README_python.md # this file
This project is released under the same license as the original Suno API.