# How to stop pasting API keys into AI chats

> Store the key once in a vault and let the agent fetch it by name at run time, so the value never appears in a chat transcript.

Store the key once in a Guardry vault and give the agent its own credential. The agent then fetches the key by name when it runs a command, and the value goes into the program's environment instead of the conversation. Any key you have already pasted should be revoked at its provider and replaced.

## Why a pasted key is a problem

A key pasted into a chat is part of that conversation from then on. It stays in the transcript and in whatever stores or logs the conversation. You cannot take it back, and nothing tells you where it went.

The fix is to give the agent the name of the key, not the value. The agent gets the value from the vault when a program needs it.

## 1. Store the key in the vault

[Request an invite](https://guardry.ai/invite/) and add the key as a secret in the environment where it is used, under a name such as `STRIPE_KEY`. Add a description too, because agents can search names and descriptions without reading any value.

## 2. Create a credential for the agent

Under Agent access, create an agent credential with a scope, the permission to read secret values, and a lifetime of 1 hour, 4 hours, 7 days or 30 days. The credential is shown once.

## 3. Sign in at a hidden prompt

The agent credential does not go into the chat either. Run the login yourself in a terminal and paste the credential at the hidden prompt.

```sh
# Paste the agent credential at the hidden prompt
guardry login --profile coding-agent
guardry --profile coding-agent whoami
```

## 4. Let the agent fetch the key by name

In the chat, give the agent the profile and the name of the key, never the value.

```sh
# Find the entry by name or description, without reading any value
guardry --profile coding-agent secrets list --search "billing sandbox" --json

# Run the program with the values in its environment; nothing is written to disk
guardry --profile coding-agent secrets run --secret API_KEY --secret DATABASE_URL -- python agent.py
```

## 5. Replace the keys you already pasted

Treat every key that has been in a chat as exposed. Revoke it at its provider, create a new one there, and save the new value in the vault. Guardry cannot remove a key from an old transcript, and it does not rotate keys at the provider.

## What this does not do

- An agent that can read a secret can copy it, so it can still print a value it was allowed to read. Guardry controls who gets a value and records every release, not what a program does with it afterwards.
- Guardry does not scan for leaks. An agent that notices it exposed a value can report the leak without repeating the value, as described in [An AI agent leaked an API key](https://guardry.ai/guides/ai-agent-leaked-api-key.md).

## Questions

### Is it safe to paste an API key into an AI chat?

Treat a pasted key as exposed. It becomes part of the transcript, and you cannot control where that transcript is stored or logged. Store the key in a vault and give the agent its name instead.

### I already pasted an API key into a chat. What should I do?

Revoke the key at its provider and create a new one. Deleting the message is not enough, because the old key keeps working until the provider revokes it. Save the new key in your vault.

### How does the agent get the key if I never paste it?

The agent runs the `guardry` CLI with its own agent credential, which you paste once at a hidden prompt and never into the chat. `guardry secrets run` puts the named secrets into the environment of the program it starts. Each release is written to the audit log before the value leaves the vault.

---

Source: https://guardry.ai/guides/stop-pasting-api-keys-into-ai-chats/ · Updated 2026-11-27 · Guardry for language models: https://guardry.ai/llms.txt
