Official JavaScript SDK for the Loudly AI Music API. Generate AI-powered songs, across 50+ genres, with pre-set prompts and parameters like energy, tempo, key and song structures via an easy intuitive interface. 100% Ethical AI and Copyright-Safe.
import LoudlyJSSDK from "loudly-js-sdk";
const sdk = new LoudlyJSSDK({
apiKey: "your_api_key_here"
});
// Generate a song from a prompt
const song = await sdk.createSongFromPrompt({
prompt: "A 90-second energetic house track with tropical vibes and flute"
});
console.log(song);Install the SDK via npm:
npm install loudly-js-sdk- Create an account on the (https://www.loudly.com/music-api)
- Navigate to your account dashboard
- Generate an API key
- Copy your API key for authentication
Environment Variables (Recommended)
Create a .env file in your project root:
LOUDLY_API_KEY=your_api_key_hereThen initialize the SDK:
import dotenv from "dotenv";
import LoudlyJSSDK from "loudly-js-sdk";
dotenv.config();
const sdk = new LoudlyJSSDK({
apiKey: process.env.LOUDLY_API_KEY
});Retrieve account usage limits for a specified date range.
const limits = await sdk.getAccountLimits({
dateFrom: "2025-01-01",
dateTo: "2025-01-31"
});Generate a song with detailed parameters.
const song = await sdk.createSong({
genre: "House",
duration: "90",
energy: "high",
bpm: "128",
key_root: "C",
key_quality: "major",
instruments: "piano, drums"
});Generate a song directly from a natural language prompt.
const song = await sdk.createSongFromPrompt({
prompt: "A 90-second energetic house track with tropical vibes and flute",
duration: "90"
});Fetch all available music genres.
const genres = await sdk.getGenres();Retrieve available song structures.
const structures = await sdk.getStructures();Get all available song tags for categorization.
const tags = await sdk.getSongTags();Search and filter songs with various parameters.
const songs = await sdk.getSongs({
genre: "House",
mood: "Energetic",
limit: 10,
page: 1
});Generate a random AI prompt for inspiration.
const prompt = await sdk.getRandomPrompt();import LoudlyJSSDK from "loudly-js-sdk";
const sdk = new LoudlyJSSDK({
apiKey: process.env.LOUDLY_API_KEY
});
async function generateSong() {
try {
// Create a song with specific parameters
const song = await sdk.createSong({
genre: "Electronic",
duration: "120",
energy: "medium",
bpm: "120",
key_root: "A",
key_quality: "minor"
});
console.log("Song created:", song);
} catch (error) {
console.error("Error generating song:", error.message);
}
}
generateSong();async function exploreOptions() {
try {
// Get all available genres
const genres = await sdk.getGenres();
console.log("Available genres:", genres);
// Get song structures
const structures = await sdk.getStructures();
console.log("Available structures:", structures);
// Get random prompt for inspiration
const prompt = await sdk.getRandomPrompt();
console.log("Random prompt:", prompt);
} catch (error) {
console.error("Error:", error.message);
}
}async function searchSongs() {
try {
const songs = await sdk.getSongs({
genre: "Ambient",
mood: "Relaxing",
limit: 5
});
console.log(`Found ${songs.length} ambient songs`);
songs.forEach(song => {
console.log(`- ${song.title} (${song.duration}s)`);
});
} catch (error) {
console.error("Error searching songs:", error.message);
}
}loudly-js-sdk/
βββ src/
β βββ loudlyjssdk.js # Core SDK implementation
βββ test/
β βββ test.js # Example usage and tests
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ package.json # Package configuration
βββ LICENSE # MIT License
The SDK throws descriptive errors when something goes wrong. Always wrap API calls in try-catch blocks:
try {
const song = await sdk.createSong(params);
// Handle successful response
} catch (error) {
console.error("API Error:", error.message);
// Handle error appropriately
}- All methods return JSON responses directly from the Loudly API
- API responses may vary based on your account tier and limits
- Store your API key securely using environment variables
- Rate limiting may apply based on your account plan
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please:
- Search existing GitHub issues
- Create a new issue if needed
Made with β€οΈ by the Loudly team