A Node.js REST API backend that generates music playlists using various LLM providers and Spotify integration.
- Modular architecture supporting multiple LLM providers
- Currently supports Gemini and Deepseek LLMs
- Spotify API integration for playlist creation
- Generate AI playlists based on venue, date, and music style
- Use your existing Spotify playlists as seed libraries
- Create and manage a DJ AI Song Library
- Easy to extend with additional LLM providers
- Node.js v16 or later
- npm or yarn or pnpm
- API keys for at least one of the supported LLM providers:
- Gemini API key from Google AI Studio
- Deepseek API key from Deepseek API
- Spotify Developer account and API credentials:
- Register a new app at Spotify Developer Dashboard
- Set the redirect URI to
http://127.0.0.1:3000/callback
-
Clone the repository
git clone https://github.com/yourusername/dj-ai-server.git cd dj-ai -
Install dependencies
pnpm install
-
Create a
.envfile by copying the examplecp .env.example .env
-
Edit the
.envfile and add your API keys and preferences:LLM_PROVIDER=gemini GEMINI_API_KEY=your_gemini_api_key DEEPSEEK_API_KEY=your_deepseek_api_key SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret PORT=3000
Start the server in development mode with auto-reload:
pnpm devRun the server with:
pnpm devThe server will start on port 3000 (or the port specified in your .env file).
Open your browser and navigate to:
http://127.0.0.1:3000/playlist-generator
- Click on the "Login with Spotify" link
- Authorize the application when prompted by Spotify
- You'll be redirected back to the playlist generator
-
Fill in the required fields:
- Venue: Enter the venue name (e.g., "La Tropical", "Casa de la Música")
- Date: Select the event date
- Style: Choose the music style from the dropdown (e.g., "Timba heavy", "Traditional Son")
- Spotify Playlist ID or URL (optional): Enter a Spotify playlist ID or URL to use as the source library
- If left empty, the app will use the "DJ AI Song Library" playlist
-
Click "Generate Playlist"
-
Wait for the AI to generate the playlist (this may take a minute or two)
-
Once completed, you'll see a link to open the newly created playlist in Spotify
The new playlist will be available in your Spotify account with the songs organized into:
- Warmup songs
- Peak time songs
- Cooldown songs
This application can be deployed to Vercel. Follow these steps:
- Fork or clone the repository to your GitHub account
- Sign up for a Vercel account
- Create a new project in Vercel and connect it to your GitHub repository
- Configure the following environment variables in Vercel's project settings:
LLM_PROVIDER: Choose "gemini" or "deepseek"GEMINI_API_KEY: Your Google Gemini API keyDEEPSEEK_API_KEY: Your Deepseek API keySPOTIFY_CLIENT_ID: Your Spotify application client IDSPOTIFY_CLIENT_SECRET: Your Spotify application client secret
- Important: Update the Spotify redirect URI in your Spotify Developer Dashboard to match your Vercel domain (e.g.,
https://your-app-name.vercel.app/callback) - Deploy the project
If you encounter a 404 error after deployment, check the following:
- Ensure all environment variables are correctly set in Vercel
- Verify that your Spotify redirect URI is updated to use your Vercel domain
- Check the function logs in the Vercel dashboard for any errors
- Make sure your Spotify app has the correct scopes enabled
- BPM Detection: The application cannot access Spotify's "Audio Features" API to get BPM (tempo) information. This is a limitation of the Spotify API permissions. The AI makes recommendations based on music style and not actual BPM data.
- Library Creation: First-time users will need to create a "DJ AI Song Library" (can be any name) playlist by using the application or by himself.
Endpoint: POST /generate
Request Body:
{
"venue": "La Tropical",
"date": "2023-07-15",
"style": "Timba heavy",
"playlistId": "spotify:playlist:37i9dQZF1DXdSjVZQzv2tl"
}Response:
{
"success": true,
"data": {
"playlist": "... generated playlist content ...",
"provider": "gemini",
"inputs": {
"venue": "La Tropical",
"date": "2023-07-15",
"style": "Timba heavy"
}
}
}You can configure the following options in your .env file:
LLM_PROVIDER: The LLM provider to use (options: "gemini", "deepseek")GEMINI_API_KEY: Your Google Gemini API keyDEEPSEEK_API_KEY: Your Deepseek API keySPOTIFY_CLIENT_ID: Your Spotify application client IDSPOTIFY_CLIENT_SECRET: Your Spotify application client secretPORT: Server port (default: 3000)
To add a new LLM provider:
- Create a new provider class in
src/llm/providers/that implements theLLMProviderinterface - Add the new provider to the factory in
src/llm/providerFactory.ts - Update the environment variable options