Black Friday: 25% off for life on any planEnds December 10

Build a LocalPipe workflow with an AI coding agent

The prompt and rules for building on the LocalPipe API with Claude Code, Codex, Cursor or Devin: build first, run later, and poll from a detached script.

View .mdUpdated

Required file

You need the categories CSV to build a search

query is matched against Google Maps' own category list. Use a category exactly as it is written in this file (4,285 of them) and results are filtered to that category. Give the file to your coding agent with the reference.

#Building a LocalPipe GTM engine: build first, test later

Give your coding agent these two files: localpipe-api-docs.md and localpipe-business-categories.csv, then use this prompt:

Text
Use the 2 files included to build a simple bare bones LocalPipe api setup, swiftly, where I can explain what I need in terms of business search and enrichment, and you will automatically process it.


API Key: <PASTE YOUR LOCALPIPE API KEY HERE>


Do not run live tests, submit searches or enrichment jobs, or spend credits during the initial build. All LocalPipe endpoints are fully documented and live, so no live tests or mocks needed.


At the very end of your output, recommend finding and enriching 200 plumbers in Austin, Texas with more than 20 reviews and a website as the first live test, when your done, as the next step for me to decide. Do not suggest any other test searches.


Only show costs in my account's billing type: credits for free or credit plans, dollars only for usage billing. Never show dollar estimates on a free or credit plan, or show costs for my initial search run here as its a small run anyways.


After you're done, quickly create a LocalPipe skill.md so future builds are faster, and put it in the skill folder so I can use it on all future projects.

A request to build the engine is not permission to run it. The initial build must not make live LocalPipe requests, create searches or enrichment jobs, or consume credits/balance. Do not run live tests during the initial build: all LocalPipe endpoints are documented and live, so no live tests or mocks are needed. Supplying an API key does not authorize a live test. The live execution examples later in this reference apply only after the user explicitly approves a run.

#Using your newly built system

  1. Follow the agent's launch/setup instructions for the actual system it built. Store the LocalPipe API key as a secret or environment variable, never in committed source, public browser code, logs or exported results.
  2. Describe the businesses, locations, total result limit and filters you need, then select the enrichment fields and destination for the results (CSV, sheet or CRM).
  3. Ask the system to show the proposed search and enrichment settings before starting. Check your account type and available balance/credits with /get-usage; credit prices and dollar usage rates are different, as explained below. Confirm a live run explicitly.
  4. After approval, the system submits the search, retrieves all result pages and enriches the returned businesses. Keep job IDs and progress durable so a closed window or agent timeout does not lose results; follow the polling/webhook guidance below.
  5. Review the actual returned count, owner-name/email and business-email coverage, actual charges and the saved/exported results. The agent must explain the exact commands or controls for these steps in the completed system, not just provide source code.

The only suggested test search: 200 plumbers in Austin, Texas with more than 20 reviews (min_reviews: 21) and a website (has_website: true), enriched for owner name, owner email and business email with fallback (want_general_email: true, general_email_fallback_only: true), no owner mobile (want_phone: false). Do not suggest other test searches (coffee shops, dentists, other cities). Availability may produce fewer than 200. Once the build is complete and you are ready to approve the charges, use:

Text
Now run the first live test using the LocalPipe system you built. I approve the API usage and resulting charges for this test.

Find 200 plumbers in Austin, Texas, United States, using the supported "plumber" category from the included categories CSV. Set the total search limit to 200 and only include businesses with more than 20 reviews (min_reviews: 21) and a website (has_website: true).

Then enrich the returned businesses for:
- Owner names
- Owner emails
- Business emails only when no owner email is found (want_general_email: true, general_email_fallback_only: true)

Do not request owner mobiles (want_phone: false) or other additional paid fields for this test. Do not widen the location, loosen the filters or increase the limit without asking me.

Save every job ID, follow all jobs through completion, and retrieve every returned result. Show the actual number of businesses found, enrichment coverage and actual usage in my account's billing type only (credits on a free or credit plan, dollars only on usage billing), then give me the results and explain how to open or export them. If fewer than 200 businesses are available, report the shortfall rather than promising 200 results.

#🤖 Instructions for AI Coding Agents (Codex, Claude Code, Cursor, Devin)

