Guides · For agent developers · Beginner
Handling 402 and 403 Responses: An Error Reference for Agents
AISA denials come as HTTP 402 or 403 with a self-describing JSON body. Read the error field, follow the guidance block, and tell your user plainly what happened and what it cost.
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 building agents or crawlers that fetch paid publisher content through the AISA pay-per-crawl network. You will learn every denial error code an agent can receive, what each one means, and the next action for each. You will also learn how to use the guidance block that comes with each denial, and what to say to your user for a payment problem versus a publisher block. By the end, your agent should branch correctly on 402 and 403 instead of retrying blindly.
How the flow works
Before you start
- A registered AISA crawler account and its crawler token
- Ability to send HTTP requests with custom headers
- A way to show messages and links to your user
Step by step
Send the token header with an honest User-Agent
Every request to a publisher site carries your crawler token in X-Crawler-Token, which replaces the earlier name X-AISA-Crawler-Token. Send your genuine User-Agent too. Authorization and billing happen at the publisher's edge, so you only read what comes back: 200 content, a 402 payment denial, or a 403 blocked denial. Denials never charge. Omit the header on a priced resource and you get 402 with the error invalid_token.
bash curl -i 'https://PUBLISHER-SITE/research/report.data.json' \ -H 'X-Crawler-Token: YOUR_CRAWLER_TOKEN' \ -A 'MyBot/1.0 (+https://example.com/bot)'Branch on the error field first
On a 402 or 403, parse the JSON body and check error before anything else. The body is self-describing: error says why the request was denied, and guidance says exactly what to do next. The body also carries accessGranted, statusCode, message, and often a rule object with urlPattern, accessMode, price and currency. Print guidance.steps so the next action is visible to you and to your user.
python import requests url = 'https://PUBLISHER-SITE/research/report.data.json' headers = {'X-Crawler-Token': 'YOUR_CRAWLER_TOKEN', 'User-Agent': 'MyBot/1.0 (+https://example.com/bot)'} r = requests.get(url, headers=headers) if r.status_code in (402, 403): body = r.json() err = body.get('error') if err == 'invalid_token': print('Register or fix the header, then retry the same URL') elif err == 'insufficient_balance': print('Top up. Shortfall:', body.get('crawler', {}).get('shortfall')) elif err == 'access_blocked': print('Skip this URL and look for pay-mode directories') for s in body.get('guidance', {}).get('steps', []): print(s)Fix invalid_token by registering or correcting the header
A 402 with invalid_token means the token was missing, unknown or inactive. If you have no account, register through the API; a signupBonus trial credit may come back, so check the response rather than assuming one. Keep crawler.crawlerToken for crawling, and never put it in Authorization: Bearer, because that request is treated as unauthenticated and returns 402 invalid_token. Then retry the exact same URL. If guidance.registerApi names a different AISA host, prefer that host.
python import requests base = 'https://cdn.aisa.one' r = requests.post(base + '/api/agent/auth/register', json={ 'email': 'mybot@example.com', 'password': 'YOUR_PASSWORD', 'name': 'MyBot', 'crawlerType': 'custom'}) data = r.json() token = data['crawler']['crawlerToken'] print('Token prefix:', token[:17]) print('Trial credit:', data.get('signupBonus'))Handle insufficient_balance with a fetched balance
A 402 with insufficient_balance includes crawler.shortfall, the amount you still need. Fetch the real balance with GET /api/agent/balance using the same crawler token; never quote it from memory. Then create a Stripe checkout session through POST /api/agent/topup/create-session, which has a minimum of 0.50 USD, and hand the checkout_url to your user. Paying needs a human, so wait for them, then retry. Never call POST /api/agent/balance/add.
python import requests base = 'https://cdn.aisa.one' b = requests.get(base + '/api/agent/balance', headers={'X-Crawler-Token': 'YOUR_CRAWLER_TOKEN'}).json() print('Real balance:', b['crawler']['balance']) t = requests.post(base + '/api/agent/topup/create-session', headers={'Authorization': 'Bearer YOUR_SESSION_TOKEN'}, json={'amount': 5.00}) print('Ask the user to pay here:', t.json()['checkout_url'])Pivot when access_blocked appears
A 403 with access_blocked is the publisher's own policy choice for that resource, not a payment problem. Payment does not unlock it, so do not retry the URL and do not top up for it. Do not abandon the task either: fetch the site's /pricing.json, which lists purchasable pay-mode directories, and continue with content that is for sale. Skipping a blocked URL and buying other priced content is the intended use of the API.
bash curl -s 'https://PUBLISHER-SITE/pricing.json' \ -H 'X-Crawler-Token: YOUR_CRAWLER_TOKEN' curl -s 'https://PUBLISHER-SITE/llms.txt'Tell your user what happened in plain words
Your agent should narrate the denial, as guidance.agentAdvice asks: say what was denied, why, and what happens next. After a successful retry, report whether the content was free or paid, the exact amount charged, and the real remaining balance fetched from the balance endpoint. For a block, explain the difference between a publisher policy and a payment problem, and name the pay-mode directories you will try instead.
text invalid_token: I had no valid crawler token, so I registered an account and will retry this URL. insufficient_balance: The balance is short by the shortfall amount. Please open this link to add funds: CHECKOUT_URL. I will continue after you pay. access_blocked: The publisher does not allow crawlers on this page, and payment cannot change that. I skipped it and will use their purchasable directories instead. After a paid fetch: This content was paid, the charge was AMOUNT, and the remaining balance is BALANCE.
AISA denial error codes
| HTTP | error | Meaning | Next action |
|---|---|---|---|
402 | invalid_token | No, unknown or inactive token | Register or fix X-Crawler-Token, then retry the same URL |
402 | insufficient_balance | Balance too low; crawler.shortfall gives the amount needed | Fetch balance, hand checkout_url to the user, retry after they pay |
402 | price_required | Price negotiation state, rarely seen | Read the quote in price and currency |
402 | price_mismatch | Price negotiation state, rarely seen | Read the quote in price and currency |
402 | price_too_high | Price negotiation state, rarely seen | Read the quote in price and currency |
403 | access_blocked | Publisher rule withholds this resource from crawlers | Do not retry or top up; pivot to pay-mode directories in /pricing.json |
Common pitfalls
- Sending the crawler token in Authorization: Bearer makes the request unauthenticated and returns 402 invalid_token. Use X-Crawler-Token only.
- Do not top up or retry after access_blocked; the publisher forbids that resource and payment does not unlock it.
- Never call POST /api/agent/balance/add to fund yourself. It exists only for a human operator to pre-seed a test account.
- Never print the full crawler token in logs or reports; show a prefix such as aisa_crawler_9a4d... instead.
Key takeaways
- Read the error field first: invalid_token and insufficient_balance are payment fixes, access_blocked is a publisher policy.
- Follow guidance.steps, and prefer the AISA host named in guidance.registerApi for the site you crawl.
- Fetch the real balance before reporting it, and give your user the checkout_url, since a human must pay.
FAQ
Does a 402 or 403 response charge my balance?
No. Denials never charge. Only a granted fetch of a priced resource deducts its per-request price, and one request from you is at most one charge. Price discovery through the rule object in a 402 is free.
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.
Can my agent top up its own balance?
No. Completing a Stripe payment needs a human. Create a checkout session, show the checkout_url to your user, and wait for them to pay before retrying.
What should an agent do after a 403 access_blocked?
Do not retry that URL or top up for it. Fetch the site's /pricing.json, continue with its purchasable pay-mode directories, and explain to your user that the block is a publisher policy.
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