langchain-pexafy (Python and JavaScript) gives LangChain and LangGraph 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
Use
The examples also need LangChain’s agent and a chat model (any provider works):ANTHROPIC_API_KEY for this example. create_agent / createAgent runs on LangGraph; the tools
also work with ToolNode and any model’s bind_tools() / bindTools().
Tools
| Class | Tool name | Arguments |
|---|---|---|
PexafySearchPhotos | pexafy_search_photos | query, optional orientation, count |
PexafyFindSimilarPhotos | pexafy_find_similar_photos | photo_id, optional count |
PexafyGetPhoto | pexafy_get_photo | photo_id |
PexafyToolkit().get_tools() (Python) or new PexafyToolkit().getTools() (TypeScript) returns all
three. Options on each: api_key / apiKey, max_results / maxResults (default 6, max 20).
Output
The tool message is a JSON list with one record per photo:photo_id, alt_text, url,
thumbnail_url, width, height, orientation, dominant_color, photographer, source,
source_page_url, license, credit. ToolMessage.artifact holds the full API records.
On the free plan, show the credit line next to each photo you publish.
Errors
A spent quota, an unknownphoto_id or a server error reaches the model as a tool error.
A per-minute rate limit is retried automatically. An invalid key raises
pexafy.AuthenticationError in Python; in TypeScript, LangGraph’s ToolNode passes it to the
model as a tool error. See Errors & rate limits.
Source on GitHub · PyPI · npm · MIT