GroqAiApiGroq API Key Not Working? A Step-by-Step Fix List
Groq API Key Not Working? A Step-by-Step Fix List
When a groq api key not working error shows up, the cause is nearly always one of six things: the wrong service, a wrong base URL, a malformed header, a replaced key, an empty balance, or a rate limit. This list tests them in order.

Summary
- Check which service issued the key first: a key only works on the service that created it.
- Test with curl before blaming your SDK, and print response headers with -i.
- 429 has two meanings here: rate_limited (requests per minute) and concurrency (too many at once).
- If you regenerated the key, the old one stopped working immediately.
Start with the service, not the code
Before you read a stack trace, confirm where the key came from. This site is a separate service from Groq. A key issued by Groq's console will not authenticate here, and a key from the key page on this site will not authenticate on Groq's endpoint. If you pasted a key into the wrong place, you can lose an hour on a problem that has nothing to do with your code.
If the key is from this site, the answers below apply to the endpoint https://api.groqaiapikey.com/v1 and the model name uncensored. The same order of checks works for any OpenAI-compatible API, so you can reuse the list elsewhere.
Run one curl call outside your app
A single curl call tells you whether the key, the URL and the account are healthy, without your SDK, framework or proxy in the way. Set the key in a shell variable first:
export API_KEY="paste-your-key-here" # used with model "uncensored"
curl -i https://api.groqaiapikey.com/v1/models \
-H "Authorization: Bearer $API_KEY"
The -i flag prints the status line and headers. A 200 and a model list mean the key and URL are fine, and the fault is in your application. Now test an actual completion:
curl -i https://api.groqaiapikey.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello."}]}'
Look at the response headers as well as the body. X-Request-Id identifies the call if you contact support, and X-Balance-USD shows your remaining credit.
Authentication errors
If curl returns an authentication failure (normally HTTP 401), the server did not accept the credential. Go through these in order:
- Header format. It must be
Authorization: Bearer YOUR_KEY, with the word Bearer, one space, then the key. Other header names do not work. - Hidden characters. A trailing newline or space copied with the key is the most common cause. In a shell, run
echo -n "$API_KEY" | wc -cand compare the count with the key's real length. - Quotes in .env files. Some loaders keep the quotes as part of the value. Print the variable in code and check the first and last characters.
- A replaced key. On the key page you can regenerate your key at any time, and the old one stops working at once. If a teammate or a script regenerated it, every client holding the old value fails together.
- A revoked key. Accounts that have topped up can hold up to 5 labelled keys and revoke any of them. Check the key page to see which are still active.
- An expired trial. The trial credit is valid for 7 days. After that, requests need a topped-up balance.
Wrong base URL: the quiet failure
A 404 or an HTML page in response to an API call points to the URL, not the key. Check:
- The base URL ends in
/v1, and the SDK appends/chat/completionsitself. If you put the full path in the base URL, the SDK appends it again and the path doubles. - No trailing typo such as
/v1/v1. - The host is
api.groqaiapikey.com, not the bare site domain, which serves web pages. - An environment variable is not overriding your code. The OpenAI SDKs read
OPENAI_BASE_URLandOPENAI_API_KEYwhen you do not pass values explicitly, and a stale value in your shell profile can win.
A quick way to see what the SDK actually uses:
from openai import OpenAI
client = OpenAI(base_url="https://api.groqaiapikey.com/v1", api_key="YOUR_API_KEY")
print(client.base_url)
print(client.models.list().data[0].id) # the model to request is "uncensored"429: read the error code before you retry
This API returns HTTP 429 in three situations, and the fix differs.
| Signal | Meaning | Fix |
|---|---|---|
Error code rate_limited | Too many requests in a minute (300 for a full key, 60 for a trial key) | Slow down, queue requests, back off |
Error code concurrency | Too many requests at once (8 for a full key, 2 for a trial key) | Cap parallel calls with a semaphore |
Retry-After: 5 header | Temporary overload | Wait 5 seconds, then retry |
The concurrency case surprises people who stream. A streamed request keeps its slot until the stream ends, so a client that opens many streams and reads them slowly can hit the cap without sending many requests per minute. Compare X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency in the response headers with what your code actually does.
import asyncio, os
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="https://api.groqaiapikey.com/v1", api_key=os.environ["API_KEY"])
gate = asyncio.Semaphore(2) # trial key: 2 at once; use 8 for a full key
async def ask(text):
async with gate:
r = await client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": text}],
)
return r.choices[0].message.contentSymptom to cause: a quick lookup
Use this table when you already know what the error looks like and want the likeliest cause first.
| What you see | Most likely cause | First thing to try |
|---|---|---|
| Authentication error on every call | Bad header, hidden whitespace, or a replaced key | Re-copy the key from the key page and rerun the curl test |
| 404 or an HTML page | Wrong base URL or doubled path | Print the base URL your client uses |
| Works once, then fails under load | Concurrency or requests-per-minute limit | Add a semaphore and backoff |
| Fails only on long inputs | Prompt plus answer over 100,000 tokens, or body over 8 MB | Trim or summarize history |
| Worked yesterday, fails today | Trial ended after 7 days, balance used up, or key regenerated | Read X-Balance-USD and check the key page |
| Model not found | Wrong model string | Use exactly uncensored |
A reusable health check
Keep a small script next to your project that you can run whenever something looks wrong. It tells you in one step whether the account, the key and the endpoint are healthy, before you start reading logs.
import os, sys
from openai import OpenAI, APIStatusError
client = OpenAI(base_url="https://api.groqaiapikey.com/v1", api_key=os.environ.get("API_KEY", ""))
try:
raw = client.chat.completions.with_raw_response.create(
model="uncensored",
messages=[{"role": "user", "content": "ping"}],
max_tokens=5,
)
print("ok, balance:", raw.headers.get("X-Balance-USD"))
except APIStatusError as e:
print("failed:", e.status_code, e.response.headers.get("X-Request-Id"), e.message)
sys.exit(1)
A healthy run prints the balance. A failure prints the status code and request ID, which is the pair to quote if you ask the team for help.
Balance, size and model name
If authentication passes and you still get failures, check the account itself. Read X-Balance-USD from any response, or call GET /v1/balance. A balance of zero means it is time to top up on the pricing page; failed or refused requests are not charged, so errors do not drain it.
Then check the request. The model ID must be exactly uncensored. The body must stay under 8 MB. The prompt plus the completion must fit in the 100,000-token context window, so a pasted book or a long chat history can fail even though the key is fine. Trim the history, or summarize older turns.
When it is still failing
If the curl test passes but your app fails, the difference is in your environment: a proxy that strips the Authorization header, a framework that logs and re-sends the request, or a serverless function that loads old environment variables from the last deploy. Redeploy after changing a key, and log only the last four characters of the key to confirm which one is loaded.
If the curl test fails with the right key and URL, send support the X-Request-Id value and the time of the call. Never post the key itself. If you suspect it leaked, regenerate it on the key page first. The production checklist covers how to store keys so this does not recur.
One more cause is the network between you and the API. Corporate proxies, school networks and some VPNs block unfamiliar hosts or rewrite headers. Run the same curl command from a phone hotspot or another network. If it works there, the key and the account are fine, and the fix belongs to whoever manages the first network.
More guides
Frequently asked questions
Why does my key work in curl but not in my app?
Something in the app changes the request: a stale environment variable, a proxy removing the Authorization header, or a base URL set to the wrong value. Print the base URL and the last four characters of the key your code actually uses.
Can I use a Groq console key with this API?
No. This is a separate service, and keys are only valid on the service that issued them. Get a key from the API key page on this site.
Does a 429 mean my key is broken?
No. It means a limit was reached. Read the error code: rate_limited means too many requests per minute, concurrency means too many at the same moment.
I regenerated my key. Why did everything stop?
Regenerating issues a new key and the old one stops working immediately. Update the value in every client, script and deployment that used it.
Obtain your API key
Register, retrieve the key, and update your base URL. That is all that is required for configuration.