import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3, ImageModelV3, SpeechModelV3 } from '@ai-sdk/provider'; import { FetchFunction } from '@ai-sdk/provider-utils'; /** * Types for Pollinations API */ /** * Language model settings that can be passed when creating a language model * or via providerOptions.pollinations (providerOptions take precedence) */ interface PollinationsLanguageModelSettings { /** Request log probabilities */ logprobs?: boolean; /** Number of top log probabilities to return */ top_logprobs?: number; /** Enable parallel tool calls */ parallel_tool_calls?: boolean; /** User identifier for tracking */ user?: string; /** Modalities to use (e.g., ['text', 'audio']) */ modalities?: string[]; /** Audio output configuration */ audio?: { voice?: string; format?: string; }; /** Repetition penalty (alternative to frequency_penalty) */ repetition_penalty?: number; /** Logit bias to modify token likelihood */ logit_bias?: Record; /** Streaming options */ stream_options?: { include_usage?: boolean; }; /** Thinking configuration for reasoning models */ thinking?: { type?: 'enabled' | 'disabled'; budget_tokens?: number; }; /** Reasoning effort level */ reasoning_effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; /** Thinking budget (alternative to thinking.budget_tokens) */ thinking_budget?: number; /** Additional options are allowed for future API updates */ [key: string]: unknown; } /** * Image model settings that can be passed when creating an image model * or via providerOptions.pollinations (providerOptions take precedence) */ interface PollinationsImageModelSettings { /** * Remove Pollinations logo from generated images. * @default false */ nologo?: boolean; /** * Enhance image quality. * @default false */ enhance?: boolean; /** * Make image private (not shown in public feed). * @default false */ private?: boolean; } /** * Response types for Pollinations API */ interface PollinationsResponse { id: string; object: string; created: number; model: string; /** * Optional list of citation URLs returned by the model (e.g. Perplexity-style responses). */ citations?: string[]; choices: Array<{ index: number; message: { role: string; content: string | null; reasoning_content?: string | null; tool_calls?: Array<{ id: string; type: 'function'; function: { name: string; arguments: string; }; }>; annotations?: Array<{ url_citation?: { url?: string; title?: string | null; }; }>; }; finish_reason: string | null; /** * Optional grounding metadata for models that provide grounded answers * (e.g. Google / Vertex-style responses). * * This is intentionally loosely typed and focused on the fields we use for * extracting sources. */ groundingMetadata?: { groundingChunks?: Array<{ web?: { uri?: string | null; title?: string | null; domain?: string | null; } | null; retrievedContext?: { uri?: string | null; title?: string | null; text?: string | null; fileSearchStore?: string | null; } | null; maps?: { uri?: string | null; title?: string | null; text?: string | null; placeId?: string | null; } | null; }>; } | null; }>; usage?: { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; completion_tokens_details?: { reasoning_tokens?: number; audio_tokens?: number; }; prompt_tokens_details?: { cached_tokens?: number; audio_tokens?: number; }; }; } interface PollinationsStreamChunk { id: string; object: string; created: number; model: string; /** * Optional list of citation URLs returned by the model (e.g. Perplexity-style responses). */ citations?: string[]; choices: Array<{ index: number; delta: { role?: string; content?: string; reasoning_content?: string; tool_calls?: Array<{ index?: number; id?: string; type?: 'function'; function?: { name?: string; arguments?: string; }; }>; annotations?: Array<{ url_citation?: { url?: string; title?: string | null; }; }>; }; finish_reason?: string | null; groundingMetadata?: PollinationsResponse['choices'][number]['groundingMetadata']; }>; usage?: { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; completion_tokens_details?: { reasoning_tokens?: number; audio_tokens?: number; }; prompt_tokens_details?: { cached_tokens?: number; audio_tokens?: number; }; }; } /** * Available Pollinations image model IDs * Based on: https://gen.pollinations.ai/image/models */ type PollinationsImageModelId = 'kontext' | 'turbo' | 'nanobanana' | 'nanobanana-pro' | 'seedream' | 'seedream-pro' | 'gptimage' | 'gptimage-large' | 'flux' | 'zimage' | 'veo' | 'seedance' | 'seedance-pro' | string; declare class PollinationsLanguageModel implements LanguageModelV3 { readonly specificationVersion = "v3"; readonly provider: string; readonly modelId: string; private readonly settings; private readonly config; constructor(modelId: string, settings: PollinationsLanguageModelSettings, config: PollinationsConfig); readonly supportedUrls: { 'image/*': RegExp[]; 'application/pdf': RegExp[]; 'audio/wav': RegExp[]; 'audio/x-wav': RegExp[]; 'audio/mpeg': RegExp[]; 'audio/mp3': RegExp[]; }; private getArgs; doGenerate(options: LanguageModelV3CallOptions): Promise; doStream(options: LanguageModelV3CallOptions): Promise; } /** * Available Pollinations language (text) model IDs * Based on: https://gen.pollinations.ai/v1/models */ type PollinationsLanguageModelId = 'openai' | 'openai-fast' | 'openai-large' | 'openai-audio' | 'gemini' | 'gemini-fast' | 'gemini-large' | 'gemini-search' | 'claude' | 'claude-fast' | 'claude-large' | 'mistral' | 'deepseek' | 'grok' | 'perplexity-fast' | 'perplexity-reasoning' | 'qwen-coder' | 'kimi' | 'nova-fast' | 'glm' | 'minimax' | 'chickytutor' | 'midijourney' | string; type PollinationsSpeechModelId = 'openai' | 'openai-fast' | 'openai-large' | 'openai-audio' | (string & {}); type PollinationsVoice = 'alloy' | 'echo' | 'fable' | 'onyx' | 'shimmer' | 'coral' | 'verse' | 'ballad' | 'ash' | 'sage' | 'amuch' | 'dan'; type PollinationsAudioFormat = 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16'; interface PollinationsProvider extends ProviderV3 { (modelId: string): PollinationsLanguageModel; /** * Creates a Pollinations model for text generation. */ languageModel(modelId: PollinationsLanguageModelId, settings?: PollinationsLanguageModelSettings): PollinationsLanguageModel; /** * Creates a Pollinations model for text generation. */ chat(modelId: PollinationsLanguageModelId, settings?: PollinationsLanguageModelSettings): PollinationsLanguageModel; /** * Creates a Pollinations model for image generation. */ imageModel(modelId: PollinationsImageModelId, settings?: PollinationsImageModelSettings): ImageModelV3; /** * Creates a Pollinations model for image generation. */ image(modelId: PollinationsImageModelId, settings?: PollinationsImageModelSettings): ImageModelV3; /** * Creates a Pollinations model for speech/audio generation. */ speechModel(modelId: PollinationsSpeechModelId): SpeechModelV3; /** * Creates a Pollinations model for speech/audio generation. */ audio(modelId: PollinationsSpeechModelId): SpeechModelV3; } interface PollinationsProviderSettings { /** * API key for authenticating requests (optional). * Get one at: {@link EXTERNAL_URLS.AUTH} */ apiKey?: string; /** * Base URL for API calls. * @default See {@link LEGACY_API_ENDPOINTS.LANGUAGE} for legacy, {@link API_ENDPOINTS.LANGUAGE} for new */ baseURL?: string; /** * Base URL for image generation API calls. * @default See {@link LEGACY_API_ENDPOINTS.IMAGE_BASE} for legacy, {@link API_ENDPOINTS.IMAGE} for new */ imageURL?: string; /** * Referrer identifier for analytics (optional). */ referrer?: string; /** * Custom headers to include in the requests. */ headers?: Record; /** * Provider name. Overrides the `pollinations` default name. */ name?: string; /** * Custom fetch implementation. * * You can use this to: * - Add custom request/response interceptors * - Use a different fetch implementation (e.g., node-fetch, undici) * - Add retries or custom error handling * - Mock fetch for testing * * @default globalThis.fetch */ fetch?: FetchFunction; /** * Whether to use legacy Pollinations API URLs. * * When `false` (default), uses the new unified API endpoints: * - Language models: {@link API_ENDPOINTS.LANGUAGE} * - Image models: {@link API_ENDPOINTS.IMAGE} * - API key parameter: {@link API_KEY_PARAMS.NEW} (in query string) * * When `true`, uses legacy API endpoints: * - Language models: {@link LEGACY_API_ENDPOINTS.LANGUAGE} * - Image models: {@link LEGACY_API_ENDPOINTS.IMAGE} * - API key parameter: {@link API_KEY_PARAMS.LEGACY} (in query string) * * **When to use legacy URLs:** * - Existing integrations that depend on legacy endpoints * - Backward compatibility with older API versions * - Testing or migration scenarios * * **Recommendation:** Use the default (`false`) for new projects as the new * unified API provides better consistency and future-proofing. * * @default false */ useLegacyUrls?: boolean; } interface PollinationsConfig { provider: string; baseURL: string; headers: () => Record; queryParams: () => Record; generateId: () => string; fetch?: FetchFunction; referrer?: string; } /** * Create a Pollinations provider instance. */ declare function createPollinations(options?: PollinationsProviderSettings): PollinationsProvider; export { type PollinationsAudioFormat, type PollinationsConfig, type PollinationsImageModelSettings, type PollinationsLanguageModelSettings, type PollinationsProvider, type PollinationsProviderSettings, type PollinationsResponse, type PollinationsSpeechModelId, type PollinationsStreamChunk, type PollinationsVoice, createPollinations };