Since November 12, 2026, Brave's Search API also sells searches to AI agents over x402: an unpaid request gets an HTTP 402 with a price, and the agent pays $0.005 in USDC on Base per request, with no account. That is the same rate as the API key plan, which adds $5 of free credits a month, so most iOS apps should keep the key on their own server. Never put a key or a wallet in the app, disclose that queries go to Brave, and cap searches per request and per day.
On November 12, Brave added a second way to pay for its Search API. Until now you signed up, picked a plan, and sent an API key in a header. Now an AI agent can skip the account entirely: it asks for a search, gets back an HTTP 402 Payment Required response with a price, signs a tiny USDC payment on the Base network, and sends the same request again with the payment attached. The payment itself is the credential. Brave calls this agentic payments, and it runs on the open x402 protocol.
The announcement reached the Hacker News front page on November 13. For anyone shipping apps, the first question is whether to use it at all. If your iOS app has an AI feature that answers questions with fresh web results, or you are building an agent that does research for your users, search is part of your backend. This article explains how the new flow works, using a real 402 challenge captured from Brave's endpoint, what it costs next to the classic API key, where it fits in an iOS app's architecture, and what to put in place before any of your code is allowed to spend money.
What Brave actually launched
Brave's announcement says the Search API now accepts "instant, pay-as-you-go, agentic payments" through x402. Brave runs its own facilitator, which is the service that verifies and settles payments, and it accepts USDC on Base today. The company says other networks and stablecoins are coming, and that it will cover Base gas fees for a limited time.
The paid endpoints live on a separate host, search.agent.s.brave.app. The paths match the regular API on api.search.brave.com, and query parameters pass through unchanged. According to the proxy's own llms.txt file, these paths are for sale at launch: web search, LLM Context, news, videos, images, and the three local endpoints (place search, POIs, and descriptions). Each one costs 5,000 base units of a six decimal token, which is $0.005 per request or $5 per thousand.
Some endpoints are missing on purpose. The Answers API is not sold over x402 because it bills per query and per token, and one fixed price cannot express that. Autosuggest and Spellcheck are not sold either, because each request costs less than the fee a facilitator takes to settle one payment. Brave says those will wait until many queries can be settled together. If you depend on any of these, you still need an API key.
How the pay then retry loop works
The flow is five steps, and it is worth understanding even if a library handles it for you, because your logs and your error handling depend on it.
- Your agent sends a normal GET request with no payment header.
- The proxy answers 402 with an empty body. Everything it wants you to know is in a response header called
Payment-Required, which holds base64 encoded JSON. - Your client decodes that JSON, picks one of the offers it lists, and signs a payment for exactly that offer.
- The client repeats the identical request with a
Payment-Signatureheader. - If the search succeeds and the payment settles, the results come back with a
Payment-Responseheader that works as a receipt.
Here is the real challenge from one unpaid request to the LLM Context endpoint, sent on November 13 while writing this post. Decoded, it looked like this (the recipient address and the long resource description are trimmed here):
{
"x402Version": 2,
"error": "Payment required",
"resource": {
"url": "https://search.agent.s.brave.app/res/v1/llm/context?q=swiftui+navigationstack",
"mimeType": "application/json",
"serviceName": "Brave Search"
},
"accepts": [
{
"scheme": "exact",
"network": "eip155:8453",
"amount": "5000",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"payTo": "(Brave's receiving address)",
"maxTimeoutSeconds": 300,
"extra": { "assetTransferMethod": "eip3009", "name": "USD Coin", "version": "2" }
}
]
}
A few fields matter for your code. network is eip155:8453, the chain ID for Base. amount is a string in base units, so "5000" means half a cent. asset is the USDC token contract on Base. maxTimeoutSeconds is 300, which matches the llms.txt rule that an offer is payable for five minutes. After that you must fetch a fresh 402 instead of paying an old one.
You can look at the same challenge from a terminal without paying anything. This needs curl, base64 and jq, and it only reads headers:
curl -s -D - -o /dev/null \
'https://search.agent.s.brave.app/res/v1/llm/context?q=swiftui+navigationstack' \
| grep -i '^payment-required:' | cut -d' ' -f2 | tr -d '\r' | base64 -d | jq .accepts
Two details from Brave's documentation will save you a debugging session. First, this deployment speaks x402 version 2 only. An older client that sends the version 1 X-Payment header is treated as if it sent nothing, and gets the plain 402 again. Second, send the payment header alone. If an Authorization header rides along with Payment-Signature, the proxy answers 400. Agents that reuse one HTTP client for several services can trip over this when a default header leaks into every request.
When the money moves, and when it does not
The order of operations is friendly to retries. Brave's proxy verifies the payment first, which moves no money, then runs the search, then settles. If the search fails, you are not charged. If you receive results, the payment settled. Repeating a failed search costs nothing extra.
The error table in llms.txt is short and worth copying into your agent's error handling almost line for line:
- A 402 with an empty body means no payment was sent, or it was sent on a rail this deployment does not accept. Read the headers and pay an advertised offer.
- A 402 with
malformed x402 payment payloadmeans yourPayment-Signatureheader is not base64 JSON in the expected shape. - A 402 with
x402 payment did not verifycovers several cases on purpose: the offer was changed, the payment was already used, or it was refused. Fetch a fresh challenge and pay exactly what it says. - A 502 saying the facilitator is unavailable, or that Brave itself could not be reached, means you were not charged. Retry later.
- A 502 saying the payment could not be settled means the search ran but the result was withheld and no money moved. Retry with a new payment, because the old one will be refused.
- A 404 means the path is not for sale. It is never a payable 402.
One more rule protects you from a whole class of bugs: a payment is checked against the price of the path it is sent to. Your agent cannot name its own price, and a modified amount, asset or recipient matches nothing and is refused. There is also no session, no balance and no top-up on Brave's side. Every request carries its own payment, and a receipt proves one purchase and nothing more.
What it costs next to an API key
The headline price is the same on both paths. Brave's pricing page lists the Search plan at $5.00 per 1,000 requests, and the x402 proxy charges $0.005 per request, which is the same rate. The difference is in what comes around that price.
The API key plan is prepaid and includes $5 in free credits every month, applied automatically. At $5 per thousand, that covers about 1,000 searches a month before you pay anything. The plan page lists a capacity of 50 requests per second. Brave's documentation lists no free credits for the x402 path, so every request costs half a cent from the first one. On the other hand, it needs no account, no plan, and no key to store or rotate.
For a small iOS app with an AI feature, the math usually favors the key. Say 300 daily active users each trigger two searches a day. That is about 18,000 searches a month. With an API key you pay for roughly 17,000 of them after the free credits, about $85. Over x402 you pay for all 18,000, about $90, plus whatever your wallet tooling costs to run, and you take on the work of holding USDC. The gap is small in dollars, but the key path is simpler to operate for a single product with predictable traffic.
The x402 path makes more sense in other shapes of work. An agent that runs for a short time, does a few hundred searches, and should not need a human to create an account is the case Brave describes. So is an internal research tool you spin up for a week, or a multi tenant agent platform where each customer's agent should pay from its own wallet instead of sharing your key. If you are writing a coding or research agent for your own team, it can also be a convenient way to give it search without handing it a long lived secret.
Where this fits in an iOS app
The most important rule is the same for both paths: neither the API key nor a wallet belongs inside your app binary. Brave's authentication guide says the key must never be exposed in client side code, and anything shipped in an IPA can be pulled out by anyone who downloads it. A funded wallet is worse than a key, because a leaked key can be revoked from the dashboard, while a leaked wallet's funds can be spent by whoever holds it.
So the app talks to your server, and your server talks to Brave. That server can be a small function in whatever stack you already use. It holds the API key or the wallet, applies your own limits, and returns results to the app. The app never sees a credential, and you can switch from the key to x402, or back, without shipping an update.
There is also an App Review angle. Guideline 3.1.5(i) says apps may facilitate virtual currency storage provided they are offered by developers enrolled as an organization. If you were tempted to put a USDC wallet in the app so each user's agent pays for its own searches, you would be building a crypto wallet feature, with the enrollment requirement and the review attention that come with it. Keeping the wallet on the server avoids that question entirely for a search feature.
Privacy is the other angle. Search queries typed by your users are their data, and you are sending them to a third party. Guideline 5.1.2(i) requires you to disclose where personal data is shared with third parties, including third party AI, and to get explicit permission before doing so. If your AI feature turns a user's question into a Brave query, say so in your privacy policy and in the feature's first run screen, and strip anything you do not need, such as names or email addresses, before the query leaves your server.
A small server proxy with a budget
Here is a minimal Node proxy that uses the classic API key path, because that is the cheaper choice for most apps. It reads the key from an environment variable, rejects empty queries, caps query length, keeps a daily request budget, and turns network failures into a clean 502. It needs Node 18 or later for the built in fetch.
// search-proxy.mjs: your app talks to this, never to Brave directly.
import http from "node:http";
const BRAVE = process.env.BRAVE_BASE ?? "https://api.search.brave.com";
const KEY = process.env.BRAVE_API_KEY; // stays on the server
const DAILY_LIMIT = Number(process.env.DAILY_LIMIT ?? 500);
let day = new Date().toISOString().slice(0, 10);
let used = 0;
http.createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost");
if (url.pathname !== "/search") { res.writeHead(404).end(); return; }
const q = (url.searchParams.get("q") ?? "").trim().slice(0, 200);
if (!q) { res.writeHead(400).end(); return; }
const today = new Date().toISOString().slice(0, 10);
if (today !== day) { day = today; used = 0; }
if (used >= DAILY_LIMIT) {
res.writeHead(429, { "content-type": "application/json" })
.end(JSON.stringify({ error: "daily search budget reached" }));
return;
}
used += 1;
try {
const upstream = await fetch(
`${BRAVE}/res/v1/llm/context?q=${encodeURIComponent(q)}`,
{ headers: { "X-Subscription-Token": KEY, "Accept": "application/json" } }
);
res.writeHead(upstream.status, { "content-type": "application/json" });
res.end(await upstream.text());
} catch {
used -= 1; // a failed call should not use up the budget
res.writeHead(502, { "content-type": "application/json" })
.end(JSON.stringify({ error: "search unavailable" }));
}
}).listen(8787);
This was tested on Linux against a local mock that checks the X-Subscription-Token header, with the daily limit set to 2. Two searches returned 200, the third returned 429 with the budget message, an empty query returned 400, and pointing it at a port with nothing listening returned 502. It was not run against Brave's live API. The in memory counter resets when the process restarts, so a real deployment should keep the count in your database or cache, and should limit per user as well as globally.
Running the proxy on a Mac
The proxy was run again on a Mac with Node 22.17, against a small local stand-in for Brave that checks the X-Subscription-Token header. With DAILY_LIMIT=3, three searches returned 200 and the fourth returned 429, an empty query returned 400, and a wrong key came back to the app as Brave's 401. The stand-in confirmed it saw exactly three authorized calls.
One case behaved differently from what you would want. With the upstream address pointing at a port where nothing listens, three searches returned 502, and the fourth returned 429: the failed calls had used up the day's budget. In real life that means a short Brave or network outage, plus an app that retries, can lock your users out of search for the rest of the day even though nothing was searched. The proxy above now gives the budget back when the call to Brave fails. After that change, five searches during the same outage all returned 502, and with the upstream working the limit still stopped the fourth search.
Two more details are worth knowing before you deploy it. The day rolls over on toISOString(), which is UTC, so for users in Indonesia the budget resets at 07:00 WIB, not at midnight. And fetch is called without a timeout, so a slow upstream holds the app's request open. Passing signal: AbortSignal.timeout(10000) in the fetch options is one way to bound it.
The Swift client below was type-checked in the Swift 5 and Swift 6 language modes with no warnings, then built with its base URL pointed at the local proxy and run with a limit of 2. A normal query returned the stand-in's 28-byte body, an empty query threw badStatus(400), a second query succeeded, and the third threw budgetReached, which is the state your UI should show as "busy".
Calling it from Swift
On the app side you only need a plain request to your own endpoint and a clear mapping of status codes to states your UI can show. This snippet was later compiled and run on a Mac against the proxy above, as described in the previous section:
import Foundation
struct SearchClient {
let base = URL(string: "https://api.yourapp.example")!
enum SearchError: Error { case budgetReached, unavailable, badStatus(Int) }
func context(for query: String) async throws -> Data {
var comps = URLComponents(url: base.appendingPathComponent("search"),
resolvingAgainstBaseURL: false)!
comps.queryItems = [URLQueryItem(name: "q", value: query)]
let (data, response) = try await URLSession.shared.data(from: comps.url!)
let status = (response as? HTTPURLResponse)?.statusCode ?? 0
switch status {
case 200: return data
case 429: throw SearchError.budgetReached
case 502, 503: throw SearchError.unavailable
default: throw SearchError.badStatus(status)
}
}
}
Give the 429 case its own message in the interface, something like "Search is busy, try again later," and keep the rest of the feature working without search results. An AI answer without fresh context is better than a spinner that never ends, and it gives App Review nothing to flag as a broken feature during testing.
If you do use x402: cap the price before you pay
The x402 path moves real money automatically, so the first guardrail is a price check that runs before any signing. Stripe's purl client has this built in. Brave's example uses --max-amount, which is the most purl will pay in base units:
purl --max-amount 5000 'https://search.agent.s.brave.app/res/v1/web/search?q=rust'
If your agent uses another client, or you want a check in a deploy script or a monitoring job, the 402 challenge tells you the price without spending anything. This Python script reads the Payment-Required header, picks the cheapest offer, and exits with 0 if the price is at or under your cap, 1 if it is over, and 2 if the endpoint did not answer with an x402 version 2 challenge. It uses only the standard library and never signs or pays.
#!/usr/bin/env python3
"""Ask an x402 endpoint what a request costs, without paying.
Usage: probe_price.py URL MAX_BASE_UNITS
Exits 0 if the advertised price is at or under the cap, 1 if over,
2 if the endpoint did not answer with an x402 V2 challenge.
"""
import base64, json, sys, urllib.request, urllib.error
def read_challenge(url):
req = urllib.request.Request(url, method="GET")
try:
urllib.request.urlopen(req, timeout=15)
except urllib.error.HTTPError as e:
if e.code != 402:
return None, f"status {e.code}"
raw = e.headers.get("Payment-Required")
if not raw:
return None, "402 without a Payment-Required header"
return json.loads(base64.b64decode(raw)), None
except urllib.error.URLError as e:
return None, f"could not connect: {e.reason}"
return None, "no 402: the request went through without payment"
def main():
if len(sys.argv) != 3:
print(__doc__)
return 2
url, cap = sys.argv[1], int(sys.argv[2])
challenge, err = read_challenge(url)
if err:
print("not an x402 challenge:", err)
return 2
if challenge.get("x402Version") != 2:
print("unexpected x402 version:", challenge.get("x402Version"))
return 2
offers = challenge.get("accepts", [])
if not offers:
print("payments paused: no offers")
return 2
cheapest = min(offers, key=lambda o: int(o["amount"]))
amount = int(cheapest["amount"])
usd = amount / 1_000_000 # USDC has 6 decimals
print(f"network={cheapest['network']} amount={amount} (${usd:.4f}) "
f"expires_in={cheapest.get('maxTimeoutSeconds')}s")
if amount > cap:
print(f"over the cap of {cap}; not paying")
return 1
print("within the cap")
return 0
if __name__ == "__main__":
sys.exit(main())
Testing note: it was run on Linux against two local mock servers that send the same header shape as Brave's real 402. A 5,000 unit price with a 10,000 cap returned 0, a 50,000 unit price returned 1, and an unreachable port returned 2 after printing the connection error. Run as a scheduled check against the live proxy, it will warn you if the advertised price ever changes, and it costs nothing because unpaid requests are never charged.
Beyond the per request cap, give the agent's wallet only the money you are willing to lose. Fund it in small amounts, keep it separate from any wallet that holds real savings, and log every Payment-Response receipt next to the query that produced it. Brave notes that purl does not print the receipt, so if you need an audit trail with purl you have to look the transfer up on the chain. A library such as @x402/fetch, which Brave lists as a supported client, gives your code direct access to response headers.
The price check against Brave's live endpoint
On November 16, 2026, the terminal command from earlier and the price check were run against Brave's real x402 host. Both only read the 402 response, so nothing was paid and no wallet was involved. The command printed one offer: scheme exact, network eip155:8453, amount 5000, the USDC contract on Base, maxTimeoutSeconds 300, and an extra block naming eip3009 as the transfer method. That matches the challenge shown above. The base64 -d in it works with the base64 that ships with macOS.
The Python check, run with the system Python 3.9 on macOS, gave the expected answers:
- Web search with a cap of 10,000 printed "amount=5000 ($0.0050) expires_in=300s", then "within the cap", and exited 0.
- The same with a cap of 1,000 printed "over the cap of 1000; not paying" and exited 1.
- News search was also priced at 5,000 base units.
- The Autosuggest path returned a 404, and the script exited 2, which fits the rule that a path not for sale is never a payable 402.
Two runs showed where a monitoring job could read the wrong thing. With the python.org build of Python 3.12, which has no root certificates until you run its Install Certificates command, every check exited 2 with "CERTIFICATE_VERIFY_FAILED". The message is clear, but a job that only looks at the exit code would treat it as "not an x402 endpoint". And with the cap argument left out, the original script stopped with an IndexError and exit code 1, the same code it uses for "over the cap". The script above now prints its usage and exits 2 when the arguments are missing.
Agent loops are where the money leaks
The bigger risk with pay per request search is an agent that searches far more than you expected. A research loop that retries a vague query, or a planning step that searches once per sub task, can turn one user question into dozens of paid requests. With an API key the damage shows up on a monthly bill. With a funded wallet it shows up as an empty wallet. AI Coding Costs: Why Your Agent Bill Is Mostly Re-Reading shows the same pattern in coding agents.
Three limits catch most of this. Set a maximum number of searches per user request and stop the loop when it is reached. Cache results by normalized query for at least a few minutes, because agents often repeat the same search. And keep a daily cap at the server, like the counter in the proxy above, so a bug in one release cannot drain a month's budget overnight. Log the count of searches per conversation for your first week in production, and adjust the limits from what you see.
Also watch for prompt injection through search results. Web pages can contain text written to steer an agent. If your agent can both read search results and trigger actions that cost money, a hostile page could try to talk it into more searches or other paid calls. Treat search results as data, keep the payment limits in code where the model cannot change them, and do not let the model choose the cap. OpenAI Agents Escaped a Sandbox and Hacked Hugging Face has more on keeping agents away from actions they should not take.
A quick decision checklist
- One app, predictable traffic, a server you already run: use the API key, keep it on the server, and take the monthly free credits.
- You need Answers, Autosuggest or Spellcheck: use the API key, because x402 does not sell those yet.
- A short lived agent or tool that should not need an account: x402 is a reasonable fit, with a price cap and a small wallet.
- Many customers' agents that should each pay their own way: x402 can work, with one wallet per customer held server side.
- Anything that would put a wallet or a key in the iOS app itself: do not ship it.
- Every path: disclose that queries go to Brave, strip personal details, and cap searches per request and per day.
FAQ
Do I need a Brave account to use the x402 endpoints?
No. Brave says each request carries its own payment, so an account is not needed. You do need a funded wallet with USDC on Base and an x402 version 2 client.
Is the x402 price cheaper than the API key?
The per request rate is the same, $5 per thousand. The API key plan adds $5 of free credits each month, so for steady traffic the key usually costs a little less overall.
What happens if a search fails after I pay?
You are not charged for failed searches. Brave verifies the payment first, runs the search, then settles. If settlement fails after the search, the result is withheld and no money moves.
Can my iOS app call the x402 endpoint directly?
It could technically, but the app would need to hold a funded wallet, which anyone can extract from a shipped app, and it would raise guideline 3.1.5 questions. Keep payments on your server.
Which endpoints still require an API key?
Answers, Autosuggest and Spellcheck, according to Brave's agent payments guide and llms.txt. The Summarizer is deprecated.
How long is a 402 offer valid?
The offer captured for this post had maxTimeoutSeconds set to 300, and llms.txt says an x402 offer is payable for 300 seconds. After that, request a fresh challenge.
Tools for setting up the agent itself
If you are building the agent that will call this search proxy, the free The Coding Agent Lab pack on Gumroad has 25 written agent briefs for tools like Claude Code and Cursor, each with a mission, rules, an output format and quality gates. It includes agents for iOS, security and testing. It does not include x402 or payment code, so use it for the agent's working rules and the snippets above for the search and budget parts.
Keep reading on JR Devhub
- Apple Now Sells $49.99 AI Usage Packs. If Your App Uses Private Cloud Compute, Build the Limit Screen First
- Cursor Can Now Deploy Your App From a Prompt. Test These 5 Bugs Before You Share the Link
- ChatGPT vs Gemini vs Claude on Google Trends: What the Numbers Show and How to Get Cited in AI Answers
- Outlook.com Is Bouncing Mail From Domains With No DMARC Record. Fix Your App's Sign-Up Emails First
Sources
- Brave: The Brave Search API now accepts agentic payments via the x402 protocol (Nov 12, 2026)
- Brave Search API: Agent payments guide
- Brave x402 proxy: llms.txt (prices, headers, error table)
- Brave Search API: Authentication
- Brave Search API: Pricing
- Stripe purl on GitHub
- Apple App Review Guidelines (3.1.5 and 5.1.2)
- Hacker News front page, Nov 13, 2026

Comments