Give your AI agent a stock photo tool in 5 lines
Agents that write blog posts, landing pages or slides end up needing pictures. Generated images are not always the answer: you may want a real street in Lisbon, a real espresso machine, and a licence you can check. Pexafy is a semantic search engine over millions of free-to-use photos from Unsplash, Pexels, Pixabay and other libraries. Your agent describes the photo it needs in plain language and…
To create an AI agent capable of fetching stock photos with just five lines of code, you need a Pexafy API key and a model key. The examples in the source code use Claude Haiku 4.5 as the model, but any provider will work. Install the necessary packages using pip: langchain-pexafy, langchain, and langchain-anthropic for Python, or langchain-pexafy and ai sdk for TypeScript.
Import the required modules and create an agent using create_agent, passing in the anthropic:claude-haiku-4-5 model and the PexafyToolkit() as tools. Invoke the agent with a message requesting a header photo for a post about remote work, along with its credit line. The toolkit provides three tools: search by description, find similar photos, and get one photo.
The same package is available for LangChain.js and can be used with the Vercel AI SDK. Additionally, Pexafy can run an MCP server using your API key as a Bearer header. The package also works with Pydantic AI, enabling the creation of an MCPToolset and agent for fetching free stock photos and providing credit lines.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.