Why does my Unlid API key return 401 invalid_api_key?
The key the request carried is missing, mistyped, revoked, or the request did not go to Unlid at all. Unlid keys start with ul- and are sent as Authorization: Bearer ul-…; if the error says "Incorrect API key provided … platform.openai.com", your app sent the key to OpenAI because its base URL is not set to Unlid.
Check, in this order
- Base URL. It must be
https://api.unlid.ai/v1, with nothing after/v1(Claude Code takeshttps://api.unlid.aiwithout/v1). An error that mentions platform.openai.com came from OpenAI, not from Unlid. - The key itself. Copy it again without spaces or line breaks. The full key is shown only once, when it is created; the account page shows just its prefix. If you lost it, create a new one.
- Revoked or regenerated. A key that worked minutes ago and now fails was usually revoked or replaced on the account page. Update every app that uses it.
- Header. OpenAI-style requests send
Authorization: Bearer ul-…; Anthropic-style requests may sendx-api-key: ul-….
Test the key on its own
curl https://api.unlid.ai/v1/models -H "Authorization: Bearer ul-…"
If this returns the model list, the key works and the problem is in the app's settings: see its page under Apps & clients. A 401 is never charged.
Not the same as
403 means the key works but is not allowed this model or the account is restricted; 402 means the balance cannot cover the request (402 answer).
Related questions
- Why do I get ECONNRESET or "Connection reset by server" with the Unlid API?
- What does upstream_billing_error ("the upstream provider refused the request for an account reason") mean?
Something not covered? Ask in the support chat at the bottom right, or see the FAQ and the API docs.