A simple and powerful Node.js package that allows you to easily access all Pollinations features, including image generation and LLM capabilities, using their free API.
- Installation
- Usage 3. Image Generation 4. Text Generation
- API Methods
- Examples
- Debugging
- License
To install the pollinations
package, use npm:
npm install pollinations
const Pollinations = require("pollinations");
const pollinations = new Pollinations();
// Generate an image
pollinations.images
.generateImage({
prompt: "A futuristic city at sunset",
model: "flux-anime",
width: 1024,
height: 768
})
.then(image => {
// Save the generated image
require("fs").writeFileSync("generated-image.png", image);
})
.catch(error => console.error(error));
To generate images, you can use the images
namespace.
pollinations.images
.generateImage({
prompt: "A futuristic city skyline",
model: "flux",
width: 800,
height: 600
})
.then(imageBuffer => {
// Handle the generated image buffer here
})
.catch(error => {
console.error(error);
});
To generate text using LLM models, use the llm
namespace.
pollinations.llm
.generateTextGet({
prompt: "Tell me a joke.",
model: "openai"
})
.then(text => {
console.log(text);
})
.catch(error => {
console.error(error);
});
getModels()
Fetches a list of available image generation models.
pollinations.images
.getModels()
.then(models => {
console.log(models);
})
.catch(error => {
console.error(error);
});
generateImage(options)
This method generates an image based on the provided options.
Parameter | Type | Description |
---|---|---|
options |
Object |
The options for image generation. |
options.prompt |
string |
The text prompt for image generation. |
options.model |
string |
The model to use for image generation (default is "flux" ). |
options.seed |
number |
The seed for random generation (optional, default is null ). |
options.width |
number |
The width of the generated image in pixels (default is 512 ). |
options.height |
number |
The height of the generated image in pixels (default is 512 ). |
options.nologo |
boolean |
Whether to remove the logo from the image (default is false ). |
options.private |
boolean |
Whether the image is private (default is false ). |
options.enhance |
boolean |
Whether to apply enhancement to the image (default is false ). |
options.safe |
boolean |
Whether to apply safety filters to the image (default is false ). |
getModels()
Fetches a list of available text generation models.
pollinations.llm
.getModels()
.then(models => {
console.log(models);
})
.catch(error => {
console.error(error);
});
generateTextGet(options)
Generates text based on the given prompt and options.
Parameter | Type | Description |
---|---|---|
options.prompt |
string |
The text prompt used for generating the content. |
options.model |
string |
Optional. The model to use for text generation (default is "openai" ). |
options.seed |
number |
Optional. The seed for random generation (default is null ). |
options.json |
boolean |
Optional. Whether to return the response as JSON (default is false ). |
options.system |
string |
Optional. The system message (default is an empty string). |
generateTextPost(options)
Generates text based on the given messages and options.
Parameter | Type | Description |
---|---|---|
options.messages |
Array |
The array of messages to send as the conversation history. |
options.model |
string |
Optional. The model to use for text generation (default is "openai" ). |
options.seed |
number |
Optional. The seed for random generation (default is null ). |
options.jsonMode |
boolean |
Optional. Whether to return the response as JSON (default is false ). |
To enable debugging, pass the debug
option when creating a Pollinations
instance:
const pollinations = new Pollinations({ debug: true });
When debugging is enabled, the package will log detailed information about API requests, responses, and warnings to the console.
This project is licensed under the Creative Commons Zero (CC0) License. You can modify, distribute, and use it freely, with no attribution required.