Guides · For agent developers · Intermediate
Building a Pay-Per-Crawl Client for Your Agent
A pay-per-crawl client needs four behaviors: register or log in once, send the token header with an honest User-Agent, read charge receipt headers, and branch on denial errors. The snippets below are a pattern you can embed in any agent.
You're reading the full report — free for humans. The machine-readable dataset for this section is open to all agents too — no payment required.
https://esa.aisa.one/api/v1/access/verify
This guide is for developers who want their agent to fetch paid publisher content on the AISA network without hand-holding. You will build a small client in pieces: it obtains a crawler token, crawls with the right header and an honest identity, records what each fetch cost, and reacts correctly to 402 and 403 denials. Billing happens at the publisher's edge, so the client stays thin and has no payment protocol to implement. The snippets alternate between two runtimes, but each function is only a few lines of HTTP and translates one-to-one into whatever stack your agent already uses.
How the flow works
Before you start
- An HTTP client library in your agent's runtime
- An email and password for the crawler account
- A real bot name and info URL for your User-Agent
Step by step
Register or log in once
POST to /api/agent/auth/register. If the email is already registered you get a 409, so fall back to /api/agent/auth/login. Keep crawler.crawlerToken, which is your crawl credential. The response token is a short-lived session token for account APIs only. If signupBonus is present, a trial credit is active and you can crawl immediately. Store the crawler token as a secret and never log it in full.
python import requests BASE = 'https://cdn.aisa.one' def get_account(email, password, name): creds = {'email': email, 'password': password} r = requests.post(BASE + '/api/agent/auth/register', json={**creds, 'name': name, 'crawlerType': 'custom'}) if r.status_code == 409: r = requests.post(BASE + '/api/agent/auth/login', json=creds) r.raise_for_status() body = r.json() return { 'crawler_token': body['crawler']['crawlerToken'], 'session': body.get('token'), 'balance': body['crawler']['balance'], 'bonus': body.get('signupBonus'), }Send the token header and honest User-Agent
Every request to a publisher URL carries X-Crawler-Token, which replaces the earlier name X-AISA-Crawler-Token. Pair it with your genuine User-Agent. Claiming another bot's identity marks you unverified, which forfeits any free passes publishers give verified bots. Never put the crawler token in Authorization: Bearer, because that header is reserved for the gateway layer.
javascript const UA = 'MyBot/1.0 (+https://example.com/bot)'; async function crawl(url, crawlerToken) { return fetch(url, { headers: { 'X-Crawler-Token': crawlerToken, 'User-Agent': UA, }, }); } // Example: // const res = await crawl('https://PUBLISHER-SITE/research/report.data.json', YOUR_CRAWLER_TOKEN);Read the charge receipt headers
A paid 200 may carry X-AISA-Charged and X-AISA-Charge-Amount, so treat them as optional and record them whenever present. A free 200 has no charge. Each fetch of a priced resource deducts its price once, so fetching twice means paying twice; cache what you buy. Denials never charge.
python def read_receipt(resp): charged = resp.headers.get('X-AISA-Charged') amount = resp.headers.get('X-AISA-Charge-Amount') return { 'status': resp.status_code, 'charged': charged == 'true', 'amount': amount, 'url': resp.url, } # Append each receipt to your task log so you can report # free versus paid fetches to your user.Branch on denial errors
Denial bodies are self-describing JSON, so read error first. An invalid_token means register or fix the header, then retry the same URL. An insufficient_balance carries crawler.shortfall, so tell your user. An access_blocked is a publisher policy decision: do not retry or top up, and pivot to the pay-mode directories listed in /pricing.json. For anything else, follow guidance.steps.
python def next_action(resp): if resp.status_code == 200: return 'use the content' body = resp.json() err = body.get('error') if err == 'invalid_token': return 'register or fix the header, then retry the same URL' if err == 'insufficient_balance': short = body.get('crawler', {}).get('shortfall') return 'ask the user to top up, shortfall ' + str(short) if err in ('price_required', 'price_mismatch', 'price_too_high'): return 'read price and currency from the body' if err == 'access_blocked': return 'skip this URL and check pricing.json for pay-mode directories' return 'follow guidance.steps from the body'Fetch the real balance, hand off payment
Call GET /api/agent/balance with the same crawler token you crawl with, and report only the number it returns. Never quote a remembered balance. When funds run out, create a Stripe checkout session with the session token and surface checkout_url to your user. A human completes payment, and the agent must not try to fund itself.
javascript const BASE = 'https://cdn.aisa.one'; async function getBalance(crawlerToken) { const r = await fetch(BASE + '/api/agent/balance', { headers: { 'X-Crawler-Token': crawlerToken }, }); const body = await r.json(); return body.crawler.balance; } async function topUpLink(sessionToken, amount) { const r = await fetch(BASE + '/api/agent/topup/create-session', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + sessionToken, }, body: JSON.stringify({ amount }), }); return (await r.json()).checkout_url; }
Responses and what the client does
| HTTP | error or header | Client action | Cost |
|---|---|---|---|
200 free | none | Use the content | $0 |
200 paid | X-AISA-Charged, X-AISA-Charge-Amount | Record the receipt headers when present | the per-request price |
402 | invalid_token | Register or fix the header, retry the same URL | $0 |
402 | insufficient_balance | Read crawler.shortfall, give the user checkout_url, retry after payment | $0 |
402 | price_required / price_mismatch / price_too_high | Read price and currency from the body | $0 |
403 | access_blocked | Do not retry or top up; pivot to pay-mode directories in /pricing.json | $0 |
Common pitfalls
- Sending the crawler token in Authorization: Bearer makes the request unauthenticated and returns 402 invalid_token. Use X-Crawler-Token only.
- The session token from register or login is for account APIs only. Never use it for crawling, and never send the crawler token to account endpoints expecting a session.
- Never quote a balance from memory. A remembered signup bonus goes stale after the first spend, so call GET /api/agent/balance before reporting.
- Never call POST /api/agent/balance/add to top yourself up. It exists only for a human operator pre-seeding a test account.
Key takeaways
- Your whole crawling contract is the X-Crawler-Token header plus an honest User-Agent; the edge gateway handles authorization and billing.
- Branch on the error field of denial bodies: invalid_token, insufficient_balance and access_blocked each demand a different action.
- Always fetch the real balance with the crawler token, and hand Stripe checkout to a human when funds run out.
FAQ
Which header carries the crawler token?
X-Crawler-Token. The older X-AISA-Crawler-Token spelling is still accepted as an alias, but new integrations should use X-Crawler-Token. Never use Authorization: Bearer for the crawler token.
Does a 402 or 403 response charge my balance?
No. Denials never charge. Only a granted fetch of a priced resource deducts its price, and one request from you is at most one charge.
What should my agent do on a 403 access_blocked?
Do not retry or top up, because payment does not unlock it. Skip that URL, then check the site's /pricing.json for purchasable pay-mode directories and explain the difference to your user.
How does my agent get a crawler token and starting credit?
POST /api/agent/auth/register returns crawler.crawlerToken immediately, with no email verification. If signupBonus is in the response, a trial credit is active and you can crawl before any top-up.
How this page is made. Written from 4 primary sources — the AISA agent and publisher documentation and AgentFlare's own files (pricing.json, robots.txt, llms.txt, live responses, .data.json field lists). Each step links the sources it relies on; steps naming a header, endpoint, error code or figure that the sources do not contain are removed. Refreshed weekly.
Sources & citations
- Header name: X-Crawler-Token esa.aisa.one
- AISA Agent Integration Guide — API reference esa.aisa.one
- AISA agent skill (SKILL.md) esa.aisa.one
- Live capture: anonymous request to a paid AgentFlare file agentflare.org