pexafy-ai-sdk gives AI SDK agents three tools to find real, free-to-use photos (Unsplash, Pexels, Pixabay and more). Each photo comes back with its URL, alt text, licence and credit line.

Install

npm install pexafy-ai-sdk ai zod
Set PEXAFY_API_KEY. Create a free key at pexafy.com/dashboard/api-keys/create (no card).

Use

npm install @ai-sdk/anthropic  # for this example; any AI SDK provider works
export ANTHROPIC_API_KEY="sk-ant-..."
import { anthropic } from "@ai-sdk/anthropic";
import { generateText, stepCountIs } from "ai";
import { pexafyTools } from "pexafy-ai-sdk";

const { text } = await generateText({
  model: anthropic("claude-haiku-4-5"),
  tools: pexafyTools(),
  stopWhen: stepCountIs(5),
  prompt: "Find a header photo for a post about remote work, with its credit line.",
});
console.log(text);

Tools

FunctionArguments the model fills
searchPhotos()query, optional orientation (landscape, portrait, square), count
findSimilarPhotos()photo_id, optional count
getPhoto()photo_id
pexafyTools() returns all three. Options on each: apiKey, maxResults (default 6, max 20), timeoutMs (default 30000), maxRetries (default 2).

Output

Each photo is one record:
{
  "rank": 1,
  "photo_id": "019e1ea7-2e82-7a34-a451-4c6c7c8250f4",
  "alt_text": "Red bicycle parked against white wall with front wheel facing left and back wheel right",
  "url": "https://images.unsplash.com/photo-1520538254843-27a40bae5e3a?w=1280",
  "thumbnail_url": "https://images.unsplash.com/photo-1520538254843-27a40bae5e3a?w=400",
  "width": 4896,
  "height": 3264,
  "orientation": "landscape",
  "dominant_color": "#CAB8B4",
  "photographer": "Mitchel Lensink",
  "source": "Unsplash",
  "source_page_url": "https://unsplash.com/photos/red-bicycle-near-white-wall-Hx_dY7Xeszo",
  "license": "free",
  "credit": "Photo by Mitchel Lensink on Unsplash (https://pexafy.com/legal/licenses/#unsplash)"
}
On the free plan, show the credit line next to each photo you publish.

Errors

A spent quota, an unknown photo_id or an invalid key reaches the model as a tool error. A per-minute rate limit, a server error or a network failure is retried automatically. See Errors & rate limits. Source on GitHub · npm · MIT