跳到正文
DEV Community· Edward Izgorodin·· 50 分鐘前AI 評分61

如何測試 API 金鑰是否有效?

How can I test my API key?

AI 導讀

作者於 19 November 2026 測試六個託管記憶 API,無金鑰及假金鑰請求均回覆 401,當中兩者會回傳不同錯誤訊息。六個 API 使用四種標頭格式,包括 Authorization 中的 Bearer、Token、Api-Key,以及獨立的 X-Api-Key。若兩種測試回覆相同,401 不能證明金鑰已送達,應改用必須成功的請求(例如列出自己的資源)驗證。

正文

Cover image for How can I test my API key?

Edward Izgorodin

Send two requests before you trust it: one with no key at all, and one with a made-up key in the header the API documents. If the two answers differ, the API tells you whether a key reached it, and the answer to your real key means something. If the two answers are the same, a 401 cannot tell you whether your key arrived, and only a call that has to succeed proves the key works.

I sent exactly these two requests to six hosted memory APIs on 19 November 2026. Every request got a 401. Two APIs changed the message between the two requests, and four did not.

No key, then a made-up key, six memory APIs: Hindsight Cloud and Mnemoverse change the message, Letta Cloud, Mem0 Platform, Supermemory and Zep give the same answer both times

API (documented header) No key Made-up key in the documented header
Hindsight Cloud (Authorization: Bearer) "Authentication failed: API key required" "Authentication failed: Invalid API key format"
Mnemoverse (X-Api-Key) "Missing API key. Send X-Api-Key header." "This value does not have the shape of a Mnemoverse API key (mk_live_ followed by 32 lower-case hex characters)"
Letta Cloud (Authorization: Bearer) "Unauthorized" the same
Mem0 Platform (Authorization: Token) "Invalid API key. You can find your API key on https://app.mem0.ai/dashboard/api-keys." the same
Supermemory (Authorization: Bearer) "Unauthorized" the same
Zep (Authorization: Api-Key) "unauthorized" the same

Why a right key can still fail to arrive

An SDK sets the header for you. A proxy, a CI secret, a plain curl call or an MCP client configuration does not, and these six APIs alone use four ways to send a key: Bearer, Token and Api-Key in the Authorization header, and a separate X-Api-Key header. A key in a header the server does not read is, for the server, no key at all. At the four APIs that answer both requests the same way, that mistake looks exactly like a wrong key.

The two-minute check

URL=https://api.vendor.example/v1/some-endpoint
curl -s -w ' %{http_code}\n' "$URL"
curl -s -w ' %{http_code}\n' "$URL" -H "Authorization: Bearer not-a-real-key"
curl -s -w ' %{http_code}\n' "$URL" -H "Authorization: Bearer $KEY"

Put the header your vendor documents in the second and third lines. If the first two answers differ, the third one tells you what happened to your key: the "missing" message means the header was not read, the "invalid" message means the key arrived and was rejected, and a 200 means it works. If the first two answers are the same, a 401 on the third line proves nothing, so test the key with a request that has to succeed, such as listing your own resources.

Sources and method. The requests were sent on 19 November 2026 with curl from one machine, one at a time, with the made-up key probe-not-a-real-key-0000000000; the answers are quoted as the APIs returned them that day. The same requests on 17 November got the same answers. No accounts or keys were created. This article describes the APIs as of 19 November 2026.

I work on Mnemoverse; this comparison uses the same two requests for every API, Mnemoverse included.

來源:DEV Community · dev.to