Pollinations AI
by @kanfred
Generate images, music, and videos from text prompts using Pollinations AI with models like flux, zimage, and suno-4 via API key.
Image Generation
# Basic usage
python pollinations_image_gen.py "a cute cat" --output cat.jpgWith specific model and enhancements
python pollinations_image_gen.py "cyberpunk city at night" --model flux --enhance --width 1920 --height 1080 --output city.jpgUsing different models
python pollinations_image_gen.py "your prompt" --model zimage
python pollinations_image_gen.py "your prompt" --model flux-2-dev # Free tier
Parameters:
| Parameter | Description | Default |
|-----------|-------------|---------|
| prompt | Text description of desired image | (required) |
| --model | AI model to use | flux |
| --width | Image width in pixels | 1024 |
| --height | Image height in pixels | 1024 |
| --enhance | Enable AI prompt enhancement | false |
| --seed | Fixed random seed for reproducibility | random |
| --safe | Enable safe mode | false |
| --output | Output filename | output.jpg |
| --telegram | Send result via Telegram (requires TELEGRAM_CHAT_ID) | false |
Music/Audio Generation
# Generate music from prompt
python pollinations_audio_gen.py "upbeat electronic dance music" --output music.mp3With custom duration
python pollinations_audio_gen.py "calm piano melody" --duration 60 --output piano.mp3
Parameters:
| Parameter | Description | Default |
|-----------|-------------|---------|
| prompt | Description of desired music | (required) |
| --model | Audio model | suno-4 |
| --duration | Length in seconds | 30 |
| --output | Output filename | output.mp3 |
Video Generation
# Generate video
python pollinations_video_gen.py "a cat playing with a ball" --output video.mp4Custom duration and aspect ratio
python pollinations_video_gen.py "ocean waves" --duration 30 --aspectRatio 16:9 --output ocean.mp4
Parameters:
| Parameter | Description | Default |
|-----------|-------------|---------|
| prompt | Description of desired video | (required) |
| --model | Video model | suno-4 |
| --duration | Length in seconds | 10 |
| --aspectRatio | Video aspect ratio (16:9 or 9:16) | 16:9 |
| --output | Output filename | output.mp4 |
1. Get an API Key
Visit pollinations.ai to get your free API key.
2. Set Environment Variable
Add to your shell profile (~/.bashrc or ~/.zshrc):
export POLLINATIONS_API_KEY="your_api_key_here"
Then reload:
source ~/.bashrc
3. Install Dependencies
pip install requests Pillow
| Error | Cause | Solution |
|-------|-------|----------|
| 401 Unauthorized | Missing or invalid API key | Set POLLINATIONS_API_KEY correctly |
| 403 Forbidden | API key lacks permission | Check your key permissions at pollinations.ai |
| 429 Too Many Requests | Rate limit exceeded | Wait before making more requests |
| 402 Payment Required | Insufficient balance | Add credits at pollinations.ai |
clawhub install pollinations-ai