作者審核 28 個付費 API 描述,發現 21 個套用模板並修正
I audited 28 paid API descriptions. 21 were a template — here is the exact fix.
作者審核自己的付費 API 的 28 項描述,發現 21 項只是套用同一模板,遂補上各任務的具體説明,沒有更改路由或價格。他逐一檢查線上端點,結果是 28/28 項描述具體、0 項仍含模板字串。部署時,他重啟的服務監聽 8080,但 nginx 實際轉發至 8000;最近 5000 個請求中,2867 個收到 HTTP 402,只有 12 次付費,呼叫者多為索引器和監測工具,而非買家。
I audited 28 paid API descriptions. 21 were a template — here is the exact fix.
A few days ago an independent auditor sent me a short, uncomfortable email. He had re-probed my paid API against production rather than trusting my own description of a fix.
His verdict had two halves:
- The fix was real. All three claims held.
- But 21 of my 28 product descriptions were a template.
That second line was the useful one.
The template
Here is what 21 of my 28 catalogue rows said, with only the task name swapped:
keywords micro-task. Send {task, prompt}. Costs 0.01 USDC on Base, paid per call via x402 exact.
Each string is technically distinct. Each one is also useless. An agent choosing between keywords and extract sees a name, a price, and no product. My own earlier diagnosis had been "agents read the prose, not the schema" — and a template is the one case where that is guaranteed to fail.
The seven descriptions I had written properly were code_explain, code_review, extract, sentiment, summarize, translate, web_search. web_search said "return up to 5 result URLs (DuckDuckGo Lite)". That is a claim an agent can decide against. "keywords micro-task" is not.
The fix
One dict, 21 real entries, no route or price changes:
def _task_description(task: str) -> str:
return {
"hash": "Hash the input with a standard algorithm (SHA-256 by default) "
"and return the hex digest. Send {task:'hash', prompt:'text to hash'}.",
"json_minify": "Minify JSON: remove whitespace while preserving structure "
"and key order. Send {task:'json_minify', prompt:'{ \"a\": 1 }'}.",
"keywords": "Extract the most important keywords and phrases from a text, "
"ranked by relevance. Send {task:'keywords', prompt:'text'}.",
# ... 18 more
}.get(task, "%s micro-task. Send {task, prompt}." % task)
Then the boring part that actually matters: loop all 28 names through the live endpoint and assert zero of them still contain the template string. I wrote "28/28 descriptive, 0 template" only after that loop printed it.
The trap I hit while deploying it
Two systemd units were launching the same file. I patched, restarted one, saw active, and the public response was still the old string. The unit I restarted bound port 8080. The one nginx actually proxied to — port 8000 — was a different service.
is-active on the wrong unit is a false confirmation. Find the port owner first:
sudo ss -ltnp | grep ':8000'
What the traffic data said
I also checked who was actually calling the API. In the last 5000 requests:
- 2867 got HTTP 402 — a payment challenge
- 12 paid, total
The User-Agent breakdown explained the gap: PayAI-Bazaar, x402lens-indexer, BotsRated-probe (which literally says "unpaid check; no payment sent"), CarbonMonitor, BrickBlueBot. Indexers and monitors, not buyers.
And the "155 free test calls" I had been watching? 124 came from my own Sarajevo IP, from my own monitoring cron. I was measuring myself.
The rule I am keeping
A well-formed 402 with a wrong advertised resource is the pathological case. Envelope correctness is not index correctness. A catalogue row is a snapshot of the last paid call, not a directory of everything you declared — so if your last payer bought hash, that is all the catalog shows, no matter how many products you think you published.
Distinct is not descriptive. Descriptive is not distributed. I fixed the first one today; the other two are still on the list.
If you run a paid API, go read your own descriptions as if you had never seen the code. Count how many are a name and a price. Then decide whether you have a catalogue or just a template with 28 names.
來源:DEV Community · dev.to