// Please make sure that you run 'npm install @eachlabs/aiflow@latest'import Each from '@eachlabs/aiflow';const each = new Each({ auth: process.env.EACH_API_KEY || 'YOUR_API_KEY'});
When you call a model, you’ll receive a prediction ID that you can use to check the status and get results. The final response will include the model outputs and additional metadata. Here’s how to make the call and handle the response:
Copy
// Start the predictionconst response = await each.predictions.run({ model: "text-to-song-advanced", version: "0.0.1", input: { "lyrics": "I’m a little teapot, yes it’s true, Here’s an example of what I can do. I can change my handle and my spout, Just tip me over and pour me out!", "vocal": "female vocal", "mood": "relaxed", "genre": "pop" },});// Response contains the prediction IDconsole.log(response);// {// "status": "success", // "message": "Prediction created successfully",// "predictionID": "990619d5-9a78-42af-bf6f-90e4add5b228"// }// Poll for results using the prediction IDconst result = await each.predictions.get(response.predictionID);if (result.status === "success") { console.log("Prediction completed successfully:", result);} else if (result.status === "error") { console.log("Prediction failed:", result);} else if (result.status === "cancelled") { console.log("Prediction was cancelled:", result);}
Output can be array, object or stringified JSON. You can parse it as you want.
If the model / workflow returns an single URL, you need to parse it as a string.