Search and fetch photos from Unsplash with proper attribution. Use when users need images for content, want photos by keyword, need random images for variety, or ask for stock photos...
Search and fetch high-quality photos from Unsplash with automatic attribution.
# Search for photos
./scripts/search.sh "sunset beach"
# Get random photos
./scripts/random.sh "nature" 3
# Track download (when user downloads)
./scripts/track.sh PHOTO_ID
IMPORTANT: If the script returns UNSPLASH_ACCESS_KEY not set, handle it interactively:
Ask the user: "I need an Unsplash API key to search for photos. You can get a free key at https://unsplash.com/developers - do you have one?"
Wait for the user to provide their key
Save the key to .env in the project root:
echo "UNSPLASH_ACCESS_KEY=<user_provided_key>" >> .env
Re-run the original search/random command
The skill automatically loads .env from the project root on each run.
Find photos by keyword with optional filters.
./scripts/search.sh QUERY [PAGE] [PER_PAGE] [ORDER_BY] [ORIENTATION] [COLOR]
Parameters:
QUERY (required): Search keyword(s)PAGE (optional, default: 1): Page number for paginationPER_PAGE (optional, default: 10): Results per page (1-30)ORDER_BY (optional, default: "relevant"): Sort order ("relevant" or "latest")ORIENTATION (optional): Filter by orientation ("landscape", "portrait", "squarish")COLOR (optional): Filter by color ("black_and_white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue")Examples:
# Basic search
./scripts/search.sh "mountain landscape"
# Search with filters
./scripts/search.sh "sunset" 1 5 latest landscape
# Search by color
./scripts/search.sh "flower" 1 10 relevant portrait red
Get random photos with optional filtering.
./scripts/random.sh [QUERY] [COUNT] [ORIENTATION]
Parameters:
QUERY (optional): Topic/keyword to filter random photosCOUNT (optional, default: 1): Number of photos (1-30)ORIENTATION (optional): Filter by orientation ("landscape", "portrait", "squarish")Examples:
# Single random photo
./scripts/random.sh
# Random photos by topic
./scripts/random.sh "architecture" 5
# Random landscape photos
./scripts/random.sh "nature" 3 landscape
Track when a user downloads a photo (required by Unsplash API guidelines).
./scripts/track.sh PHOTO_ID
When to call:
Example:
./scripts/track.sh "abc123xyz"
All operations return JSON with complete photo information:
{
"id": "abc123xyz",
"description": "A beautiful sunset over mountains",
"alt_description": "orange sunset behind mountain range",
"urls": {
"raw": "https://...",
"full": "https://...",
"regular": "https://...",
"small": "https://...",
"thumb": "https://..."
},
"width": 6000,
"height": 4000,
"color": "#f3a460",
"blur_hash": "L8H2#8-;00~q4n",
"photographer_name": "Jane Smith",
"photographer_username": "janesmith",
"photographer_url": "https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral",
"photo_url": "https://unsplash.com/photos/abc123xyz?utm_source=claude_skill&utm_medium=referral",
"attribution_text": "Photo by Jane Smith on Unsplash",
"attribution_html": "Photo by <a href=\"https://unsplash.com/@janesmith?utm_source=claude_skill&utm_medium=referral\">Jane Smith</a> on <a href=\"https://unsplash.com/?utm_source=claude_skill&utm_medium=referral\">Unsplash</a>"
}
The urls object contains different sizes:
Recommended: Use urls.regular for most web content (best quality/size balance).
CRITICAL: Unsplash requires attribution for all image usage.
When presenting photos to users, you MUST include one of:
attribution_text (for plain text contexts):
Photo by Jane Smith on Unsplash
attribution_html (for HTML/web contexts):
Photo by <a href="...">Jane Smith</a> on <a href="...">Unsplash</a>
# Search for relevant image
./scripts/search.sh "technology workspace" 1 3 latest landscape
# Present options to user with attribution
# User selects one
# Display image with attribution_html in blog post
# Get variety of images
./scripts/random.sh "travel" 10
# Display all images with their attributions
# Search for images matching brand colors
./scripts/search.sh "abstract" 1 5 latest "" blue
Missing API Key:
ERROR: UNSPLASH_ACCESS_KEY not set
β See "Setup (Interactive)" section above. Ask user for key, save to .env, and retry.
Rate Limit Exceeded:
ERROR: Rate limit exceeded (50/hour in demo mode)
Wait an hour or use production credentials with higher limits.
Invalid API Key:
ERROR: Invalid API key
Check that your API key is correct.
No Results:
[]
Empty array returned if no photos match search criteria.
Required tools (standard on macOS/Linux):
bash - Shell interpretercurl - HTTP clientjq - JSON processorInstall jq if missing:
# macOS
brew install jq
# Ubuntu/Debian
sudo apt-get install jq
Production mode requires:
See detailed usage patterns in: examples/usage-examples.md
Scripts not executable:
chmod +x scripts/*.sh
jq not found:
brew install jq # macOS
API errors: