import { Client } from "modelslab";// Method 1: Direct API keyconst client = new Client("your-api-key");// Method 2: Environment variable// Reads from process.env.API_KEY when called without argsconst clientFromEnv = new Client();// Method 3: With custom settings// new Client(apiKey, retries, timeoutSeconds)const clientCustom = new Client("your-api-key", 5, 10);
console.log(client.baseUrl); // API base URLconsole.log(client.fetchRetry); // Number of retriesconsole.log(client.fetchTimeout); // Timeout in seconds
import { Community, Audio, Video, ImageEditing } from "modelslab";// Create instances with your API keyconst community = new Community(client.key);const audio = new Audio(client.key);const video = new Video(client.key);const imageEditing = new ImageEditing(client.key);
// Pass true as second argument for enterprise modeconst enterpriseCommunity = new Community(client.key, true);// Uses endpoints like: https://modelslab.com/api/v1/enterprise/images/
import { Client, Audio } from "modelslab";const client = new Client("your-api-key");const audio = new Audio(client.key);const result = await audio.textToAudio({ key: client.key, prompt: "A calm piano melody with soft strings in the background", duration: 30 // Duration in seconds});console.log("Audio URL:", result.output[0]);
const result = await audio.textToSpeech({ key: client.key, text: "Hello! Welcome to ModelsLab. This is a sample of our text-to-speech API.", voice_id: "alloy", // Choose from available voices language: "en"});console.log("Speech URL:", result.output[0]);
const result = await audio.musicGen({ key: client.key, prompt: "Upbeat electronic dance music with heavy bass drops and synth melodies", duration: 30});console.log("Generated music:", result.output[0]);
const result = await audio.lyricsGen({ key: client.key, prompt: "Write lyrics for a pop song about summer love and road trips"});console.log("Generated lyrics:", result.output);
const result = await audio.songGenerator({ key: client.key, prompt: "A country ballad about hometown memories", lyrics: "Optional: your custom lyrics here"});console.log("Generated song:", result.output[0]);
const result = await audio.sfxGen({ key: client.key, prompt: "Thunder rolling in the distance with heavy rain on a metal roof", duration: 10});console.log("Sound effect URL:", result.output[0]);
const result = await imageEditing.outpainting({ key: client.key, image: "https://example.com/photo.jpg", prompt: "Continue the landscape with mountains and trees", width: 1024, // New width (larger than original) height: 768 // New height});console.log("Extended image:", result.output[0]);
const result = await imageEditing.objectRemover({ key: client.key, image: "https://example.com/photo.jpg", mask_image: "https://example.com/mask.png" // White areas will be removed});console.log("Object removed:", result.output[0]);
const result = await imageEditing.facegen({ key: client.key, image: "https://example.com/portrait.jpg", prompt: "Make the person look 10 years younger"});console.log("Face generation result:", result.output[0]);