Skip to content

Per-Person API Keys ​

When the agent calls an outside API, the call can be made with a key that belongs to the person who asked, rather than one shared account. The upstream then attributes the call to that person and limits it to what they may do.

You write a script that exchanges an admin credential for a key belonging to one person, and configure it per API domain:

json
"apiKeys": {
  "api.example.com": {
    "command": ["scripts/get_example_api_key.sh", "{principal.email}", "{thread.id}", "{interface}"],
    "env": { "API_KEY": "$BISHOP_ADMIN_API_KEY", "PATH": "/usr/bin:/bin" },
    "needs": "write"
  }
}

During a turn the agent calls get_api_key_path with a domain. Bishop runs that domain's script for the person the turn is for, writes the key to a file, and gives the agent the file's path. The agent reads the file in the command that uses it, like curl -H "Authorization: Bearer $(cat "$path")". The file is deleted before the turn ends.

Bishop keeps each key in memory, never on disk, for the person, domain and conversation it was issued for, so whatever the script checks before issuing a key is checked once per person and conversation. A later turn in the same conversation, for the same person and domain, gets a new file holding the kept key without running the script. Another person, or the same person in another conversation, runs the script. Kept keys are dropped when Bishop restarts, and a conversation's are all dropped when its permission level changes, which only happens in a Teams chat. Bishop doesn't know when a key expires. When the API rejects a kept key, the agent can ask for a new one with refresh, which runs the script and replaces the kept key. Each refresh is a request to whatever issues the keys.

The script ​

  • It prints the key on stdout and exits 0. Bishop removes every newline and trims the result, so the file holds the key and nothing else. A nonzero exit, empty output or running past timeoutSeconds fails the call. The agent is told Bishop couldn't get a key, and the script's stderr goes to Bishop's log.
  • It runs without a shell. command is an argument list. Each placeholder is replaced inside its argument as literal text, so an email address containing shell syntax stays one argument. An email address can start with -, so put placeholders after -- or inside a key=value argument, both in command and in anything the script passes them on to, where they can't be read as an option.
  • Its stderr is logged as written when it fails. Don't trace a credential to it with set -x or curl -v.
  • Its path is relative to Bishop's own directory, never the agent's. Keep it outside the agent's directory: it runs unconfined with the admin credential, so a script the agent can edit is one it can make print that credential. Startup warns when the script is inside the agent's directory or the temp directory.
  • Its environment is only env. $NAME copies NAME from Bishop's environment, including BISHOP_ variables, which is how the admin credential reaches the script and nothing else. Keep the admin credential in .env under a BISHOP_ name so the agent never gets it. PATH is /usr/local/bin:/usr/bin:/bin unless env sets it. Pass secrets in env, never in command, since anyone on the machine can read a running process's arguments.
  • Its working directory is Bishop's own directory.
  • A timeout stops the script but not what it started. Make the last command exec curl …, or give it its own timeout, so a slow upstream call doesn't outlive the script.
PlaceholderReplaced with
{principal.email}The email address of the person the turn is for.
{thread.id}Bishop's id for the conversation, like t_abc123.
{interface}slack, gmail or teams.

A key you issue can be scoped or audited per person and conversation with these.

When the agent gets no key ​

  • Nobody's email address is known. Slack gives Bishop email addresses only with the users:read.email scope.
  • The conversation's permission level is below needs. needs defaults to write.
  • The turn is a scheduled prompt or the agent's own follow-up, since those run as Bishop rather than as a person.
  • The turn answers messages from more than one person, which happens when people write while the agent is working. Bishop can't tell whose request the key is for.
  • The domain isn't configured. The refusal lists the ones that are.

The tool is offered only when at least one domain is configured.

What it protects and what it doesn't ​

The key is for the person Bishop verified sent the message, never for anyone the agent names. On email a sender is verified by heuristics, which is weaker than Slack or Teams.

apiKeys needs the sandbox on, and startup refuses it otherwise. Unconfined, the agent runs as the same user as Bishop, so it could read .env, edit the script, or read the key files of other people's conversations. Under the sandbox the admin credential never reaches the agent, and the agent can read its own turn's key file and can't change it.

The agent can still read the key and print it, which puts it in the transcript, and the key is in the arguments of any command the agent passes it to. Issue keys that expire quickly. When one does, the agent refreshes it.