Together AI API keys are created on a project's API keys page (api.together.ai/settings/projects/~current/api-keys), can be given an expiration date, and are shown only once. Send the key as Authorization: Bearer $TOGETHER_API_KEY; the Python and TypeScript SDKs read TOGETHER_API_KEY automatically. A revoked Together AI API key stops working within about five minutes and cannot be restored.
Together AI key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Project API key Together recommends project-scoped keys. They stay active if their creator leaves the project. | — | Yes | Full access to the project it was created in, including spending its credits | Optional; set a preset or custom date at creation, or later with **Set expiration** |
| Legacy key Marked Deprecated. Legacy keys cannot be regenerated or renamed; replace them with project keys. | — | Yes | The organization's default project | Cannot be given an expiration date |
| Vercel integration key Set as TOGETHER_API_KEY in Vercel. Disconnecting the Vercel project does not revoke the key. | — | Yes | The default project; one key per linked Vercel project | — |
How to create a Together AI key
- Sign in to Together AI and open the project the key is for.
- Go to the project's API keys settings.
- Select Create API Key, enter a descriptive name such as
prod-inference, and optionally choose Set an expiration date. - Select Create and copy the key immediately; it is not shown again.
- Export it as
TOGETHER_API_KEY.
Open Together AI's key settings
Limiting what the key can do
Together AI API keys are scoped to one project, and anyone holding a key has full access to that project. Use separate projects to separate environments, and set expiration dates on temporary or test keys. Project admins and editors can both create and revoke keys.
How to rotate a Together AI key
- Create a new project key, with an expiration date if it suits your rotation schedule.
- Move every application and secret store to the new key.
- Check the old key's Last used column until it stops receiving traffic.
- Open the old key's three-dot menu, select Revoke key, type
I understandand select Revoke.
The old and new Together AI API keys both work until the old one is revoked; revocation takes about five minutes. To replace a legacy key, create a project-scoped key, move applications to it, then revoke the legacy key.
How to revoke a Together AI key
- Open the project's API keys settings.
- Open the three-dot menu on the key's row and select Revoke key, or tick several keys and select Revoke N keys (up to 100 at once).
- Type
I understandand select Revoke. The dialog warns if the key was used in the past 24 hours. - The key stops working within about five minutes, and revocation cannot be undone.
If your Together AI key leaked
- Revoke the exposed Together AI API key from its row menu with Revoke key.
- Create a new project key and deploy it.
- Check the Last used column and the organization's billing for usage you do not recognise, since a key can spend the project's credits.
- Revoke any other keys that are unused, including legacy keys.
Environment variables and CLI
Together AI's SDKs and docs read the key from TOGETHER_API_KEY.
Together CLI (tg): tg login signs in through the browser and saves credentials to ~/.config/together/credentials.json; while logged in, the CLI ignores TOGETHER_API_KEY. tg whoami shows the project in use.
Things that catch people out
- New Together AI API keys are shown only once, so save the value when you create it.
- Revocation takes about five minutes to take effect, so a leaked key can still be used briefly.
- Disconnecting a Vercel integration does not revoke its key; revoke it on the API keys page.
- The Together CLI prefers a
tg loginsession overTOGETHER_API_KEY, so scripts and CI should pass the key explicitly.
Common Together AI authentication errors
401 - Authentication Error
The API key is missing or invalid.
402 - Payment Required
The organization's balance has reached its spend cut-off ($0 for prepaid accounts), or the model requires a positive credit balance.
403 - Forbidden
The account cannot access the requested model or feature, for example because of the plan, a missing payment method or disabled passthrough models. The error message names the reason.
Using your Together AI 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 Together AI 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 find my Together AI API key?
Create one on your project's API keys page at api.together.ai/settings/projects/~current/api-keys. Existing keys cannot be shown again.
Which environment variable does Together AI use?
TOGETHER_API_KEY, read automatically by the Python and TypeScript SDKs.
How do I revoke a Together AI API key?
Open the key's three-dot menu, select Revoke key, type I understand and confirm. It stops working within about five minutes.
Do Together AI API keys expire?
Only if you set an expiration date, at creation or later with Set expiration. Legacy keys cannot be given one.
Why does my Together AI API key return 401?
Together returns 401 when the API key is missing or invalid; check the key and the Authorization: Bearer header.
Can an AI agent use my Together AI 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.