Your first API-powered stock hunt

Day 3, 30 minutes · beginner

Goal of this lessonGet Claude Code to write a script that calls the Pexels API and builds a shortlist of candidates — so you stop clicking through catalog pages by hand.

The shift

Steps 1 and 2 were manual browsing — fine for one asset. But the moment you need 20 candidates to pick from, manual scouting is painful. This is where AI tooling earns its keep.

Claude Code is Anthropic''s CLI that runs Claude inside your repo. It reads your project, writes code, runs commands, and commits. For a task like "fetch 30 candidate images from Pexels and write them to a JSON file," you describe the outcome in a sentence and Claude does the plumbing.

If you''d rather stay in the desktop app, Claude Desktop with Cowork folder sync (covered in the 7-Day AI Challenge) gives you the same muscle — Claude writes the script into your synced project folder, you run it.

Step 1 — Get a Pexels API key (free, 30 seconds)

  1. Sign in at https://www.pexels.com
  2. Go to https://www.pexels.com/api/new/ and fill in the form
  3. Copy the key, store it in an env var — never commit it
# in your shell or .env.local
export PEXELS_API_KEY="your-key-here"

Step 2 — The prompt that does the work

Open Claude Code in your project and paste something like this:

Write a Node.js script at scripts/fetch-stock.mjs that takes a search query as its first argument, calls the Pexels video search API using the PEXELS_API_KEY env var, picks the highest-resolution MP4 from each result, and writes manifest.json containing filename, CDN URL, poster URL, author name, and Pexels page URL for each pick. Skip clips shorter than 5s or longer than 30s. Don''t download the files themselves.

Claude Code will write the whole script — usually ~40 lines. You review it, commit it, and run it:

PEXELS_API_KEY=xxx node scripts/fetch-stock.mjs "coast aerial"

The resulting manifest.json is your shortlist.

Why this beats manual browsing

  • Speed — 30 candidates in 3 seconds instead of 30 browser tabs
  • Repeatability — rerun next month with a new query, same script
  • Version controlled — your manifest is a reviewable artifact, not tabs in your head
  • Composable — the next step turns this manifest into a picker UI automatically

A real example

The source of truth for this course was built exactly this way. One query to Claude Code, 50 candidate clips across 6 categories, total script length about 40 lines.

Today's actions

Ticks are not saved without an account

Do it in your tool

Claude

  1. Create your free Pexels key as the lesson shows. Keep it out of the chat: everything you type in a prompt is sent to the model.
  2. Install or open the Claude desktop app, sign in and click the Code tab at the top of the sidebar.
  3. In the environment selector, hover over the top entry in the Local group (your own computer) and click the gear icon. Enter one line, PEXELS_API_KEY= followed by your key, and select Save changes.
  4. Select that top entry in the Local group. Then click the project folder control, select Open folder… and choose your project. In the mode selector in the same row, pick Manual.
  5. Paste this prompt and press Enter.
    Write a Node.js script at scripts/fetch-stock.mjs that takes a search query as its first argument, calls the Pexels video search API using the PEXELS_API_KEY environment variable, picks the highest-resolution MP4 from each result, and writes manifest.json containing filename, CDN URL, poster URL, author name and Pexels page URL for each pick. Skip clips shorter than 5 seconds or longer than 30 seconds. Do not download the video files themselves. Also store the search query in a field named query, and the width and height of the chosen file, in each entry.
    
    Read the key only from the environment variable PEXELS_API_KEY. Never print it and never write it to a file.
    
    First check that Node.js is installed on this computer, and give me the exact command that runs the script in my terminal.
  6. Read the script in the diff (the list of changed lines) before you approve it: it must read the key from the environment and never print it. Then ask Claude commit my changes with a descriptive message.
  7. Select Terminal and run the command Claude gave you with your search term. If the script says the key is missing, ask Claude how to set PEXELS_API_KEY in that terminal and type the key there yourself.
  8. Click the path of manifest.json in the chat to open your shortlist. Then ask Claude to commit it too, so the shortlist is in Git.

Note: The lesson text calls Claude Code "Anthropic's CLI". Today it is also the Code tab of the desktop app, used here. The lesson's "Cowork folder sync" is not a name Claude uses, so that route is left out. Commands Claude runs in this session can read the saved key too, so never ask Claude to show or print it. Node.js must be on your computer. No gear icon? Skip the key in step 3, do step 4 as written, and set PEXELS_API_KEY in the Terminal pane yourself, as step 7 says.

Paid planNeeds a paid Claude plan: Pro, Max, Ultra, Team or Enterprise. The Free plan does not include Claude Code.

Checked on 30 November 2026 · Source: Claude Code docs: Use Claude Code Desktop (opens in a new tab)

Pexels API docs ↗ (opens in a new tab)

Create a free account to save your progress. Sign in or sign up