Ayogiakbar

Suno V3

Oct 2nd, 2025 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require("axios");
  2.  
  3. class SunoFree {
  4.   constructor() {
  5.     this.API_KEY = "a03a378e05004f27b17ccd712721b18b"; // Ganti kalau punya API key sendiri
  6.     this.API_URL = "https://api.topmediai.com/v1/music";
  7.   }
  8.  
  9.   async requestMusic(payload) {
  10.     try {
  11.       const res = await axios.post(this.API_URL, payload, {
  12.         headers: {
  13.           "x-api-key": this.API_KEY,
  14.           "Content-Type": "application/json",
  15.           "User-Agent": "okhttp/5.0.0-alpha.3"
  16.         }
  17.       });
  18.  
  19.       if (res.data?.status === 200 && Array.isArray(res.data.data)) {
  20.         return res.data.data.map((item) => ({
  21.           title: item.title || "Lagu AI",
  22.           audio_url: item.audio_file,
  23.           duration: 0,
  24.           image_url: item.image_file || "",
  25.           tags: item.tags || "AI Music",
  26.           mode: payload.is_auto
  27.             ? "auto"
  28.             : payload.instrumental
  29.             ? "instrumental"
  30.             : payload.lyrics
  31.             ? "custom"
  32.             : "normal"
  33.         }));
  34.       } else {
  35.         throw new Error("Respons API tidak valid");
  36.       }
  37.     } catch (err) {
  38.       throw new Error(err.response?.data?.message || err.message);
  39.     }
  40.   }
  41.  
  42.   // Mode normal → AI bikin lirik & judul otomatis
  43.   async generateNormal(prompt) {
  44.     return this.requestMusic({
  45.       instrumental: 0,
  46.       is_auto: 1,
  47.       lyrics: "",
  48.       prompt
  49.     });
  50.   }
  51.  
  52.   // Mode custom → user kasih genre & lirik, judul otomatis
  53.   async generateCustom({ prompt, style, lyrics }) {
  54.     if (!style || !lyrics) throw new Error("Genre dan lirik wajib diisi");
  55.     return this.requestMusic({
  56.       instrumental: 0,
  57.       is_auto: 0,
  58.       lyrics,
  59.       prompt: `${prompt} in style ${style}`
  60.     });
  61.   }
  62.  
  63.   // Mode instrumental → tanpa lirik
  64.   async generateInstrumental(prompt) {
  65.     return this.requestMusic({
  66.       instrumental: 1,
  67.       is_auto: 0,
  68.       lyrics: "",
  69.       prompt
  70.     });
  71.   }
  72. }
  73.  
  74. module.exports = new SunoFree();
  75.  
Advertisement
Add Comment
Please, Sign In to add comment