Groq API keys are created in the GroqCloud console at console.groq.com/keys, and each Groq API key belongs to the project selected when it was made. Groq's SDKs and the AI SDK provider read GROQ_API_KEY, sent as Authorization: Bearer. Only team Owners and Developers can create or manage Groq API keys.
Groq key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| API key Groq's own examples show keys starting with gsk_; the docs do not specify the full format. | gsk_ | Yes | The project selected when the key was created, within that project's rate limits and model permissions | — |
How to create a Groq key
- Sign in to the GroqCloud console.
- Select the project the key is for; keys are specific to the selected project.
- Open the API keys page and create a key.
- Copy it and export it as
GROQ_API_KEY, or store it in a secret manager.
Limiting what the key can do
Groq API keys are scoped to a project, so use separate projects for separate apps or environments. Model permissions (an allow list or block list) restrict which models a project can call, under Settings → Projects → Limits, and the organization's Settings → Organization → Limits sets the ceiling. Project rate limits can be lower than the organization's but not higher. Project Readers have read-only access and cannot manage keys.
How to rotate a Groq key
- Create a new key in the same project.
- Redeploy the secret wherever
GROQ_API_KEYis read and confirm requests succeed. - Delete the old key on the API keys page.
Groq recommends rotating API keys periodically, for example quarterly. The old key works until it is deleted.
How to revoke a Groq key
- Open the API keys page in the GroqCloud console and select the key's project.
- Delete the key. Only team Owners or users with the Developer role can manage API keys.
If your Groq key leaked
- Revoke the exposed Groq API key immediately from the GroqCloud console.
- Rotate to a new key and redeploy your secrets.
- Review the project's logs and usage for suspicious activity.
- Notify your security admin, and never reuse the compromised key, even temporarily.
- Groq is a GitHub secret scanning partner, so GitHub reports Groq API keys found in public repositories to Groq.
Environment variables and CLI
Groq's SDKs and docs read the key from GROQ_API_KEY.
Things that catch people out
- Groq API keys are tied to the project selected when they were created, so check the project selector before creating or deleting keys.
- Model permissions apply to projects, not to individual keys; a 403 on one model can come from a project or organization block list.
- Groq's error responses carry a
messageand atypebut no fixed message string for invalid keys, so match on the 401 status.
Common Groq authentication errors
401 Unauthorized
The request was not successful because it lacks valid authentication credentials for the requested resource.
403 Forbidden
The request is not allowed due to permission restrictions, for example a model blocked by the project's or organization's model permissions.
Using your Groq key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Groq key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
store_secret | Saves a value the agent already holds as a new vault item. |
capture_secret | Planned, not built yet: will read a newly created key straight from the page or command output into the vault. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I get a Groq API key?
Create one at console.groq.com/keys in the GroqCloud console, after selecting the right project.
What environment variable does Groq use?
GROQ_API_KEY, which Groq's SDKs and the AI SDK provider read by default.
Why does my Groq API key return 401?
Groq returns 401 when the request lacks valid credentials; check that the key is sent as a bearer token and has not been deleted.
How often should I rotate a Groq API key?
Groq's security guidance suggests rotating periodically, for example quarterly, and revoking immediately if compromise is suspected.
Can I limit which models a Groq API key can use?
Yes, at the project level. Model permissions under Settings → Projects → Limits allow or block models for every key in that project.
Can an AI agent use my Groq key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.