---
name: pollinations-pollinations-sdk
description: "Use the official @pollinations/sdk npm package when writing JavaScript apps or scripts that call Pollinations. Covers installation, API-key authentication, and a first text or image request."
license: "MIT"
metadata:
  decimalai-skill-id: "c5da9e49-be15-4108-8ecb-784a55e51525"
  decimalai-version-id: "94075066-e88b-43bb-93a2-eacc31ecbd3e"
  decimalai-version: "4"
  decimalai-body-sha256: "1ecd203cd8836878a31fbb8c52ce7605fe9f9d1a320f7549b7cd0d4f72f162dd"
  decimalai-name: "pollinations/pollinations-sdk"
  decimalai-format: "1"
  decimalai-invocation: "model"
  decimalai-category: "coding"
  decimalai-source: "https://app.decimal.ai/s/pollinations-pollinations-sdk@4/SKILL.md"
---
# Pollinations SDK quickstart

These examples use the published stable SDK 5.0.0, not the repository's
in-progress alpha API. Check the installed version's types before using other
helpers; methods on `main` may not exist in the published package.

## Install and authenticate

```bash
npm install @pollinations/sdk@5.0.0
```

Get a key at https://enter.pollinations.ai/keys and set
`POLLINATIONS_API_KEY` in the process environment. Never print it or commit it.
Requests spend from the user's balance: confirm the intended model and budget before running.

Save this as `example.mjs` and run `node example.mjs`:

```js
import { configure, generateText, generateImage } from "@pollinations/sdk";

configure({ apiKey: process.env.POLLINATIONS_API_KEY });

const text = await generateText("Write a short haiku about a garden.");
console.log(text);

const image = await generateImage("A small garden in watercolor.");
await image.saveToFile("garden.png");
```

Check that text is nonempty and `garden.png` is readable. The helpers return a
single result by default; `n` requests multiple results. `saveToFile` is Node-only.

## Beyond the quickstart

- For current model IDs, query https://gen.pollinations.ai/models. Pass a chosen
  ID through the helper's `{ model }` option; do not invent model names.
- For browser apps, use a publishable app key and Pollinations Pay rather than
  embedding a secret key. See the [Pollinations Pay guide](https://gen.pollinations.ai/docs/llm.txt?section=byop).
- For device authorization, React, streaming, editing, and other media, consult the
  [5.0.0 package docs](https://www.npmjs.com/package/@pollinations/sdk/v/5.0.0)
  and its installed type declarations. Verify signatures before copying examples
  from a newer release.
- If no npm package is needed, use the [REST API guide](https://gen.pollinations.ai/docs/llm.txt).
