---
title: "B2B data for AI agents: wiring in a paid API | Forager"
description: "Expose people search and contact lookups as tools, run the loop server-side, cap calls per task, trim results and keep the API key out of the model."
canonical: https://www.forager.ai/blog/b2b-data-for-ai-agents-paid-api
lang: en
---
# B2B data for AI agents: how to wire in a paid API

GuideAI agents

Give the model two tools, keep the API key and the credit budget in your own code, and hand back only the fields the model needs. Working tool definitions, executor code and the error rules, from the Forager recipe.

Written by [Justin Winter](https://www.forager.ai/authors/justin-winter), Head of Growth Founder and growth executive across VC-backed startups and B2B SaaS.

Published November 24, 2026 8 min read

**Build it on a free API key**

- Get $5 in free credits
- No credit card to sign up

[Get $5 free](https://app.forager.ai/sign-up)   [Book a demo →](https://www.forager.ai/demo)

On this page

## Key takeaways

- The model picks a tool and its arguments. Your server holds the key, makes the call and trims the result.
- Write tool descriptions that say what a call costs, so the model searches first and looks up only the people who matter.
- Search is cheap and a contact lookup costs more. A mobile lookup is 15 credits per mobile found and 0 credits when nothing is found.
- Cap the calls per task, so a decision the model takes cannot become an open-ended bill.

**The short version.** An AI agent gets B2B data through tools your code executes. The model picks a tool and its arguments. Your server calls the data API with the key, trims the result and returns it. The model never holds the key, and it never holds an unlimited budget.

Every paid call an agent makes is a decision the model took on your account. This guide is about the three things that keep that safe: tool descriptions that say what a call costs, a loop that runs on your server, and a cap on calls per task. The code is from the [agent tool-calling recipe](https://docs.forager.ai/api-overview/recipes) in the Forager docs, so you can paste it rather than retype it.

## Which data an agent needs, by task

Most agent tasks that touch B2B data come down to three jobs, and each job maps to one endpoint. The cheap calls come first. Search returns ids. A contact lookup spends more credits, so it runs only on the ids the user actually cares about.

| The agent's job | What it has | Endpoint | Credits |
| --- | --- | --- | --- |
| Find people by role | A job title, optionally company domains | `POST /datastorage/person_role_search/` | 1 per call |
| Enrich one person | A LinkedIn handle or a Forager person id | `POST /datastorage/person_detail_lookup/` | 1 |
| Get a mobile number | A person id from the search | `POST /datastorage/person_contacts_lookup/phone_numbers/` | 15 per mobile found; nothing found costs 0 credits |
| Get a personal email | A person id | `POST /datastorage/person_contacts_lookup/personal_emails/` | 5, only when at least one address is returned |
| Get a work email | Name and company domain, or a LinkedIn handle | `POST /api/v2/{account_id}/datastorage/person_contacts_lookup/work_emails/` (async, poll for the result) | 5, only when an address is found |
| Find companies | Industry, size, location or technology filters | `POST /datastorage/organization_search/` | 1 per call |
| Find job postings | A title, company, location or date | `POST /datastorage/job_search/` | 2 per call |

Paths are relative to `https://api-v2.forager.ai/api/{account_id}/`. The [choose an endpoint](https://docs.forager.ai/openapi) guide has the full map, and [credit pricing](https://docs.forager.ai/api-overview/credit-pricing) is the source of truth for the numbers. Autocomplete, feedback and polling a work email job are free.

The rest of this guide wires in the first and third rows: search people by role, then look up a phone number. The same pattern covers every other row, because each one is a single POST.

## Tool definitions that say what a call costs

A tool is a name, a description and a JSON Schema for its arguments. Most model providers accept this shape in their tool-calling API; only the wrapper keys differ. The description is the part people skip, and it is the part that controls spend. The model reads it to decide whether a call is worth making. If the description says a lookup costs more than a search, the model searches first and looks up only the people the user asked about.

```
[
{
"name": "search_people_by_role",
"description": "Find people by job title, optionally limited to company domains. Returns up to one page of matches with person ids. Costs credits per call.",
"parameters": {
"type": "object",
"properties": {
"role_title": { "type": "string", "description": "Job title. Supports a boolean text query." },
"role_is_current": { "type": "boolean", "description": "Only current roles." },
"organization_domains": { "type": "array", "items": { "type": "string" }, "description": "Company domains, for example example.com." },
"page": { "type": "integer", "description": "Page number." }
},
"required": ["role_title"]
}
},
{
"name": "find_phone_numbers",
"description": "Get phone numbers for one person by person_id. Costs more credits than a search, so call it only for people the user asked about.",
"parameters": {
"type": "object",
"properties": {
"person_id": { "type": "integer", "description": "The id from search_people_by_role." }
},
"required": ["person_id"]
}
}
]
```

Two things to notice. `find_phone_numbers` takes a `person_id`, and the only way the model can get one is from `search_people_by_role`. That ordering is enforced by the schema, so the model cannot skip to the expensive call. And neither description mentions a credit count. Prices change; the relative cost ("more than a search") is what the model needs to choose well.

Evidence

**15 credits**

for a mobile number lookup, against 1 credit for a people search by role.

Source: [Forager docs, credit pricing](https://docs.forager.ai/api-overview/credit-pricing)

## The loop, server-side

The model decides when to call. Your code decides what it may spend. That split is the whole design. The executor is the only place the key lives, and every request to the data API goes through it.

Each tool maps to one request. These are the two requests your executor sends.

**cURL**

```
curl -X POST "https://api-v2.forager.ai/api/$FORAGER_ACCOUNT_ID/datastorage/person_role_search/" \
-H "X-API-KEY: $FORAGER_API_KEY" -H "Content-Type: application/json" \
-d '{"role_title": "Head of Data", "role_is_current": true, "organization_domains": ["example.com"]}'

curl -X POST "https://api-v2.forager.ai/api/$FORAGER_ACCOUNT_ID/datastorage/person_contacts_lookup/phone_numbers/" \
-H "X-API-KEY: $FORAGER_API_KEY" -H "Content-Type: application/json" \
-d '{"person_id": 123}'
```

**Python (requests)**

```
import os, time, requests

BASE = f"https://api-v2.forager.ai/api/{os.environ['FORAGER_ACCOUNT_ID']}/datastorage"
HEADERS = {"X-API-KEY": os.environ["FORAGER_API_KEY"]}
ENDPOINTS = {
"search_people_by_role": "person_role_search/",
"find_phone_numbers": "person_contacts_lookup/phone_numbers/",
}

def execute(name, args):
if name not in ENDPOINTS:
return {"error": "unknown_tool"}
for attempt in range(2):
r = requests.post(BASE + "/" + ENDPOINTS[name], headers=HEADERS, json=args, timeout=30)
if r.status_code == 429 and attempt == 0:
time.sleep(2)
continue
break
if r.status_code == 403:
raise RuntimeError("Forager rejected the API key")  # fatal: never show the model
if r.status_code == 429:
return {"error": "rate_limited"}
r.raise_for_status()
data = r.json() if r.content else []
if name == "search_people_by_role":
return {"total": data["total_search_results"], "people": [
{"person_id": h["person"]["id"], "name": h["person"]["full_name"],
"title": h["role_title"], "company": h["organization"]["name"]}
for h in data["search_results"]]}
return {"phone_numbers": [row["phone_number"] for row in data]}
```

**JavaScript (fetch)**

```
const BASE = `https://api-v2.forager.ai/api/${process.env.FORAGER_ACCOUNT_ID}/datastorage/`;
const ENDPOINTS = {
search_people_by_role: "person_role_search/",
find_phone_numbers: "person_contacts_lookup/phone_numbers/",
};

async function execute(name, args) {
if (!(name in ENDPOINTS)) return { error: "unknown_tool" };
let res;
for (let attempt = 0; attempt < 2; attempt++) {
res = await fetch(BASE + ENDPOINTS[name], {
method: "POST",
headers: { "X-API-KEY": process.env.FORAGER_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify(args),
});
if (res.status !== 429 || attempt === 1) break;
await new Promise((ok) => setTimeout(ok, 2000));
}
if (res.status === 403) throw new Error("Forager rejected the API key");
if (res.status === 429) return { error: "rate_limited" };
if (!res.ok) throw new Error(`Forager ${res.status}`);
const text = await res.text();
const data = text ? JSON.parse(text) : [];
if (name === "find_phone_numbers") return { phone_numbers: data.map((r) => r.phone_number) };
return {
total: data.total_search_results,
people: data.search_results.map((h) => ({
person_id: h.person.id, name: h.person.full_name,
title: h.role_title, company: h.organization.name,
})),
};
}
```

The key comes from the environment, never from the prompt, the conversation or a browser. If your agent runs in a client, put the executor behind your own endpoint and let the client call that.

Then the loop itself. `call_model` wraps your provider's tool-calling API and returns the reply's text plus any tool calls, each with an `id`, a `name` and `arguments`.

```
import json

MAX_CALLS = 6  # per run, to cap credit spend

def call_model(messages, tools):
# Replace with a call to your model provider's tool-calling API.
raise NotImplementedError

def run_agent(messages, tools):
calls_made = 0
while True:
reply = call_model(messages, tools)
if not reply.tool_calls:
return reply.text
messages.append(reply.raw)  # the assistant turn, in your provider's format
for call in reply.tool_calls:
calls_made += 1
if calls_made > MAX_CALLS:
result = {"error": "call_budget_reached"}
else:
result = execute(call.name, call.arguments)
messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
```

The role and field names for tool results differ between providers. Adapt the two `messages.append` lines to yours and the rest stays the same.

## Budgets and trimming

A loop with no cap can spend fast. A role search is 1 credit per request and a mobile number lookup is 15 credits per number found, so a model that calls `find_phone_numbers` on every search hit will burn through a balance before the user sees an answer. Three rules keep it in check.

**Cap calls per task.** `MAX_CALLS` above is the simplest version. Once the budget is reached, the executor returns `call_budget_reached` as data, and the model can tell the user what it found so far. Log every call with its tool name and arguments, so you can see what a run cost after the fact. The [Forager API skill](https://docs.forager.ai/skill.md) puts the same rule in plain words for a coding agent: never loop over results calling a paid endpoint without the user agreeing to the total.

**Search before lookup.** The schema already forces this, because a lookup needs a `person_id` that only a search returns. The description does the rest. If you want the model to confirm with the user before a lookup, say so in the system prompt and keep the lookup tool's description unchanged.

**Return only what the model needs.** The `execute` functions above return ids, names, titles, companies and phone numbers, and nothing else. A full person record is large. Passing it back whole fills the context window, slows the model and gives it fields it was never going to use. Trim at the executor, where you know the shape of the response.

**Put this into practice** Create an account, copy your key and Account ID, and run the recipe on your own search.

[Get $5 free](https://app.forager.ai/sign-up)

## Errors the model should and should not see

An agent handles three kinds of outcome, and each one goes to a different place.

**A miss is a result.** An empty `people` list or an empty `phone_numbers` list goes back to the model as data. The model can then say "no number found" instead of inventing one.

**429 is retried once, then surfaced.** The executor sleeps two seconds and tries again. If the second attempt is also rate limited, it returns `rate_limited` as data, so the model can stop or wait rather than hammer the API. The documented limits today are 10 requests per second on autocomplete and 60 per minute on feedback, both per account; the single work email lookup is rate limited for interactive use. The docs do not publish limits for the other endpoints today, so treat a `429` as the signal and back off.

**403 is fatal and stays with you.** A missing or invalid key returns `403` with `{"detail": "Authentication credentials were not provided."}`. The executor raises, the loop stops, and a human gets the alert. The model never sees it. There is nothing a model can do about a bad key except retry, and a retry loop on a 403 is wasted traffic. Note that it is a `403`, not a `401`, so match on the right code.

Full detail is on the [errors and rate limits](https://docs.forager.ai/openapi) page.

## Docs an agent can read

If the agent that builds your integration is itself a model, give it the docs in a shape it can read rather than a link to a rendered site.

| What | Where | Use it for |
| --- | --- | --- |
| OpenAPI 3 spec | `https://www.forager.ai/docs/openapi.yaml` | Discover every operation and parameter |
| `llms.txt` | `https://www.forager.ai/docs/llms.txt` | A short index of all pages, to decide what to read |
| `llms-full.txt` | `https://www.forager.ai/docs/llms-full.txt` | The whole documentation as one text file |
| Markdown of a page | Add `.md` to any docs URL | One page without the site chrome |
| Recipe prompts | Top of every [recipe](https://docs.forager.ai/api-overview/recipes) | A paste-ready brief for a coding agent |
| Forager API skill | `https://www.forager.ai/docs/skill.md` | Endpoints, auth and credit rules in the Agent Skills format |

The agent tool-calling recipe starts with a prompt you can paste into a coding agent. It asks for the two tools, the server-side loop, the call cap, the not-found and 429 handling, the fatal 403, and tests with a fake model and stubbed HTTP. That is the same list as this guide, in the order a build goes.

## FAQ

Can an agent call Forager directly?

Yes, through the REST API, with the key held by your server. The model proposes a tool call; your executor sends the request with `X-API-KEY` and returns a trimmed result. The model never holds the key.

How do I stop an agent spending credits?

Three ways, in this order: a per-task call cap in the executor, tool descriptions that say a lookup costs more than a search, and a system prompt that asks the model to confirm with the user before any lookup. Log every call so you can audit a run.

What does the model see when nothing is found?

An empty list. An empty `people` or `phone_numbers` list is a valid result and goes back to the model as data, so it can tell the user rather than guess.

Which docs should I give the agent?

The OpenAPI spec for operations and parameters, `llms.txt` to pick pages, and the recipe prompt for the build itself. If the agent is skill-aware, add `/skill.md` as `forager-api/SKILL.md` in its skills directory.

## What page 1 says

For the query "b2b data for ai agents", the page-1 how-to is LinkupAPI's "B2B Data for AI Agents: How to Wire It In (2026)", updated June 7, 2026 and retrieved November 1, 2026. It covers what counts as B2B data, why a model cannot know current facts, how the data reaches an agent, live data versus snapshots, and how buying signals reach an agent. As of that date the page has no tool definitions, no executor code, no call budget and no key handling. Those are the parts this guide adds.

## Build it on a free API key

Create an account, copy your key and Account ID, and run the recipe on your own search.

- Get $5 in free credits
- No credit card to sign up

[Get $5 free](https://app.forager.ai/sign-up) [Read the recipe](https://docs.forager.ai/api-overview/recipes)

**#1 of 10 in Clay's 2026 test of mobile data providers** [Source: Clay](https://www.clay.com/blog/best-mobile-phone-data)

Related: [B2B data for AI SDRs and agent builders](https://www.forager.ai/solutions/ai-agent-platforms) [Build with AI agents (docs)](https://docs.forager.ai/api-overview/send-your-first-request) [Pricing](https://www.forager.ai/pricing) [Platforms](https://www.forager.ai/platforms)

**Justin Winter**  Head of Growth at Forager. Founder and growth executive across VC-backed startups and B2B SaaS.

[All posts](https://www.forager.ai/authors/justin-winter) [iamjustinwinter.com](https://iamjustinwinter.com/) [X (@jcwinter)](https://x.com/jcwinter)

## More from the blog

[All posts](https://www.forager.ai/blog)

- [GuideRecruiting How to add candidate contact details to a recruiting platform Build a get-contact-details action: profile URL to identifier, separate personal email and mobile lookups, a validation filter, and reported call outcomes. December 1, 20268 min read**Justin Winter**](https://www.forager.ai/blog/add-candidate-contact-details-to-a-recruiting-platform)
- [ArticleProduct updates Silver mobiles: more numbers, every Gold number included Silver is a second set of mobile numbers on every Forager phone lookup. It includes every Gold number, costs 9 credits, and you choose it per request. November 18, 20263 min read**Justin Winter**](https://www.forager.ai/blog/silver-mobile-numbers)
- [ArticleData feeds Professional profile dataset: fields, delivery and license What a licensed profile dataset holds, how it reaches S3, GCS or Snowflake, how to read date_updated and schema_version, and what to ask before signing. November 17, 20268 min read**Justin Winter**](https://www.forager.ai/blog/professional-profile-dataset-fields-delivery-license)

---
Source: https://www.forager.ai/blog/b2b-data-for-ai-agents-paid-api (Markdown version of the HTML page). Site index: https://www.forager.ai/llms.txt
