Skip to content

Generating Images

Project Setup

Terminal window
# Create a project directory.
mkdir prodia-image-generation
cd prodia-image-generation

Install Node (if not already installed):

Terminal window
brew install node
# Close the current terminal and open a new one so that node is available.

Create project skeleton:

Terminal window
# Requires node --version >= 18
# Initialize the project with npm.
npm init -y
# Install the prodia-js library.
npm install prodia --save
Terminal window
# Export your token so it can be used by the main code.
export PRODIA_TOKEN=your-token-here

Create a main file for your project:

main.js
const { createProdia } = require("prodia/v2");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN // get it from environment
});

You’re now ready to make some API calls!

Generate an image

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
// run a flux dev generation
const job = await prodia.job({
type: "inference.flux.dev.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k"
}
});
const image = await job.arrayBuffer();
await fs.writeFile("puppies.jpg", new Uint8Array(image));
// open puppies.jpg
})();
Terminal window
node main.js
Terminal window
open puppies.jpg

Full Example

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
// run a flux dev generation
const job = await prodia.job({
type: "inference.flux.dev.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k"
}
});
const image = await job.arrayBuffer();
await fs.writeFile("puppies.jpg", new Uint8Array(image));
// open puppies.jpg
})();
Terminal window
node main.js