On this page
Troubleshooting · Block 1 · Week 2 · Building APIs and the backend
When the request fails
Status code says whose fault. The message says what. Read both before you ask.
01The Errors You Should Expect
401Invalid API Key
key
CauseKey missing, mistyped, a space copied with it, or Bearer missing.
The header is Authorization: Bearer <key>. Check the environment variable is set in the same terminal that runs the app.
KeyError: 'GROQ_API_KEY'
key
CauseThe variable is not set in this terminal. export vanishes when the terminal closes.
Set it again before python app.py.
404The model does not exist or you do not have access to it
package, the model field
A typo, or a retired model. Groq's own quickstart still ships llama-3.3-70b-versatile.
Use openai/gpt-oss-20b. One word, read straight from the error.
404Not found: wrong address
address
CauseThe domain alone, or a typo in the path. api.groq.com on its own is not an endpoint.
https://api.groq.com/openai/v1/chat/completions
400Bad request
package
CauseA missing field or the wrong shape for messages.
Compare your json= with the package on the practice set.
429Too many requests
More than 30 requests in a minute on your Groq account.
FixWait a minute. You will not need more.
KeyError: 'choices'
The request failed, so the reply has error instead of choices.
Print r.status_code and r.json() first, then find the code above.
ModuleNotFoundError: No module named 'requests'
pip install requests
NameError: name 'gr' is not defined
Gradio was never imported.
FixAdd import gradio as gr at the top.
5xxServer error
Their machine, not yours.
FixTry again later.
02Still Stuck
Write down the status code, the exact message and what you tried, key masked. Writing it out often shows you the fix; if it does not, you now have a precise search query. More: The second interface troubleshooting · Keys.