Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

There is no random-photo endpoint in the Pexels API. To randomize images, request a search-results page (or the curated feed), then choose a random item in your application. For a changing gallery without repeats, shuffle the returned photos array with Fisher–Yates and consume it before requesting another page.

How Pexels randomization actually works

Pexels’ own help guidance answers the question “Is there a RANDOM endpoint?” with “Technically, no.” The API returns an ordered collection; your code supplies the randomness. That distinction matters because requesting the same endpoint repeatedly does not guarantee a different image.

You have two practical sources for a random-looking result:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Search: send a required query such as nature, receive up to 80 matching photos, and select or shuffle them locally.
  • Curated: use Pexels’ team-selected feed when topical search is unnecessary. Pexels says the curated list receives at least one new photo per hour, but also warns that API responses can be cached for 24 hours, so repeated calls may return the same selection.

Search is generally the better choice when relevance matters. Curated results are useful for a broad discovery feed, but they should not be treated as a guaranteed fresh-random source.

#1 Best Overall
Beautiful Photo Album Set of 3 For 4x6 Pictures - Linen Album Holds 216
  • Most Convenient & Easy To Organize: The clever slip-in pockets make arranging the small photo album book set simple and fun. Practical: you can add both vertical & horizontal photos! Turn your photo book into a storytelling masterpiece effortlessly!
  • From Your Camera Roll to Heartfelt Keepsakes: Keep your life's best moments safe and sound in ZICOTOs’ beautiful 4x6 photo albums set of 3. It's a memory vault for your favorite stories and your life’s epic tales, making sure they stay vivid and accessible for years to come
  • Premium Design & Timeless Beauty: Each photo album for 4x6” photos comes in a chic linen cover, embellished with elegant gold gold foil lettering. The hardcover & protective pockets make sure your photos stay safe and pristine
  • Compact Capacity – Every Memory in Its Place: Keep your favorite moments close at hand! Each petite photo album holds up to 72 4x6” photos in a perfectly sized 6.46x4.72x1.2” design. Every lovely snapshot has its place in your collection - the ultimate keepsake
  • Celebrate Life’s Milestones: From vacations to pregnancy, the versatile photo album set of 3 is great for all occasions. Ideal as baby photo albums and wedding photo album alike, it’s a thoughtful gift for baby showers, weddings & anniversaries - ready to fill with memories

Request a pool of candidate images

The search endpoint is https://api.pexels.com/v1/search. Every request needs your API key in the Authorization header. A query is required; orientation, minimum size, color, locale, page, and page size are optional. The default page size is 15 and the maximum is 80.

JavaScript: choose one random photo

const response = await fetch(
  'https://api.pexels.com/v1/search?query=nature&per_page=80',
  { headers: { Authorization: PEXELS_API_KEY } }
);

if (!response.ok) {
  throw new Error(`Pexels request failed: ${response.status}`);
}

const data = await response.json();
if (!Array.isArray(data.photos) || data.photos.length === 0) {
  throw new Error('No photos matched the query');
}

const photo = data.photos[Math.floor(Math.random() * data.photos.length)];
console.log({ id: photo.id, imageUrl: photo.src.medium, photographer: photo.photographer });

Guard against an empty array before calculating an index. Otherwise, an unsuccessful or overly specific query can leave you with undefined rather than an image.

cURL

curl -G "https://api.pexels.com/v1/search" 
  -H "Authorization: YOUR_PEXELS_API_KEY" 
  --data-urlencode "query=nature" 
  --data-urlencode "per_page=80"

Python

import random
import requests

response = requests.get(
    "https://api.pexels.com/v1/search",
    headers={"Authorization": "YOUR_PEXELS_API_KEY"},
    params={"query": "nature", "per_page": 80},
    timeout=30,
)
response.raise_for_status()
data = response.json()
photos = data.get("photos", [])
if not photos:
    raise RuntimeError("No photos matched the query")
photo = random.choice(photos)
print(photo["id"], photo["src"]["medium"])

Node.js

const params = new URLSearchParams({ query: 'nature', per_page: '80' });
const response = await fetch(`https://api.pexels.com/v1/search?${params}`, {
  headers: { Authorization: process.env.PEXELS_API_KEY }
});
if (!response.ok) throw new Error(`Pexels request failed: ${response.status}`);
const { photos = [] } = await response.json();
if (photos.length === 0) throw new Error('No photos matched the query');
const photo = photos[Math.floor(Math.random() * photos.length)];
console.log(photo.src.medium);

Apply filters before random selection

Filtering first produces a more useful random pool than downloading broad results and rejecting them afterward. Add parameters such as:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • orientation=landscape, portrait, or square
  • size=large, medium, or small for a minimum size
  • color for a dominant-color filter
  • locale for the search language and region
  • page and per_page for pagination, with 15 as the documented default and 80 as the maximum

For example, a landscape hero image can use query=mountains&orientation=landscape&size=large&per_page=80. URL-encode the query and other values rather than concatenating unescaped user input.

Rank #2
Sale
Vienrose Self Adhesive Photo Album, 40 Pages, 11 x 10.6 in, Beige
  • SIZE & FLEXIBLE LAYOUTS – Album measures 11 x 10.6 in with a 10.6 x 8.8 in usable page area. Includes 20 sheets/40 self-adhesive pages for up to 120 4 x 6 in or 40 8 x 10 in photos, plus flat keepsakes in portrait or landscape layouts.
  • EXPANDABLE DESIGN – The album lets you add up to 10 compatible self-adhesive refill sheets/20 pages, providing extra space for more photos and keepsakes as your collection grows.
  • ACID-FREE, PVC-FREE & REPOSITIONABLE – Photo-safe pages help protect pictures from damage over time. Lift the clear film to arrange, remove or reposition photos and keepsakes, then smooth it back down to hold them securely.
  • LINEN HARDCOVER – The beige linen-covered hardcover and rigid boards help protect the album contents during normal storage and handling.
  • METALLIC PEN INCLUDED – Use the supplied pen to add dates, captions and scrapbook notes alongside your photos and keepsakes.

Randomize repeatedly without repeats

Calling Math.random() for every display can select the same image twice. If a session should show each candidate once, shuffle the page once and consume the shuffled list.

Fisher–Yates shuffle

function shuffle(items) {
  const result = [...items];
  for (let i = result.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [result[i], result[j]] = [result[j], result[i]];
  }
  return result;
}

const response = await fetch(
  'https://api.pexels.com/v1/search?query=nature&per_page=80',
  { headers: { Authorization: PEXELS_API_KEY } }
);
const { photos = [], next_page: nextPage } = await response.json();
const queue = shuffle(photos);

for (const photo of queue) {
  render(photo);
}
// Fetch nextPage only after the queue is exhausted.

Fisher–Yates gives every array position an equal chance when the random source is unbiased. Keep the queue in session state, a database, or a cache depending on whether “no repeats” applies to one page view, one user, or your entire service. When the queue is empty, follow the response’s next_page URL or request another page.

Use pagination to enlarge the candidate pool

A response includes the current page, page size, total result count, and previous or next page URLs when available. Fetching another page increases variety but consumes another API request. A sensible pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Request a page of 80 results with the filters your UI needs.
  2. Shuffle and serve those results locally.
  3. Cache the page while it is being consumed.
  4. Fetch the next page only when necessary.
  5. Track photo IDs if duplicates across pages would be undesirable.

Do not assume that a high total_results value means every result is immediately available in one response; the page is the candidate set you actually received.

Rank #3
Scrapbook Album, 50 Pages, 11 x 8.5 Inch, Brown Photo Album, Scrap Book
  • This 11 x 8.5 inch Kraft photo album scrapbook is durable and suitable for long term storage for you and your loved ones beautiful memories. It has 25 sheets, 50 pages of 200gsm high quality thick Kraft paper, designed with ribbon closure, hard cover and corner protectors
  • The spiral bound spine allows the scrapbooks to expand to fit in your photos, postcards, souvenirs. You can tie the ribbon into a bow or other style that you like and make your photo album scrapbook as individual as your memories and keep them endlessly
  • The hardcover protects the pages, you can design the hardcover and inside pages of this photo book with paints, pens, stickers and even add glitter for a touch of sparkle and shine. You can look back over time at your amazing creation, So get creative now
  • Scrapbooking is all about telling a story so think about the experiences in your life that means the most to you, lays flat on the desk, hold your art pen, write and record your happy memories beside the photos, Easy to fit 4 photos, include: 2 (6 x 4 inch) photos
  • It makes an ideal gift for Anniversary, Mothers Day, Birthday, Valentines Day, Christmas, Wedding guest book, Baby memory book and for recording your travels or add your creative touches and embellishments to make it your own. Package Includes: 1 x Scrapbook

Curated images: useful, but not per-request randomness

The curated feed is Pexels’ alternative when you do not need a query. It reflects the team’s selected images and receives at least one new photo per hour. However, Pexels separately cautions that API responses are cached for 24 hours. A new HTTP request can therefore produce the same page and the same random choice.

If freshness is important, prefer a search pool, cache it on your own schedule, and rotate locally. If you use curated results, describe the behavior accurately to users: it is a shuffled selection from a curated, potentially cached feed—not a guaranteed new image on every request.

Quotas, caching, and production design

Pexels documents default limits of 200 requests per hour and 20,000 requests per month. Randomization should happen after retrieval so every image display does not consume a request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Cache by normalized query and filters. Normalize casing and whitespace so “Nature” and “ nature ” do not create separate pools.
  • Use a useful page size. A larger page gives the local shuffle more candidates, while still counting as one request.
  • Cache the response, not only the selected URL. The remaining photos can satisfy later displays without another API call.
  • Refresh deliberately. A time-based refresh avoids accidental quota spikes and makes the feed’s update behavior predictable.
  • Keep the API key server-side. Do not expose it in browser JavaScript shipped to untrusted users; proxy requests through your backend.
  • Handle rate limits and transient failures. Use bounded retries with backoff, then serve a cached pool or a clear fallback.

