To integrate Lovable with Pixabay, create a Supabase Edge Function that proxies Pixabay API requests using your API key stored in Cloud → Secrets. Pixabay's API provides free access to over 4 million royalty-free images and videos. Use Lovable's chat to build image search UIs, media pickers, and gallery components with optional Supabase caching for performance.
Add free stock images and videos to Lovable apps with the Pixabay API
Pixabay hosts over 4 million free images, illustrations, vectors, and videos contributed by a community of creators under the Pixabay Content License, which allows free commercial and non-commercial use without attribution requirements. The API provides search, filtering, and direct access to multiple image resolutions — from small thumbnails for grid displays to large originals for download.
The API is one of the most accessible in the stock media space: registration is free, the API key is issued immediately upon account creation, and there are no licensing fees for any content accessed through the API. Rate limits are generous (500 requests per hour by default, with higher limits for approved applications), making Pixabay practical for production applications with moderate traffic.
Pixabay is different from Getty Images and Shutterstock in a fundamental way: Pixabay content is community-contributed and freely licensed, while Getty and Shutterstock host professionally produced, commercially licensed content. Pixabay images are excellent for decorative backgrounds, generic concept photography, and UI illustrations. For content that requires editorial photography of specific news events, celebrities, or branded commercial imagery, Getty or Shutterstock are more appropriate. For many product and marketing use cases — blog imagery, UI mockups, icon backgrounds, hero images — Pixabay provides high enough quality without any licensing cost.
Integration method
Pixabay API uses a simple API key for authentication. While the Pixabay API is less sensitive than a payment or advertising credential, API keys should still stay server-side — exposing them in browser code allows anyone to make API calls against your rate limit quota. A lightweight Supabase Edge Function proxies Pixabay search requests and enables server-side Supabase caching to minimize API calls.
Prerequisites
- A Lovable account with a project that has Lovable Cloud enabled
- A Pixabay account — free to create at pixabay.com
- A Pixabay API key — generated immediately after account creation at pixabay.com/api/docs
- An understanding of Pixabay's content license — all Pixabay images are free for commercial use with no attribution required, but API usage must comply with Pixabay's terms
Step-by-step guide
Get your Pixabay API key
Get your Pixabay API key
Navigate to pixabay.com and create a free account if you do not have one. Once logged in, go to pixabay.com/api/docs. The API documentation page shows your personal API key at the top — it is automatically generated for every registered Pixabay user. Your API key is a numeric string. Copy it. This key authenticates your API calls and is associated with your Pixabay account's rate limit quota (500 requests per hour for standard accounts). Pixabay's API terms of service require that you add a link back to Pixabay (pixabay.com/service/license-summary/) when displaying images from the API in your application. Display this link somewhere visible in your image gallery or picker UI — in a footer, a tooltip on each image, or an attribution note. Attribution to individual photographers is optional but recommended as good practice. One important API restriction: you cannot display Pixabay image URLs directly as hotlinked images in a large-scale production app without prior approval from Pixabay. For apps with expected high traffic (millions of image views), contact Pixabay through their developer contact form to discuss usage. For most Lovable projects, standard API usage is fully permitted.
Pro tip: Pixabay generates your API key automatically when you create an account — there is no separate developer registration or wait period. Your key is visible at pixabay.com/api/docs as soon as you are logged in.
Expected result: You have a Pixabay API key — a numeric string visible at pixabay.com/api/docs while logged in.
Store your Pixabay API key in Cloud → Secrets
Store your Pixabay API key in Cloud → Secrets
Open your Lovable project and click the '+' icon next to the Preview label to open the Cloud panel. Navigate to the Secrets tab and add: - Name: PIXABAY_API_KEY — Value: your Pixabay API key from the documentation page While Pixabay's API key is less sensitive than a payment credential or social OAuth token (it only provides access to public content search), keeping it in Cloud → Secrets prevents it from appearing in browser network logs, protects your rate limit quota from being used by others who might inspect your frontend code, and follows the security best practice of keeping all API credentials server-side. Lovable's infrastructure blocks approximately 1,200 hardcoded API keys per day — the Secrets panel is always the correct approach regardless of how sensitive the credential appears to be.
Expected result: PIXABAY_API_KEY appears in Cloud → Secrets with a masked value.
Create the Pixabay API proxy Edge Function with caching
Create the Pixabay API proxy Edge Function with caching
Create a Supabase Edge Function that proxies Pixabay search requests and implements simple caching in Supabase. The caching layer stores recent search results in a Supabase table, returning cached results if the same query was made within the last 30 minutes. This reduces API calls for popular searches and improves response speed. Pixabay's API search endpoint is https://pixabay.com/api/ for images and https://pixabay.com/api/videos/ for videos. The main parameters are key (your API key), q (the search query), image_type (photo, illustration, vector, all), orientation (horizontal, vertical, all), category, min_width, min_height, page, and per_page (max 200). The response includes an array of hits with thumbnail URLs (webformatURL), large image URLs (largeImageURL), image dimensions, tags, and photographer username. Display webformatURL thumbnails in the grid and largeImageURL for lightbox or download.
Create a Supabase Edge Function at supabase/functions/pixabay-api/index.ts. Accept GET requests with query params: q (search keyword), image_type (photo/illustration/vector/all), orientation, category, page, per_page. Check a Supabase table 'pixabay_cache' for a recent result matching the same query (within 30 minutes). If found, return the cached result. If not, call https://pixabay.com/api/?key={PIXABAY_API_KEY}&q={q}&image_type={type}&per_page=20&safesearch=true, cache the result with the query as key and fetched_at timestamp, then return it. Include CORS headers.
Paste this in Lovable chat
1// supabase/functions/pixabay-api/index.ts2import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';34const PIXABAY_BASE = 'https://pixabay.com/api';5const CACHE_TTL_MINUTES = 30;67Deno.serve(async (req) => {8 if (req.method === 'OPTIONS') {9 return new Response(null, {10 headers: {11 'Access-Control-Allow-Origin': '*',12 'Access-Control-Allow-Methods': 'GET, OPTIONS',13 'Access-Control-Allow-Headers': 'Content-Type, Authorization',14 },15 });16 }1718 const apiKey = Deno.env.get('PIXABAY_API_KEY');19 if (!apiKey) {20 return new Response(JSON.stringify({ error: 'Pixabay API key not configured' }), {21 status: 500,22 headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },23 });24 }2526 const url = new URL(req.url);27 const q = url.searchParams.get('q') || 'nature';28 const imageType = url.searchParams.get('image_type') || 'photo';29 const orientation = url.searchParams.get('orientation') || 'all';30 const category = url.searchParams.get('category') || '';31 const page = url.searchParams.get('page') || '1';32 const perPage = url.searchParams.get('per_page') || '20';33 const mediaType = url.searchParams.get('media_type') || 'image';3435 const cacheKey = `${q}:${imageType}:${orientation}:${category}:${page}:${perPage}:${mediaType}`;3637 const supabase = createClient(38 Deno.env.get('SUPABASE_URL')!,39 Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!40 );4142 // Check cache43 const { data: cached } = await supabase44 .from('pixabay_cache')45 .select('result, fetched_at')46 .eq('cache_key', cacheKey)47 .single();4849 if (cached) {50 const age = (Date.now() - new Date(cached.fetched_at).getTime()) / 60000;51 if (age < CACHE_TTL_MINUTES) {52 return new Response(JSON.stringify(cached.result), {53 headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },54 });55 }56 }5758 // Fetch from Pixabay59 const apiEndpoint = mediaType === 'video' ? `${PIXABAY_BASE}/videos/` : `${PIXABAY_BASE}/`;60 const params = new URLSearchParams({ key: apiKey, q, image_type: imageType, orientation, page, per_page: perPage, safesearch: 'true' });61 if (category) params.set('category', category);6263 const pixabayResponse = await fetch(`${apiEndpoint}?${params}`);64 const data = await pixabayResponse.json();6566 // Store in cache67 await supabase.from('pixabay_cache').upsert({ cache_key: cacheKey, result: data, fetched_at: new Date().toISOString() }, { onConflict: 'cache_key' });6869 return new Response(JSON.stringify(data), {70 status: pixabayResponse.status,71 headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },72 });73});Pro tip: Create the pixabay_cache table in Supabase with columns: cache_key (text, primary key), result (jsonb), fetched_at (timestamptz). Ask Lovable: 'Create a Supabase table called pixabay_cache with columns cache_key text primary key, result jsonb, fetched_at timestamptz.'
Expected result: The pixabay-api Edge Function is deployed. Calling it with a q parameter returns Pixabay search results. On the second call with the same query, results are returned from the Supabase cache rather than the Pixabay API.
Build the image search and gallery UI
Build the image search and gallery UI
With the Edge Function running, use Lovable's chat to generate the image search interface. Pixabay returns rich metadata with each image: the webformatURL for thumbnails, largeImageURL for full-size, imageWidth and imageHeight for responsive sizing, tags for keyword display, user (photographer name), and pageURL (link back to Pixabay as required by terms). For a good image picker UX, build a masonry or grid layout that displays thumbnails. When a user clicks an image, open a lightbox showing the full-size image with the photographer credit and a link to the Pixabay page. Include an insert or select button to trigger the callback that returns the image to the parent component. Add filter controls: image type (photo, illustration, vector), orientation (horizontal, vertical), and popular Pixabay categories (nature, science, backgrounds, technology, travel, food, music). These map directly to Pixabay's API parameters. For the Pixabay attribution requirement, add a small 'Free images via Pixabay' link in the footer of the image picker modal. This satisfies Pixabay's terms of service while keeping the attribution unobtrusive. If you are building a feature where users save images for repeated use, prompt Lovable to add the 'Save to Library' flow that downloads the image from Pixabay into Supabase Storage.
Create an image search component called PixabayPicker with a search input, filter chips for image type (photo, illustration, vector) and orientation. Call the pixabay-api Edge Function on search. Display results in a responsive masonry grid showing thumbnails. Clicking an image opens a lightbox with the full-size image, photographer credit, and an 'Insert Image' button. Add a 'Free images via Pixabay' attribution link in the modal footer.
Paste this in Lovable chat
Expected result: A Pixabay image picker component shows search results in a thumbnail grid. Filters work correctly. Clicking an image opens a lightbox with the full-size image and photographer attribution. The Insert button returns the selected image URL to the parent component.
Common use cases
Image picker for a content creation tool
Add an inline image picker to a blog post editor or content builder that lets users search Pixabay for royalty-free illustrations to add to their content. Users search, preview thumbnails, click to select, and the selected image URL is inserted into their content — all without leaving the Lovable app.
Add an image picker modal that opens when a user clicks 'Add Image' in the content editor. The modal has a search input that calls the pixabay-api Edge Function. Display results as a 4-column thumbnail grid with photographer name. Clicking a thumbnail inserts the full-size Pixabay image URL into the editor and closes the modal.
Copy this prompt to try it in Lovable
Background image library for a design tool
Build a background image selector for a landing page or presentation builder. Users browse Pixabay's collection of landscape, texture, and abstract images, preview how they look as full-bleed backgrounds behind their content, and select one to apply.
Create a background picker panel that shows Pixabay images in a masonry grid filtered by the 'backgrounds' category. Add a 'Preview' button that shows the selected image as a full-screen overlay behind my current page content. Include category filter chips for nature, technology, abstract, architecture, and food. Call the pixabay-api Edge Function for all searches.
Copy this prompt to try it in Lovable
Cached media library with Supabase storage
Build a media library that searches Pixabay, lets users mark favorites, and caches frequently used images in Supabase Storage so they are served from your own CDN rather than Pixabay's servers. This prevents broken image links if Pixabay changes URLs and ensures images load reliably.
Create a media library page that searches Pixabay via the pixabay-api Edge Function. Add a 'Save to Library' button on each image that downloads the image from Pixabay and stores it in Supabase Storage in a bucket called 'media-library', saving the Pixabay ID and our Supabase URL to a 'saved_images' table. Show both Pixabay search results and saved library images in tabs.
Copy this prompt to try it in Lovable
Troubleshooting
API returns 400 Bad Request with 'API key is not valid'
Cause: The PIXABAY_API_KEY value in Cloud → Secrets is incorrect, or there is a leading/trailing space in the stored value.
Solution: Go to pixabay.com/api/docs while logged into your Pixabay account and copy your API key exactly. Open Cloud → Secrets and delete the current PIXABAY_API_KEY entry, then add it again with the freshly copied value. Pixabay API keys are purely numeric — if your stored key contains any letters, it is not a valid Pixabay key.
Thumbnails load correctly but largeImageURL images fail to display
Cause: Pixabay's largeImageURL requires a download-eligible account. For some Pixabay plans or API access levels, full-size image URLs are not accessible via API without going through the download endpoint.
Solution: Use the webformatURL (which provides up to 1920px wide images) for display purposes instead of largeImageURL. The webformatURL is freely accessible via the API for all accounts. Reserve largeImageURL for download functionality if your Pixabay account supports it. You can also use the previewURL (up to 150px) for thumbnails and webformatURL for the lightbox view.
Edge Function returns 'pixabay_cache table does not exist'
Cause: The Supabase table for caching has not been created. The Edge Function references a pixabay_cache table but the table was never created in your Supabase database.
Solution: In Lovable's chat, prompt: 'Create a Supabase table called pixabay_cache with columns: cache_key text primary key, result jsonb not null, fetched_at timestamptz not null default now(). Enable RLS but only allow service role access.' Alternatively, go to Cloud → Database and run the CREATE TABLE statement directly in the SQL editor.
1-- Create pixabay_cache table2CREATE TABLE IF NOT EXISTS pixabay_cache (3 cache_key text PRIMARY KEY,4 result jsonb NOT NULL,5 fetched_at timestamptz NOT NULL DEFAULT now()6);7-- Only service role can access (Edge Functions use service role)8ALTER TABLE pixabay_cache ENABLE ROW LEVEL SECURITY;Best practices
- Store the Pixabay API key in Cloud → Secrets even though it only accesses public content — keeping it server-side protects your rate limit quota from being consumed by others inspecting your frontend code
- Implement Supabase caching for search results to reduce API calls — Pixabay's catalog changes slowly and 30-minute cache TTL is appropriate for most use cases
- Always display the attribution link 'Free images via Pixabay' when showing Pixabay images — this is required by Pixabay's terms of service
- Use safesearch: true in all API requests unless your application explicitly handles adult content — the default does not filter sensitive content
- Prefer webformatURL over largeImageURL for display — it is universally accessible through the API and typically sufficient at up to 1920px wide
- Add a category filter to the UI — Pixabay's category system (nature, technology, food, etc.) significantly narrows results and improves search quality over keyword-only filtering
- If saving Pixabay images to Supabase Storage, store the original Pixabay image ID alongside the Supabase URL to maintain attribution records and trace any licensing questions
Alternatives
Choose Getty Images API if you need professionally shot editorial photography, news images, or celebrity content — Getty's content is premium-licensed and not available in free community repositories like Pixabay.
Choose Shutterstock API if you need premium stock photography with commercial licensing guarantees and a wider selection of professional-grade images beyond what community contributors provide.
Choose Vimeo if your media needs are video-focused — Vimeo provides professional video hosting and management rather than the image-centric free stock library that Pixabay offers.
Frequently asked questions
Are Pixabay images really free for commercial use?
Yes — all images on Pixabay are released under the Pixabay Content License, which permits free use for commercial and non-commercial purposes without attribution required. You can use Pixabay images in websites, products, advertising, and other commercial applications. However, you cannot sell the images themselves as standalone products, and a few categories (like editorial images of celebrities or branded products) have additional restrictions noted in the image metadata. Always check the individual image license when in doubt.
What is Pixabay's API rate limit?
Pixabay's standard API rate limit is 500 requests per hour per API key. For production applications that need higher limits, you can apply for an increased quota by contacting Pixabay through their developer contact form. Implementing Supabase caching as described in this tutorial significantly reduces effective API call volume — a 30-minute cache means popular searches only hit the API twice per hour regardless of how many users make the same search.
Can I use Pixabay images without the API?
You can display Pixabay images by their static URLs without using the API, but this violates Pixabay's hotlinking policy for high-traffic applications. The correct approach for any serious application is to either use the API (which provides rate-limited but policy-compliant access) or download images to your own storage (like Supabase Storage) before serving them from your own CDN. Direct hotlinking at scale puts your application at risk of having image URLs invalidated.
Does the Pixabay API support video search?
Yes — Pixabay has a separate video API endpoint at pixabay.com/api/videos/ that returns video content. The search parameters are similar to the image API: you can filter by video type (film, animation), orientation, category, and minimum dimensions. Video search results include preview GIF URLs, video file URLs in multiple resolutions (tiny, small, medium, large), and video duration. The Edge Function code in this tutorial supports switching between image and video search using the media_type parameter.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation