My AI API returns "401 Invalid API key": why isn't my key accepted?
Missing API key when no key reaches it at all, and Invalid API key when the key it receives doesn't match any active key. The most common causes of the second are a key copied incompletely or a key that has been revoked. You can test whether a key works with a GET /v1/balance request without spending anything."Missing API key" versus "Invalid API key"
Wiozen looks for the key in the Authorization: Bearer sk-gw-… header first. If it isn't there, it checks the x-api-key, api-key and x-auth-token headers in that order. If none of them holds a key, the response is 401 Missing API key. If it finds a key but can't match it to any active key, the response is 401 Invalid API key.
The error body depends on the request format. On OpenAI-format endpoints:
{"error":{"message":"Invalid API key","type":"invalid_request_error"}}On the Anthropic-format /v1/messages endpoints the error type is authentication_error:
{"type":"error","error":{"type":"authentication_error","message":"Invalid API key"}}What to check when you get "Missing API key"
- The word Bearer. The
Authorizationheader's value must start withBearer. If you write only the key, asAuthorization: sk-gw-…, Wiozen doesn't read that header and the key is ignored. - An empty variable. If your code reads the key from an environment variable and that variable isn't set in the terminal running the program, the header goes out empty. You may have set it in another window or as another user.
- The header name. The accepted names are the four headers above. A different name, such as
X-Api-Token, isn't read.
If a tool reports the connection as successful but its real requests get this error, the reason is usually this: GET /v1/models returns the model list without a key. A tool that tests the connection with that endpoint gets the list even if it never sends the key. If a key is sent, the same endpoint does check it and returns 401 when it's wrong.
What to check when you get "Invalid API key"
- Is it the whole key? Wiozen keys start with
sk-gw-followed by a long string. The Prefix column on the Keys page shows only the first 12 characters; text copied from there isn't a key. - Was the key revoked or deleted? A revoked key stays on the list with the status "revoked"; a deleted key disappears from it. Neither works again.
- Is it the right service's key? Another AI service's key doesn't work on Wiozen, and a Wiozen key doesn't work elsewhere. Make sure the tool has both the address and the key set for the same service.
- Are two headers being sent? If both
Authorizationandx-api-keyare sent, Wiozen reads the key inAuthorization. If an old key is left there, the correct key in the other header is never tried. - Did a character get in? Spaces at the start and end of the key, and quotes around it, are cleaned off. A space or line break in the middle of the key isn't, and it breaks the key.
The quickest way to test a key is the balance request. It doesn't call a model and isn't charged; with a correct key it returns your balance, otherwise the same 401 message:
curl https://api.wiozen.com/v1/balance \ -H "Authorization: Bearer $API_KEY"
That endpoint is covered in the guide to checking your balance from code.
I lost my key. Can it be shown again?
No. The full key is shown once, when it's created. Wiozen stores a digest computed from the key, not the key itself, and the key can't be recovered from the digest. Support can't see your key either.
If you lost it, create a new key on the Keys page, put it into the tools you use, and revoke the old one. If you suspect someone else has the key, the order changes: revoke first, then check the spend. The steps are in the leaked key guide.
"API key was not accepted" in the WordPress plugin
Content Bot shows this warning when it gets a 401 from Wiozen, and the banner at the top of the panel says "Could not connect account". The most common cause is that the site's key was revoked or deleted on the Keys page; for example, while clearing out old WordPress: domain rows, the newest one the site was using may have gone too. In the banner, click Disconnect first, then the Connect account button that replaces it; the site connects again with a new key. Errors while connecting are in the connection errors guide, and how the warning appears in the panel is in the cannot-generate guide.
Errors that look like 401 but aren't
| Code and message | Meaning | What to do |
|---|---|---|
403 Account is not active | The key is fine, but the account is suspended | Write to us through support |
429 Quota exhausted | The key is fine, the balance isn't enough | Top up |
429 API key spend limit reached | The key is fine, its spend limit is reached | Raise or remove the limit on the Keys page |
In all three the key was accepted, so changing the key won't fix them. The other causes of 429 are in the 429 guide.
Frequently asked questions
What does "Missing API key" mean?
Authorization: Bearer, x-api-key, api-key, x-auth-token) holds a key. Usually the word Bearer is missing, or the variable holding the key is empty.What does "Invalid API key" mean?
How do I test my key without spending anything?
GET /v1/balance request with the key. It doesn't call a model and isn't charged; with a correct key it returns your balance.Can I get a lost key back?
Do I get a 401 when my balance runs out?
429 Quota exhausted. A 401 only comes when the key is missing or invalid.Create a new key on the Keys page and test it with the balance request above. Every error code is in the docs.
Create your accountMore guides: How can you use an AI API from Turkey without a credit card? · How do you connect an OpenAI-compatible API to a tool you already use? · How do you calculate the cost of an AI API? · What should I do if my AI API key has leaked? · How do you generate images with an AI API, and what does one image cost? · How much does a speech-to-text API cost, and how is it billed per minute? · Why does my AI API return a 429 error, and how do I fix it? · Why do long AI API requests time out: streaming or non-streaming? · Anthropic Messages API or OpenAI Chat Completions: which one should I use? · What is a context window, and what is a 1 million token context good for? · Which AI model should I choose: deciding by price, context and quality · Why does a reasoning model return an empty answer, and why are thinking tokens charged? · Why is my API balance running out faster than expected? Tracking spend request by request · How do you convert a web page to Markdown to feed it to an AI model? · How do you get AI to write and publish articles in WordPress automatically? · How do you find blog topics from RSS feeds and Google Trends? · Does AI-written content show up on Google and in AI answers? · How do you get internal links into AI-written WordPress articles? · How do you get AI to generate a different featured image for every WordPress post? · How do you write a content brief when an AI writes your blog posts? · What should you watch for when an AI writes recipes for your food blog? · How do you fix errors when connecting a WordPress plugin to your AI API account? · Why does my AI article bot stop halfway in WordPress? "Run is stuck" and LiteSpeed · Why are my scheduled WordPress posts late? WP-Cron and a real server cron · How do I get an AI article bot to write blog posts in English or another language? · What does "Content Bot cannot generate articles" mean? Reading the bot's log · If I delete the WordPress AI article plugin, are the articles it wrote deleted? · How do you do function calling (tool use) with an AI API? · How do I check my AI API balance from code and get a low-balance alert? · Can I use the same AI article plugin on several WordPress sites with one account and one balance? · How do you run Claude Code with a different API address and key? · Do AI-written WordPress posts get an FAQ section and FAQ structured data (schema)? · Is there a free trial for an AI API? How much credit Wiozen API gives and what it covers · Claude Haiku vs Claude Sonnet via API: price per million tokens and when to use each · How much does a Claude Code session cost with an API key? · Can you use Claude Code without a subscription and pay only for what you use? · How much does prompt caching cut API costs? Cache read and cache write prices · When is the DeepSeek API cheaper? Peak and off-peak hour pricing · Which model should you use in Cline, Cursor, OpenCode and Aider? · How much does an AI-written WordPress post cost? Text, image and research · Why didn't the AI bot publish its post, and why is it stuck in drafts? · How many AI-written posts a day should you publish, and how do you set the frequency? · Who should be the author of AI-written WordPress posts? · What to watch for when AI writes posts for a loan, crypto or energy website · An AI API returns "Unknown model": where do I find the right model name? · How do I add web search to my AI app, and what does a search cost?