Three steps: get a key, run a few lines of code, read the photos that come back. It’s free to start, with no credit card.

1. Get your key

1

Open the key page

Go to pexafy.com/dashboard/api-keys/create. No account yet? Sign in with Google or GitHub, or create a free account with your email. No credit card.
2

Create the key

Leave the key type on Pexafy API and click Create API Key. The name and the expiration are optional.
3

Copy your key

The next page shows your key: click Copy key. Below it, Pexafy AI Assist asks what you are building and gives you code that runs as is, with your key already in it. Lost the key? It stays in API Keys: click Display next to it.
The key works on your first call.The free plan includes 5,000 requests a month, up to 1,200 an hour — see Plans & limits.
Keep your key private, like a password: never put it on a web page or in a public repository.

2. Make your first request

Pick your language, copy the code, and replace YOUR_API_KEY with your key. Tip: on the page that shows your key, Pexafy AI Assist writes this code for you, with your key already in it.
import requests

API_KEY = "YOUR_API_KEY"

response = requests.get(
    "https://api.pexafy.com/api/v1/search/photos",
    params={"q": "a red fox walking through the snow"},
    headers={"x-api-key": API_KEY},
)
response.raise_for_status()

for photo in response.json()["data"]:
    print(photo["urls"]["regular"])
const API_KEY = "YOUR_API_KEY";

const url = new URL("https://api.pexafy.com/api/v1/search/photos");
url.searchParams.set("q", "a red fox walking through the snow");

const response = await fetch(url, {
  headers: { "x-api-key": API_KEY },
});
if (!response.ok) throw new Error("HTTP " + response.status);

const { data } = await response.json();
for (const photo of data) console.log(photo.urls.regular);
curl -G "https://api.pexafy.com/api/v1/search/photos" --data-urlencode "q=a red fox walking through the snow" -H "x-api-key: YOUR_API_KEY"
<?php
$apiKey = "YOUR_API_KEY";

$url = "https://api.pexafy.com/api/v1/search/photos?"
     . http_build_query(["q" => "a red fox walking through the snow"]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-api-key: $apiKey"]);
$body = json_decode(curl_exec($ch), true);

foreach ($body["data"] as $photo) {
    echo $photo["urls"]["regular"], PHP_EOL;
}
How to run it, from a terminal:
LanguageSave the code asInstall onceRun, in the same folder
Python 3search.pypip install requestspython search.py
JavaScript (Node.js 18 or later)search.mjsnothingnode search.mjs
cURLnothing to savenothingpaste the line and press Enter
PHP 7.4 or latersearch.phpnothingphp search.php
  • On macOS and Linux, type python3 and pip3 instead of python and pip.
  • On Windows, type curl.exe instead of curl.
  • Keep the .mjs ending for JavaScript, and run it with Node.js, on your computer or your server. Never in a web page, where anyone could read your key.
  • PHP uses its curl extension. If PHP says curl_init is undefined, install it (on Ubuntu: sudo apt install php-curl).
Python, JavaScript and PHP print a link to each photo found: open one in your browser. cURL prints the whole answer, as JSON.
Pexafy searches by meaning: describe the scene in a sentence. a red fox walking through deep snow at dawn matches better than fox snow.

3. Read the response

The answer is JSON. Here is a trimmed example: each photo has more fields than shown.
{
  "success": true,
  "data": [
    {
      "photo_id": "019e1a0d-1a4f-7d62-856f-e6775b49785d",
      "urls": {
        "thumb": "https://images.pexels.com/photos/20853949/pexels-photo-20853949.jpeg?w=200",
        "regular": "https://images.pexels.com/photos/20853949/pexels-photo-20853949.jpeg?w=1280",
        "full": "https://images.pexels.com/photos/20853949/pexels-photo-20853949.jpeg?w=2400"
      },
      "width": 8234,
      "height": 5489,
      "alt_description": "Red fox walking through a snowy field with bushes and trees behind it",
      "photographer_full_name": "Dip Kheto",
      "source": "Pexels",
      "license_type": "free",
      "attribution": {
        "plain": "Photo by Dip Kheto on Pexels (https://pexafy.com/legal/licenses/#pexels)"
      }
    }
  ],
  "meta": { "request_id": "ad7140d9-2cc2-4134-8bae-6b90ba3dede2", "took_ms": 86.42 },
  "pagination": { "next_cursor": "eyJycyI6IjBlYWNjM2Q5...", "per_page": 20, "has_more": true },
  "error": null
}
  • data is the list of photos, best match first.
  • urls gives each photo in several sizes: thumb is small, regular suits a web page, full is the largest.
  • attribution.plain is a ready-made credit line. attribution.html is the same, with links.
  • pagination.next_cursor gets you the next page: see Pagination.
  • error is null when all went well. Otherwise it says what went wrong: see Errors.
Every field and every search option, such as color, orientation or source, is in the API reference.

Using an AI assistant instead?

Use Pexafy in your AI assistant

ChatGPT, Claude, Cursor, VS Code and more. Most of them need no key: you sign in once.

Libraries and integrations

Libraries & integrations

A Python library, LangChain, the Vercel AI SDK, agent frameworks and no-code tools such as n8n, Make and Zapier. The same key works everywhere.

Get help as you build

Pexafy AI Assist The bubble in the bottom-right corner of every page. It answers from these docs — so it knows the parameters, the plan limits and the error codes — and it replies in your language. Ask it for a whole integration, not just a parameter: “write me a Python function that searches and downloads the first result”, and it writes it against the current API.
Answers are generated, so verify anything going to production. When it does not know, it says so rather than guessing — and that tells us a page is missing.

Next steps