Whitepaper
Docs
Sign In
Tool
Tool
v1.1
Pollinations
Tool ID
pollinations
Creator
@kuanjames
Downloads
73+
This tool allows you to use Pollinations.ai to generate images (no API setup and you can specify image aspect ratio)
Get
README
Tool Code
Show
""" title: Pollinations author: @kuanjames (original code is based on kaneki's GenAI (Pollinations)) email: # date: 2025-04-25 version: 1.1 license: # description: AI Image generations with SOTA models using free models from Pollinations.ai with lots of customizable options for the LLM """ import requests from requests.exceptions import RequestException from urllib.parse import quote from typing import Awaitable, Callable import asyncio class Tools: def __init__(self): pass async def create_image( self, prompt: str, __event_emitter__: Callable[ [dict], Awaitable[None] ], # Moved to before parameters with defaults image_format: str = "default", # Default parameters now come after non-default ones model: str = "latest", enhance: bool = False, ) -> str: await __event_emitter__( { "data": { "description": "Image generation started", "status": "in_progress", "done": False, }, "type": "status", } ) try: formats = { "default": (1920, 1080), "square": (1080, 1080), "landscape": (1920, 1080), "landscape_large": (2560, 1440), "portrait": (1080, 1920), "portrait_large": (1440, 2560), } if image_format not in formats: raise ValueError( f"Invalid aspect ratio: {image_format}. Use one of: {list(formats.keys())}" ) width, height = formats[image_format] url = f"https://image.pollinations.ai/prompt/{quote(prompt)}?width={width}&height={height}&model={model}&nologo=true&enhance={enhance}" response = await asyncio.to_thread(requests.get, url) await __event_emitter__( { "data": { "description": "Image generation finished", "status": "complete", "done": True, }, "type": "status", } ) return f"" except RequestException as e: error_msg = f"Network error: {str(e)}" await __event_emitter__( { "data": { "description": error_msg, "status": "complete", "done": True, }, "type": "status", } ) return error_msg except Exception as e: error_msg = f"Error: {str(e)}" await __event_emitter__( { "data": { "description": error_msg, "status": "complete", "done": True, }, "type": "status", } ) return error_msg