New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pollinations

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pollinations

A Node.js package that allows you to easily access all Pollinations features, including image generation and LLM capabilities, using their free API.

  • 2.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
0
Weekly downloads
 
Created
Source

Pollinations Node.js Package

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.

Table of Contents

  1. Installation
  2. Usage 3. Image Generation 4. Text Generation
  3. API Methods
  4. Examples
  5. Debugging
  6. License

Installation

To install the pollinations package, use npm:

  npm install pollinations

Usage

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));

Image Generation

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);
  });

Text Generation

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);
  });

API Methods

Image Methods

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.

ParameterTypeDescription
optionsObjectThe options for image generation.
options.promptstringThe text prompt for image generation.
options.modelstringThe model to use for image generation (default is "flux").
options.seednumberThe seed for random generation (optional, default is null).
options.widthnumberThe width of the generated image in pixels (default is 512).
options.heightnumberThe height of the generated image in pixels (default is 512).
options.nologobooleanWhether to remove the logo from the image (default is false).
options.privatebooleanWhether the image is private (default is false).
options.enhancebooleanWhether to apply enhancement to the image (default is false).
options.safebooleanWhether to apply safety filters to the image (default is false).

LLM Methods

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.

ParameterTypeDescription
options.promptstringThe text prompt used for generating the content.
options.modelstringOptional. The model to use for text generation (default is "openai").
options.seednumberOptional. The seed for random generation (default is null).
options.jsonbooleanOptional. Whether to return the response as JSON (default is false).
options.systemstringOptional. The system message (default is an empty string).

generateTextPost(options) Generates text based on the given messages and options.

ParameterTypeDescription
options.messagesArrayThe array of messages to send as the conversation history.
options.modelstringOptional. The model to use for text generation (default is "openai").
options.seednumberOptional. The seed for random generation (default is null).
options.jsonModebooleanOptional. Whether to return the response as JSON (default is false).

Debugging

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.

License

This project is licensed under the Creative Commons Zero (CC0) License. You can modify, distribute, and use it freely, with no attribution required.

FAQs

Package last updated on 21 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc