Unsplash API
api.unsplash.com · Media
High-resolution free stock photos — search 5M+ professional photographs, get random images, download triggers, and photo statistics. Free tier: 50 requests/hour.
Authentication
API Key
Free API key at unsplash.com/developers. Pass as ?client_id= query parameter or Authorization: Client-ID YOUR_KEY header.
Sample Requests
GET
Search photos
Search Unsplash for mountain photos.
https://api.unsplash.com/search/photos?query=mountains&per_page=3&client_id=YOUR_KEY
Hover any highlighted part to learn what it does
curl -X GET "https://api.unsplash.com/search/photos?query=mountains&per_page=3&client_id=YOUR_KEY"
import requests
params = {
"query": "mountains",
"per_page": "3",
"client_id": "YOUR_KEY"
}
response = requests.get(
"https://api.unsplash.com/search/photos",
params=params,
)
print(response.json())const url = new URL('https://api.unsplash.com/search/photos');
url.searchParams.set('query', 'mountains');
url.searchParams.set('per_page', '3');
url.searchParams.set('client_id', 'YOUR_KEY');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.unsplash.com/search/photos")
q := baseURL.Query()
q.Set("query", "mountains")
q.Set("per_page", "3")
q.Set("client_id", "YOUR_KEY")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.unsplash.com/search/photos")
uri.query = URI.encode_www_form({
"query" => "mountains",
"per_page" => "3",
"client_id" => "YOUR_KEY"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.unsplash.com/search/photos?" . http_build_query([
"query" => "mountains",
"per_page" => "3",
"client_id" => "YOUR_KEY"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Get random photo
Get a random ocean photo.
https://api.unsplash.com/photos/random?query=ocean&client_id=YOUR_KEY
Hover any highlighted part to learn what it does
curl -X GET "https://api.unsplash.com/photos/random?query=ocean&client_id=YOUR_KEY"
import requests
params = {
"query": "ocean",
"client_id": "YOUR_KEY"
}
response = requests.get(
"https://api.unsplash.com/photos/random",
params=params,
)
print(response.json())const url = new URL('https://api.unsplash.com/photos/random');
url.searchParams.set('query', 'ocean');
url.searchParams.set('client_id', 'YOUR_KEY');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.unsplash.com/photos/random")
q := baseURL.Query()
q.Set("query", "ocean")
q.Set("client_id", "YOUR_KEY")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.unsplash.com/photos/random")
uri.query = URI.encode_www_form({
"query" => "ocean",
"client_id" => "YOUR_KEY"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.unsplash.com/photos/random?" . http_build_query([
"query" => "ocean",
"client_id" => "YOUR_KEY"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Register at unsplash.com/developers for a free access key
- Pass client_id=YOUR_KEY as query param
- Search: GET /search/photos?query=cityscape&client_id=YOUR_KEY
- Random: GET /photos/random?client_id=YOUR_KEY
- Attribution required — display photographer credit