Attribution and product requirements

Pexels requires API-powered applications to show a prominent link to Pexels. It also asks developers to credit photographers when possible, for example Photo by [name] on Pexels linked to the individual photo page. Do not copy or replicate Pexels’ core functionality. Render the photographer name and a link to the photo page in your gallery wherever your design permits.

Rank #4
GPIRAL Small Photo Album 4x6 – Clear Pages, Linen Cover with Front Window, Pack of 2, Each Album Holds 52 Photos, Small Brag Book for 4x6 Photos, Blue Fabric
  • ✔2 Pack Small 4x6 Photo Album: Each 26-page small photo album can display up to 52 pictures 4x6 inch. Use as portable photo album to share 4x6 photos with family and friends for wedding, baby shower, graduation, trip, birthday, anniversary, Christmas & more
  • ✔Acid-free Photo Album: The small brag book use top slip-in clear, acid and PVC free 4x6 pockets, no wrinkle, pocket sheet never stick to the item within, which make photo, flashcards, artwork, drawing and archival safe. Great gift for parent to store their kids’ photo, for bride to share photos with family members
  • ✔DIY Front Window: Each little photo album features an open window allows you to personalize every photo book with your own print. The mini album 4x6 can stand on your bookshelf or coffee table. With an elastic strap to close small album book easily and protect photos from slipping out when pictures within
  • ✔One Of Kind Clear Album: Unlike other Small Photo Albums which are made of whole plastic, feel cheap, break easily, or make photos bent due to the flexible cover, the GPIRAL small 4x6 photo album is made of high quality linen fabric solid cover, nice touch feeling in hand, super durable and really vibrant color. Stylish matched with quality!
  • ✔We hate sleeve pockets tear off easily when slide in or take out pictures as much as you do, so we’ve designed our mini photo album 4x6 really sturdy. Strongly stand behind our products.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and fixes

401 or 403 response

Cause: the key is missing, malformed, or not sent in the Authorization header. Fix: send the key exactly as the header value, keep it on the server, and verify that the environment variable is populated.

Empty photos array

Cause: no match for the query and filters. Fix: relax the query, remove an overly restrictive size or color filter, and test the array before selecting a random index.

The same image keeps appearing

Cause: a small pool, repeated cached response, or random selection performed against the same one-item array. Fix: request up to 80 results, shuffle locally, consume a queue, and fetch another page only when the queue is exhausted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Too many requests

Cause: requesting Pexels for every render or every random choice. Fix: cache a page, select locally, normalize search strings, and observe the documented 200-per-hour and 20,000-per-month limits.

Best Value
Sale
Beautiful Linen Photo Album For 4x6 Photos - Holds Up To 500 Pictures
  • From Your Camera Roll to Heartfelt Keepsakes: Keep your life's best moments safe and sound in ZICOTOs’ beautiful 4x6 photo albums. It's a memory vault for your favorite stories and your life’s epic tales, making sure they stay vivid and accessible for years to come
  • Most Convenient & Easy To Organize: The clever slip-in pockets make arranging the big photo album book simple and fun. Practical: you can add both vertical & horizontal photos! Turn your photo book into a storytelling masterpiece effortlessly!
  • Premium Design & Timeless Beauty: The photo album for 4x6” photos comes in a modern linen cover in chic sage, embellished with elegant gold foil lettering. The hardcover & protective pockets make sure your photos stay safe and pristine
  • Large Capacity - Every Moment Finds Its Place: Seamlessly fit and preserve a full brim of memories! Store up to 500 4x6” photos in the spacious album, perfectly sized at 13.39x12.32x2.2”. Every snapshot has its place in your collection - the ultimate keepsake
  • Celebrate Life’s Milestones: From vacations to pregnancy, the versatile photo album is great for all occasions. Ideal as baby photo albums and wedding photo album alike, it’s a thoughtful gift for baby showers, weddings & anniversaries - ready to fill with memories

Images are unsuitable for the layout

Cause: the random pool was not constrained. Fix: apply orientation and minimum-size filters before randomization, and use the appropriate src rendition for the display size.

Or skip the browser setup

If your actual goal is to capture randomized image pages—not to build a Pexels picker—ScreenshotNeo provides a one-call website screenshot API. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server lets Claude, Cursor, and other MCP clients call screenshot tools directly.

After creating an account, use the API documented at https://screenshotneo.com/docs/:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Sign up for ScreenshotNeo’s free 1,000-shot plan.

Frequently Asked Questions

Can I make Pexels return a different random photo on every request?

No. Pexels has no random-photo endpoint, and curated responses may be cached for 24 hours. Select and shuffle a returned search page in your own application.

What is the largest randomization pool in one search response?

The documented maximum is 80 photos per page. Use pagination to expand the pool, while accounting for additional requests.

Does random selection require a special Pexels SDK?

No. Standard HTTP requests with the API key in the Authorization header are sufficient; randomness is ordinary application-side code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.