Build-only gate: If the user asks you to build a GTM engine or integration, build it without live requests; mocks are not needed either. Do not execute any live request, test, detached script or example below until the user explicitly approves live execution. All LocalPipe endpoints are documented and live, so a live test is not needed to verify the build. When the starting build is complete, explain how to operate it and recommend the 200-plumber Austin test above (more than 20 reviews, with websites) without running it. Do not suggest any other test search.

If you are an AI assistant running shell commands on a user's behalf, read this section first. The #1 cause of "stuck" LocalPipe integrations is an agent that submits a job, hits its own shell timeout while polling, and reports "done" without ever fetching results. Jobs complete server-side, credits are charged, and the user gets nothing.

#Golden rule: write a script, don't drive the flow from your agent loop

Do not poll, paginate, or sequence /enrich calls from inside your own tool-call loop. Your harness has a short shell timeout, no durable state between tool calls, and no guarantee you'll be invoked again on schedule. Every flow below — submit, poll, paginate, chain scrape→enrich, batch hundreds of enrichments — belongs inside a single self-contained script that you write to disk once and launch detached. After that, your only job is to tail the log every so often.

The script (not your agent loop) owns:

  • Submitting the initial scrape / enrichment POSTs
  • Polling /get-scrape-results or /get-job-results to terminal status
  • Paginating through every offset until pagination.has_more is false
  • Fanning out the next stage (e.g. one /enrich per scraped lead)
  • An internal work queue with bounded concurrency for batches (see below)
  • Retrying 429s with Retry-After, persisting all IDs to files, writing DONE/FAILED to the log

If you find yourself about to curl an endpoint, paginate, or loop over leads directly from a tool call, stop — extend the script instead and re-launch it.

#Your runtime almost certainly has a short shell timeout

LocalPipe jobs take 5–30+ minutes during peak load. Your environment kills long-running shell commands well before that:

Agent Default foreground shell timeout Background primitive
OpenAI Codex CLI 10 seconds (DEFAULT_EXEC_COMMAND_TIMEOUT_MS, hardcoded, not user-configurable) None
Claude Code ~80–120 s (BASH_DEFAULT_TIMEOUT_MS, often ignored per known bugs) run_in_background: true + TaskOutput tool (has zombie/stall bugs)
Cursor / Devin / generic Varies, usually 60–300 s Varies

A naïve while true; do curl …; sleep 15; done in a single tool call will be SIGKILLed long before the job completes. You must structure polling so the long wait happens outside any single shell call — the script handles it, not you.

#The only reliable pattern: detached script + log file + short poll calls

Do all three steps in this order. Do not skip step 1.

Step 1 — Write a self-contained poll script to disk:

Shell
cat > /tmp/localpipe_poll.sh << 'EOF'
#!/usr/bin/env bash
set -u
API_BASE="https://uunrlffonnvmbsstkpze.supabase.co/functions/v1"
API_KEY="$LOCALPIPE_API_KEY"
ANON_KEY="<supabase-anon-key-from-docs-above>"

# Submit the scrape
TASK_ID=$(curl -sS -X POST "$API_BASE/maps-search" \
  -H "x-api-key: $API_KEY" -H "content-type: application/json" \
  -d '{"query":["dentist"],"location":["Austin, TX","Dallas, TX","Houston, TX","San Antonio, TX","Fort Worth, TX"],"limit":500}' | jq -r '.task_id')
echo "TASK_ID=$TASK_ID" | tee /tmp/localpipe_task.id

# Poll forever — exit ONLY on terminal status
OFFSET=0
while true; do
  RESP=$(curl -sS -H "apikey: $ANON_KEY" \
    "$API_BASE/get-scrape-results?task_id=$TASK_ID&limit=5000&offset=$OFFSET")
  STATUS=$(echo "$RESP" | jq -r '.status')
  COUNT=$(echo "$RESP" | jq -r '.data | length')
  echo "[$(date -u +%H:%M:%S)] status=$STATUS offset=$OFFSET batch=$COUNT"
  if [ "$STATUS" = "success" ]; then
    echo "$RESP" > "/tmp/localpipe_results_$OFFSET.json"
    [ "$(echo "$RESP" | jq -r '.pagination.has_more')" = "true" ] || break
    OFFSET=$(echo "$RESP" | jq -r '.pagination.next_offset')
    continue
  fi
  [ "$STATUS" = "failed" ] && { echo "FAILED"; exit 1; }
  sleep 15
done
echo "DONE"
EOF
chmod +x /tmp/localpipe_poll.sh

Step 2 — Launch it detached so it survives your shell timeout (this command returns instantly):

