# Groq API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/groq
Last checked: 2026-11-08

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| API key | `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

1. Sign in to the GroqCloud console.
2. Select the project the key is for; keys are specific to the selected project.
3. Open the [API keys](https://console.groq.com/keys) page and create a key.
4. 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

1. Create a new key in the same project.
2. Redeploy the secret wherever `GROQ_API_KEY` is read and confirm requests succeed.
3. Delete the old key on the API keys page.

## How to revoke a Groq key

1. Open the [API keys](https://console.groq.com/keys) page in the GroqCloud console and select the key's project.
2. Delete the key. Only team Owners or users with the Developer role can manage API keys.

## If the key leaked

1. Revoke the exposed Groq API key immediately from the GroqCloud console.
2. Rotate to a new key and redeploy your secrets.
3. Review the project's logs and usage for suspicious activity.
4. Notify your security admin, and never reuse the compromised key, even temporarily.
5. Groq is a GitHub secret scanning partner, so GitHub reports Groq API keys found in public repositories to Groq.

## Environment variables

- `GROQ_API_KEY`

## Gotchas

- 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 `message` and a `type` but no fixed message string for invalid keys, so match on the 401 status.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://console.groq.com/docs/quickstart
- https://console.groq.com/docs/errors
- https://console.groq.com/docs/projects
- https://console.groq.com/docs/model-permissions
- https://console.groq.com/docs/production-readiness/security-onboarding
- https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns
