Cohere API Key Rotation: Zero-Downtime Rotation and the Leaked-Key Runbook
How to replace a Cohere credential without dropping a request, what to do in the first ten minutes after one leaks, and why a stolen key usually shows up as a rate-limit anomaly rather than an authentication error.
📡 Monitor your APIs — know when they go down before your users do
Better Stack checks uptime every 30 seconds with instant Slack, email & SMS alerts. Free tier available.
Affiliate link — we may earn a commission at no extra cost to you
Getting your first Cohere key working is a five-minute job, and there is asetup guidefor it. This page is about the part nobody writes down: the credential you already have is a liability with an age, and at some point it has to be replaced — on a schedule, when someone leaves, or at 2am because it turned up in a public repository.
Almost every painful key rotation fails for the same structural reason: the team treats it as editing a secret rather than running two credentials in parallel. Editing in place guarantees a window where the deployed configuration and the set of valid keys disagree, and the length of that window is however long your slowest deploy target takes to pick up the change. Overlap eliminates the window entirely.
If your key is leaking right now: issue a replacement first, deploy it, then revoke the old one — unless you can see active abuse, in which case revoke immediately and take the outage. Jump to the leaked-key runbook. If instead you are seeing errors and are not sure whose fault they are, checklive Cohere status first.
Rotation Is a Four-Phase Overlap, Not an Edit
The whole technique is that two Cohere keys are valid at the same time for as long as it takes every consumer to move. Nothing clever happens in any individual step; the safety comes entirely from the order.
| Phase | Action | Done when |
|---|---|---|
| 1. Inventory | List every place the current key is stored — secret manager, CI variables, serverless config, container env, local .env files, and any third-party tool you pasted it into. | The list is written down, not remembered. This is the phase teams skip and the reason rotations half-complete. |
| 2. Issue | Create a second key in the Cohere dashboard, named for its purpose and creation date rather than key2. | Both keys return 200 on a test call. Neither has been revoked. |
| 3. Cut over | Update every location from the inventory, redeploy, and restart anything that reads the credential once at boot. | A real API call from each environment succeeds and the old key shows zero usage in the dashboard. |
| 4. Revoke | Delete the old key. Not disable-and-forget — delete, so it cannot be re-enabled by someone tidying up later. | A deliberate call with the old key returns 401 and nothing in production notices. |
Phase 3 is where the discipline lives. "I updated the secret" is not evidence; zero usage on the old key is. A long-running process that read COHERE_API_KEY at startup will happily keep using the old credential for days after the secret store was updated, and you will discover this at the exact moment you revoke.
Keep Provider Keys Somewhere You Can Actually Rotate Them
Overlapping rotation only works if you know every location a credential lives in. A managed secret store gives you one authoritative copy and an audit trail, instead of a key copied into six env files and one Slack thread.
Try 1Password Free →The Cohere-Specific Trap: Trial Keys and Two Client Paths
Cohere issues more than one kind of key, and they are not interchangeable in production. A trial key is free, heavily rate limited, and intended for evaluation; a production key is the one that carries real throughput. The failure mode is not that a trial key stops working — it is that it keeps working, just slowly and with a low ceiling, so a service that shipped with a trial key looks healthy in staging and then throttles under real load. Rotation is the natural moment to catch this: when you enumerate your credentials, record the key type next to each one, and treat any trial key found in a production environment as a finding rather than a footnote.
The second trap is structural. Cohere's surface spans distinct capabilities — generation, embeddings, and rerank — and retrieval stacks commonly construct separate clients for them, often in different modules written by different people at different times. Rotate the key in the chat client, redeploy, watch the dashboard go green, and the rerank client can still be holding the old credential from a config path nobody remembered.
The defence is the same single-construction-point rule that solves it everywhere else, applied per-provider: one module builds every Cohere client, reads the credential once, and every capability imports from there. Until that refactor lands, your rotation checklist needs an explicit line per capability, and the verification step has to exercise a real call on each — an embeddings call and a rerank call, not just a chat completion.
Reading the Credential So Rotation Is a Config Change
A rotation is only as fast as the slowest consumer, and the slowest consumer is always the one that read the key once, at import time, into a module-level constant. Build every Cohere client from one place, read the credential at call time, and a rotation becomes a config change rather than a redeploy.
// ONE module constructs every Cohere client for the whole codebase.
// Nothing else in the repo reads COHERE_API_KEY directly.
function credential() {
// Read at call time, not at import time — a process that has been
// running for a week must be able to pick up a rotated key.
const key = process.env.COHERE_API_KEY;
if (!key) throw new Error('COHERE_API_KEY is not set');
return key;
}
export async function callCohere(path, body) {
const res = await fetch(`https://api.cohere.com/v2${path}`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${credential()}`,
'Content-Type': 'application/json',
// Tag every request with which key issued it. During a rotation
// this is how you prove the old credential has actually drained.
'X-Key-Id': process.env.COHERE_API_KEY_ID ?? 'unlabelled',
},
body: JSON.stringify(body),
});
// 401 is fatal. Retrying it during a revocation turns a clean
// cutover into a retry storm against a dead credential.
if (res.status === 401) {
throw new Error('Cohere: credential rejected — rotated or revoked, do not retry');
}
return res;
}The X-Key-Id line is the cheap trick worth stealing. Emit the key identifier — never the key itself — into your own logs, and phase 3 stops being a guess: you can watch traffic on the old identifier fall to zero across every service before you revoke anything.
The Leaked-Key Runbook: First Ten Minutes
A leaked Cohere key is not primarily a security incident with a fixed cost. It is a metered credential that somebody else is now spending, and every minute of deliberation has a price. Work the list in order.
- Decide whether to revoke first or rotate first. Visible abuse — usage you cannot attribute, a spend curve that is not yours — means revoke now and accept the outage. No evidence of abuse means rotate first and revoke a few minutes later with no downtime at all.
- Issue the replacement in the Cohere dashboard and push it through the same four-phase overlap. Do not shortcut the inventory step just because you are in a hurry; a half-rotated stack under incident pressure is how a ten-minute problem becomes a two-day one.
- Delete the exposed key once traffic on it is zero. Delete rather than disable.
- Pull the usage record for the entire window the key was exposed — not since you noticed. The exposure started when the secret was written, not when it was found.
- Purge the secret from history. A key committed to git is still in the reflog, in forks, in CI caches, and in any build log that echoed the environment. Rewriting the commit is not sufficient on its own, which is precisely why revocation comes first.
- Close the process gap. Ask how a credential reached a location your secret store does not control, and fix that. A rotation that does not end in a changed process is a rotation you will be repeating.
Do not skip step 4. The instinct after revoking is relief, and the forensic step gets dropped. But the usage record is the only thing that tells you whether this was a scraped key nobody used or a credential that has been quietly funding somebody else's product for three weeks — and those two incidents have very different disclosure obligations.
How a Compromised Key Actually Presents
This is the part that makes credential incidents hard to spot: almost none of the symptoms look like a security event. Five of the six rows below return a perfectly ordinary HTTP status.
| What you see | What it looks like | What it may actually be |
|---|---|---|
| 429s on a workload whose volume did not change | Capacity problem — "we need a limit increase" | Someone else consuming your quota on your key |
| Spend up, product metrics flat | A regression in prompt length or retry behaviour | Unauthorised traffic on a shared credential |
| Usage on a model your app never calls | A stale experiment somebody forgot | A third party using your key for their own workload |
| A flat overnight usage plateau | A scheduled batch job | Automated abuse with no diurnal curve |
| Latency up across the board | A Cohere-side incident | Your own account queued behind borrowed traffic |
| 401 in one service only | A deploy problem | A half-finished rotation — the real one, and the only row here that is loud |
The through-line: with a single shared key, every one of these is indistinguishable from an ordinary engineering problem, and teams reliably spend days debugging the wrong layer. Split keys per workload and the same anomalies become attributable in the first hour, because the usage that does not belong is sitting on a credential with a name.
Alert on Usage Shape, Not Just Errors
A compromised key mostly returns 200s. Continuous monitoring of request volume, latency and status-code distribution on your Cohere endpoint turns an invisible spend anomaly into a page.
Try Better Stack Free →A Rotation Schedule Worth Actually Keeping
- Every 90 days for production credentials, calendared, with an owner. An unowned schedule is a decoration.
- On offboarding, for every key the departing person could read — which, if you have a shared secret store, is a bigger list than the one they personally created.
- On exposure, immediately — including "probably fine" exposure like a screenshot, a support ticket, a pasted log, or a shared no-code workflow. Probability is not a control.
- Before an audit or a security questionnaire, because the first question is always the age of the credential and the second is when you last practised the procedure.
- After any incident in which the key was read out of a running environment by a human, even a trusted one.
One more discipline that costs nothing: rotate on a boring Tuesday when nothing is on fire. A rotation procedure that has only ever been executed during an incident is a procedure you are testing in production at the worst possible moment.
Where to Send Traffic If a Revocation Goes Wrong
A botched rotation is an outage you caused, and it deserves the same fallback path as one the provider caused. Each of these runs on separate infrastructure and a separate credential, so a Cohere key problem does not follow you there.
Groq
Separate credential, separate console, separate rotation schedule. Rotating one never rotates the other.
Check Groq status →Mistral
Separate credential, separate console, separate rotation schedule. Rotating one never rotates the other.
Check Mistral status →OpenAI
Separate credential, separate console, separate rotation schedule. Rotating one never rotates the other.
Check OpenAI status →Choosing a destination is its own problem — see thefallback ranking guidefor how to decide whether the answer you get back is worth the same, and thefailover guidefor the cutover mechanics.
Frequently Asked Questions
How do I rotate a Cohere API key without downtime?
Never rotate by editing one secret in place. Issue a second Cohere key alongside the first, deploy it to every consumer, verify with a real API call from each environment that the new key is the one being used, and only then revoke the old key. The overlap window — two valid keys at once — is what makes the rotation safe, because at no point is there a moment where the deployed configuration and the valid credentials disagree.
How often should I rotate Cohere API keys?
On a fixed schedule of 90 days for production credentials, and immediately on three triggers: anyone with access to the key leaves the team, the key was pasted anywhere outside your secret store, or you see usage you cannot attribute. The schedule matters less than the fact that the procedure is practised — a rotation runbook that has never been executed will not work the first time you need it under pressure.
My Cohere API key leaked. What do I do first?
Issue a replacement key first, then revoke the exposed one — in that order, unless you have evidence of active abuse, in which case revoke immediately and accept the outage. Rotating before revoking keeps your service up. After the credential is dead, the work is forensic: check usage for the period the key was exposed, purge it from git history and any build logs or screenshots, and find the process gap that let a secret reach a place your secret store does not control.
How do I tell whether someone else is using my Cohere key?
Look for usage whose shape does not match your product. Unauthorised traffic on a stolen key typically has no diurnal curve, targets models your application does not call, or originates during hours your users are asleep. This is why per-key, per-workload credentials matter: with one shared key every request looks the same, and with keys split per service the anomaly is visible in the first hour.
Will revoking a Cohere key break requests that are already in flight?
Assume yes. Revocation takes effect at the edge and an in-flight request can fail with a 401 mid-stream, which client code often surfaces as a truncated response rather than an authentication error. Revoke during a low-traffic window where you can, drain long-running work first, and make sure your error handling classifies 401 as fatal and non-retryable so a revocation does not turn into a retry storm.
Related Cohere Guides
Know Within Minutes If a Rotation Broke Something
API Status Check monitors Cohere and every other provider in your stack continuously, so a revoked key, a missed consumer and a genuine Cohere incident never look the same again.
Start Your Free Trial →Alert Pro
14-day free trialStop checking — get alerted instantly
Next time Cohere goes down, you'll know in under 60 seconds — not when your users start complaining.
- Email alerts for Cohere + 9 more APIs
- $0 charged today — card required to start
- Cancel anytime — $9/mo after trial
🌐 Can't Access Cohere?
If Cohere is working for others but not for you, it might be an ISP or regional issue. A VPN can help bypass network-level blocks and routing problems.
Troubleshoot with a VPN
Connect from a different region to test if the issue is local to your network. Also protects your connection on public Wi-Fi.
Try NordVPN — 30-Day Money-Back GuaranteeSecure Your Cohere Account
Service outages are a common time for phishing attacks. Use a password manager to keep unique, strong passwords for every account.
Try NordPass — Free Password Manager🛠 Tools We Use & Recommend
Tested across our own infrastructure monitoring 200+ APIs daily
SEO & Site Performance Monitoring
Used by 10M+ marketers
Track your site health, uptime, search rankings, and competitor movements from one dashboard.
“We use SEMrush to track how our API status pages rank and catch site health issues early.”