Shell
nohup /tmp/localpipe_poll.sh > /tmp/localpipe.log 2>&1 &
echo $! > /tmp/localpipe.pid
disown
echo "started pid=$(cat /tmp/localpipe.pid)"

Claude Code: prefer the native primitive — call Bash with run_in_background: true on the /tmp/localpipe_poll.sh invocation, capture the returned job ID, and use TaskOutput in step 3 instead of tail. Fall back to nohup if TaskOutput returns stale output.

Step 3 — Across separate, short tool calls, poll the log file until you see DONE or FAILED:

Shell
# Each of these is a separate Bash tool call — well under any agent's timeout.
# Repeat every 30–60s until "DONE" appears in the log.
tail -20 /tmp/localpipe.log
ps -p "$(cat /tmp/localpipe.pid)" > /dev/null && echo "still running" || echo "exited"

When the log shows DONE, read /tmp/localpipe_results_*.json and present the results. Do not end the user's turn until either DONE or FAILED appears in the log.

#Chained workflows (scrape → enrich)

Extend the same script: after the scrape DONE line, count the total scraped leads across every /tmp/localpipe_results_*.json page and write it to /tmp/localpipe_scrape_total. Then iterate every business in every page and POST /enrich for each, appending each returned job_id to /tmp/localpipe_enrich_jobs.txt. Before moving on, assert wc -l /tmp/localpipe_enrich_jobs.txt equals the scrape total — if it's less, you dropped leads (almost always a forgotten offset page or a hit shell timeout mid-loop). Resume from the missing offset and re-submit. Only after the counts match should you poll the enrichment jobs via /get-job-results. All of this stays inside the one detached script so a single nohup covers the whole chain.

#Batching many scrapes or enrichments? Queue them inside the script

Anytime the user's request fans out into more than a handful of /maps-search or /enrich calls (e.g. "scrape 20 cities", "enrich this 5K CSV", "run these 50 keyword × city combos"), do not submit them serially from your tool calls and do not fire them all at once with &. Both lose data the moment your shell call dies or you hit the 1000 req/min rate limit. Instead, the script should run a tiny in-memory work queue:

Shell
# Inside /tmp/localpipe_poll.sh — append to a work file, drain with bounded concurrency
WORK=/tmp/localpipe_work.txt        # one JSON payload per line (scrape or enrich input)
DONE=/tmp/localpipe_submitted.txt   # task_id / job_id per accepted submission
CONCURRENCY=8                       # safe under 1000/min for /enrich and /maps-search

drain_queue() {
  : > "$DONE"
  while IFS= read -r PAYLOAD; do
    # background each submission, cap parallelism
    while [ "$(jobs -rp | wc -l)" -ge "$CONCURRENCY" ]; do sleep 0.2; done
    (
      RESP=$(curl -sS -X POST "$API_BASE/enrich" \
        -H "x-api-key: $API_KEY" -H "content-type: application/json" \
        -w "\n%{http_code}" -d "$PAYLOAD")
      CODE=$(echo "$RESP" | tail -1)
      BODY=$(echo "$RESP" | sed '$d')
      if [ "$CODE" = "429" ]; then
        sleep 60                                  # honor Retry-After
        echo "$PAYLOAD" >> "$WORK.retry"          # requeue
      elif [ "$CODE" = "202" ] || [ "$CODE" = "200" ]; then
        echo "$BODY" | jq -r '.job_id // .task_id' >> "$DONE"
      else
        echo "$PAYLOAD" >> "$WORK.failed"         # surface in log, do not silently drop
      fi
    ) &
  done < "$WORK"
  wait
  # re-drain retries until empty
  [ -s "$WORK.retry" ] && { mv "$WORK.retry" "$WORK"; drain_queue; }
}

Why this matters:

  • No data loss on agent timeout — the queue lives on disk; the detached script keeps draining it after your tool call dies.
  • Stays under 1000/min — bounded concurrency + 429 requeue is the only safe way to submit hundreds of jobs without losing them. A naked for loop with & will burst-trigger 429s and silently drop the rejected ones.
  • Resumable — if anything crashes, the script restarts and resumes from $WORK (whatever wasn't moved to $DONE is still pending).
  • Auditable — wc -l "$DONE" must equal wc -l "$WORK_ORIG" before you tell the user "submitted". Same count-matching rule as the chained scrape→enrich flow.

For scrapes that fan out across many cities/keywords, write each {keyword, city, state} combo as one line in $WORK and reuse the exact same drain_queue against /maps-search — then feed every returned task_id into a second queue that polls them all to completion.

#Easier alternative — let us push to you (zero polling)

If the user has any webhook-capable destination (their own server, webhook.site, n8n/Make/Zapier webhook URL, ngrok tunnel), include callback_url in both /maps-search and /enrich POSTs. The script can then exit immediately after enqueueing — we POST the full result payload the moment each job completes. Always prefer this over polling when possible. You still need the script + queue for submission and 429 retries, but you can skip the polling loop entirely.

#Hard rules — never violate these

  1. Never submit and exit. A POST without either (a) a launched detached poll script or (b) a callback_url = guaranteed data loss for the user.
  2. Never put the long wait inside a single foreground tool call. Codex's 10s timer will kill it; Claude's ~80s timer will kill it; the user sees a hang and you see a SIGKILL.
  3. Never add maxAttempts or timeoutMs to the poll loop. Exit only on a terminal status: "success" or "failed" from /get-scrape-results, "completed" or "failed" from /get-job-results. Jobs legitimately run 30+ minutes.
  4. Always persist task_id / job_id to a file (/tmp/localpipe_task.id) before starting the poll. If anything crashes, the user can resume by re-running step 3 against the saved ID.
  5. Always tail the log between poll calls and show the user the latest status line — silent waiting looks like a hang and users will Ctrl-C.
  6. 202 is success, not an error. Some HTTP clients fail res.ok checks on 202. Always read the JSON body regardless of status code on /enrich and /maps-search.
  7. Always paginate /get-scrape-results until pagination.has_more is false. A single call with limit=5000 is NOT guaranteed to return everything — keep requesting pagination.next_offset until has_more is false. Track total leads received.
  8. Enrichment submission count MUST equal scrape result count. Before declaring a chained workflow complete, assert enrich_jobs_submitted == scrape_total. If they don't match, find and resubmit the missing leads — do not tell the user the run is done.
  9. Never sequence multi-step flows from your agent loop. Submit → poll → paginate → fan-out → poll-again all belong inside the script. If your plan involves more than one tool call making HTTP requests to LocalPipe, you wrote the script wrong — extend it instead.
  10. Always queue batches with bounded concurrency inside the script. No for lead in leads; do curl …; done (serial = times out, drops the tail), no for lead in leads; do curl … &; done (burst = 429s, drops the rejected). Use the drain_queue pattern above.

#Anti-patterns — never generate this code

  • ❌ curl -X POST .../enrich && echo "submitted, check dashboard" and end the turn
  • ❌ while true; do curl .../get-job-results; sleep 15; done as a single tool call (killed by shell timeout)
  • ❌ for i in $(seq 1 20); do …; sleep 15; done (gives up after 5 min)
  • ❌ Polling inside a detached setTimeout/Promise after the main function returns
  • ❌ Submitting 100 enrichments in a loop without launching any poller for them
  • ❌ Treating 202 Accepted as a failure
  • ❌ curl ".../get-scrape-results?task_id=X&limit=5000" | jq '.data[] | …enrich…' with no offset pagination — silently drops everything past the first page
  • ❌ Reporting "enrichment started for N leads" where N is smaller than the scrape's total
  • ❌ Driving the scrape→poll→enrich→poll chain across multiple of your own tool calls instead of putting it in one detached script
  • ❌ for lead in $(cat leads.json); do curl .../enrich … &; done; wait — unbounded fan-out; the 429s vanish into the void
  • ❌ for city in cities; do curl .../maps-search -d '{"query":"plumber","location":"'$city'"}'; done — /maps-search accepts arrays for both query and location; send ONE request with "location": [...all cities...] (up to 100) and "query": [...all keywords...] (up to 1,000). Looping per-city is the #1 way AI agents waste rate limit and drop data.
  • ❌ Sending one request per keyword because you are worried about budget skew — each pair now gets its own share of limit, so batch up to 1,000 keywords in one query array and raise limit to N × pairs if you need a guaranteed count each.
  • ❌ Calling a run done without reading sub_query_breakdown. A keyword or city with found: 0, truncated: false is a genuinely empty market; do not re-run it. Only truncated: true means the limit cut results off; raise limit or use "limit": "all".
  • ❌ Treating a zero-row result for a custom keyword as an empty market. Custom keywords bypass exact category matching and use relevance search, so test with "limit": "all" or a larger limit before deciding no leads exist.