Resources

Incident response

What to do if you pasted an API key into chat

If you pasted an API key into ChatGPT, Claude, Cursor, Codex, or another AI chat, treat it as exposed, revoke or rotate it, and move future agent access to scoped runtime resolution.

Answer target

What should you do if you pasted an API key into chat?

Updated June 24, 2026

Short answer

Treat the API key as exposed. Revoke or rotate it at the provider, replace it in the systems that legitimately need it, check where else it may have been copied, and avoid pasting the replacement key into the same chat or workflow.

What to do now

Assume the pasted key can be read by systems or people beyond the original task. The fastest safe response is to remove the old key from service and replace it through the provider's normal rotation flow.

  • Revoke or rotate the key at the provider.
  • Create a replacement key with the narrowest scope that still works.
  • Update the legitimate runtime or app that needs the key.
  • Search repos, shell history, logs, tickets, and local files for extra copies.
  • Record what changed so the next review does not depend on memory.

Better pattern

For the next task, store the provider key in a credential layer and let the agent resolve only the named secret it has been granted. The chat can contain setup instructions, but not the raw provider key.

Avoid

Do not paste the replacement key into the same chat, create a broader key to save time, reuse a compromised key, or leave old .env files and terminal variables in place after rotation.

Example

If a coding agent needs a Stripe test key to debug a billing issue, rotate the pasted key, store the replacement once, grant the agent access to that one Stripe secret, and let the agent resolve it at runtime.

Why the key should be rotated

A pasted key may live in chat history, screenshots, model context, tool transcripts, browser history, logs, or another system connected to the conversation. Even if the paste was accidental and no misuse is visible, the safest assumption is that the key is no longer clean.

Replace it without widening access

Rotation is not just a new string. Check what the key can do, create the replacement with the least privilege available, and update only the systems that should use it. If the provider supports separate test and production keys, keep those separated.

Change the future workflow

The same incident will repeat if the new key is copied into another chat or .env file. A safer workflow gives the agent a scoped identity, grants it the specific secret, and records each resolve without displaying the raw key in chat.

Practical workflow

  1. 1ContainStop using the pasted key and revoke or rotate it in the provider dashboard or API.
  2. 2ReplaceCreate a scoped replacement and update the app, CI job, local runtime, or agent workflow that genuinely needs it.
  3. 3Clean upRemove accidental copies from local files, shell variables, command history, tickets, and documentation.
  4. 4Prevent repeat exposureMove future AI-agent access to scoped runtime resolution instead of pasted raw keys.

After pasting a key vs Safer next workflow

TopicAfter pasting a keySafer next workflow
Immediate actionTreat the key as exposed and rotate it.Keep raw keys out of chat before the task starts.
Agent accessThe agent may have seen a broad provider credential.The agent resolves only a directly granted secret.
ReviewYou have to reconstruct what happened from chat and logs.Grant, reveal, resolve, revoke, and rotation events are recorded.

Frequently asked questions

Do I need to revoke an API key after pasting it into an LLM?

If the key can access a real system or real data, yes. Treat it as exposed and revoke or rotate it rather than trying to prove it was not copied.

Can I just delete the message that contains the key?

Deleting a visible message is not enough. The key may already exist in logs, browser state, model context, or connected tool output, so rotation is still the safer response.

How do I avoid this next time?

Store the key centrally, grant it to a named agent or member, and let the workflow resolve the credential at runtime instead of putting the raw value into chat.

Where ScopeHold fits

ScopeHold gives teams a recovery path and a better default: store the provider key once, grant access to named members and agents, resolve credentials at runtime, and audit the event.

Sources and reference notes