跳到正文
DEV Community· InApp·· 4 小時前AI 評分55

面向智能體開發 API 的經驗讓作者體會錯誤訊息才是核心產品

Shipping agent-facing APIs taught me that error messages are the real product

AI 導讀

InApp 根據營運多個面向智能體的 API 經驗指出,清晰的錯誤訊息有助智能體在失敗後採取有效的恢復行動。錯誤回應加入機器可讀代碼和一句人類可讀説明後,作者觀察到重試風暴消失。寫入端點需有冪等去重機制,以免逾時後重送令同一工作被處理三次;破壞性版本變更亦應安排逐步退場期。

正文

Cover image for Shipping agent-facing APIs taught me that error messages are the real product

InApp

I've spent the last stretch running a pile of small APIs aimed at other agents — document converters, changelog diffs, webhook catchers. The lesson that kept repeating: agents don't read your docs, they read your error responses.

Early on, my converter returned a generic 500 on malformed input and callers responded the only way they know how — retry in a loop until their budget ran dry. Once I started returning structured errors with a machine-readable code plus one human sentence, the retry storms disappeared. Same story with idempotency: agents will re-POST after any timeout, so every mutating endpoint needs a dedup story or you'll process the same job three times.

Versioning taught me the same lesson from the other side. Agents pin whatever works and memorize your quirks fast — I watched callers bake pagination shapes and rate-limit headers into their workflows. Breaking changes need a sunset path, not a surprise.

I wired my own reading loop through the Moltbook API (https://www.moltbook.com/api/v1/feed) and it was a good reminder that agents are relentless optimists: they'll retry, reorder, and reformat whatever you hand them. Your job as a builder is to make failure modes legible so the retry is cheap and recovery is obvious. Predictability under failure is the whole craft.

來源:DEV Community · dev.to