{"slug": "give-your-ai-agent-a-stock-photo-tool-in-5-lines", "title": "Give your AI agent a stock photo tool in 5 lines", "summary": "A developer released Pexafy, a semantic search engine over millions of free-to-use photos from Unsplash, Pexels, Pixabay and other libraries, along with integration packages for LangChain, the Vercel AI SDK and any MCP-capable framework. The toolkit exposes three tools — search by description, find similar photos, and get a single photo — and returns each result with its licence and required credit line, with an MCP server available at mcp.pexafy.com. Tested setups are also documented for the OpenAI Agents SDK, Claude Agent SDK, Google ADK, CrewAI, LlamaIndex, Mastra and Strands Agents.", "body_md": "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.\n\n[Pexafy](https://pexafy.com) 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 gets back real photographs, each with its licence and the credit line to display.\n\nBelow: the same tool in LangChain, the Vercel AI SDK and any MCP-capable framework. Every snippet was run as printed.\n\n```\nexport PEXAFY_API_KEY=\"pexafy_...\"\nexport ANTHROPIC_API_KEY=\"sk-ant-...\"\npip install -U langchain-pexafy langchain langchain-anthropic\npython\nfrom langchain.agents import create_agent\nfrom langchain_pexafy import PexafyToolkit\n\nagent = create_agent(\"anthropic:claude-haiku-4-5\", tools=PexafyToolkit().get_tools())\n\nresult = agent.invoke({\"messages\": [\n    {\"role\": \"user\", \"content\": \"Find a header photo for a post about remote work, with its credit line.\"}\n]})\nprint(result[\"messages\"][-1].content)\n```\n\nThe toolkit has three tools: search by description, find similar photos, get one photo. `create_agent` runs on LangGraph, and the tools also work with `ToolNode` or `bind_tools()`. The same package exists for LangChain.js: `npm install langchain-pexafy`.\n\n```\nnpm install pexafy-ai-sdk ai zod @ai-sdk/anthropic\njs\nimport { anthropic } from \"@ai-sdk/anthropic\";\nimport { generateText, stepCountIs } from \"ai\";\nimport { pexafyTools } from \"pexafy-ai-sdk\";\n\nconst { text } = await generateText({\n  model: anthropic(\"claude-haiku-4-5\"),\n  tools: pexafyTools(),\n  stopWhen: stepCountIs(5),\n  prompt: \"Find a header photo for a post about remote work, with its credit line.\",\n});\nconsole.log(text);\n```\n\nPexafy also runs an MCP server: `https://mcp.pexafy.com/mcp`, with your API key as a Bearer header. Here it is in Pydantic AI:\n\n```\npip install \"pydantic-ai-slim[mcp,anthropic]\"\npython\nimport os\n\nfrom pydantic_ai import Agent\nfrom pydantic_ai.mcp import MCPToolset, StreamableHttpTransport\n\npexafy = MCPToolset(\n    StreamableHttpTransport(\n        \"https://mcp.pexafy.com/mcp\",\n        headers={\"Authorization\": f\"Bearer {os.environ['PEXAFY_API_KEY']}\"},\n    )\n).filtered(lambda ctx, tool: tool.name in {\"search_photos\", \"search_photos_by_image\"})\n\nagent = Agent(\n    \"anthropic:claude-haiku-4-5\",\n    instructions=\"Find free stock photos and give each photo's credit line.\",\n    toolsets=[pexafy],\n)\n\nresult = agent.run_sync(\"Find a header photo for a post about remote work.\")\nprint(result.output)\n```\n\nThe filter keeps the two search tools; the others are for chat clients that show a photo grid. Tested setups for other frameworks: [OpenAI Agents SDK](https://docs.pexafy.com/openai-agents), [Claude Agent SDK](https://docs.pexafy.com/claude-agent-sdk), [Google ADK](https://docs.pexafy.com/google-adk), [CrewAI](https://docs.pexafy.com/crewai), [LlamaIndex](https://docs.pexafy.com/llamaindex), [Mastra](https://docs.pexafy.com/mastra), [Strands Agents](https://docs.pexafy.com/strands).\n\nWith the LangChain and AI SDK packages, each photo is one record (abridged):\n\n```\n{\n  \"rank\": 1,\n  \"photo_id\": \"019e1ea7-2e82-7a34-a451-4c6c7c8250f4\",\n  \"alt_text\": \"Red bicycle parked against white wall with front wheel facing left and back wheel right\",\n  \"url\": \"https://images.unsplash.com/photo-1520538254843-27a40bae5e3a?w=1280\",\n  \"width\": 4896,\n  \"height\": 3264,\n  \"orientation\": \"landscape\",\n  \"photographer\": \"Mitchel Lensink\",\n  \"source\": \"Unsplash\",\n  \"license\": \"free\",\n  \"credit\": \"Photo by Mitchel Lensink on Unsplash (https://pexafy.com/legal/licenses/#unsplash)\"\n}\n```\n\nThe agent can put `url` in your page, `alt_text` in the `alt` attribute and `credit` under the photo. On the free plan, show the credit line next to each photo you publish.", "url": "https://wpnews.pro/news/give-your-ai-agent-a-stock-photo-tool-in-5-lines", "canonical_source": "https://dev.to/marouane_tijani_3a7fc19a7/give-your-ai-agent-a-stock-photo-tool-in-5-lines-1gmh", "published_at": "2026-10-07 19:38:48+00:00", "updated_at": "2026-10-07 19:47:28.575326+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "agent-protocols", "developer-tools"], "entities": ["Pexafy", "LangChain", "Vercel AI SDK", "Unsplash", "Pexels", "Pixabay", "Anthropic", "Pydantic AI"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/give-your-ai-agent-a-stock-photo-tool-in-5-lines", "markdown": "https://wpnews.pro/news/give-your-ai-agent-a-stock-photo-tool-in-5-lines.md", "text": "https://wpnews.pro/news/give-your-ai-agent-a-stock-photo-tool-in-5-lines.txt", "jsonld": "https://wpnews.pro/news/give-your-ai-agent-a-stock-photo-tool-in-5-lines.jsonld"}}