# Keys and secrets

Two kinds of credential keep secrets out of your application code and out of
Nestor's records.

| You want to | Use |
| --- | --- |
| Let your application call an Endpoint | An **invocation key** |
| Give a run or container a credential, such as a Hugging Face token | A **Secret** |
| Manage resources from a script or CI | A service account **management key**; see the [CLI](/cli) |

## Invocation keys

An invocation key can call Endpoints and nothing else; every management request
made with it is refused. Give each application or environment its own key.

Create one in the Console under **Access**, preferably bound to a single
Endpoint. The value is shown once; store it in your backend's secret manager.
A signed-in person can also create one from the CLI or SDK:

```sh
nestor inference keys create --name checkout-service --endpoint endp_…
nestor inference keys list
nestor inference keys revoke ik_…
```

```python
key = client.inference.keys.create(name="checkout-service", endpoint="endp_…")
key.secret        # returned on this response only
```

- A key bound to an Endpoint can call only that Endpoint. An unbound key can
  call any Endpoint in the project.
- Nestor stores only a hash. Listing shows the prefix, state and last use, never
  the value.
- Revocation takes effect immediately and cannot be undone.
- Service accounts cannot create invocation keys; a person issues them.

To rotate a key, create a replacement, deploy it to your application, confirm
traffic uses it, then revoke the old one.

## Secrets

A Secret stores a credential that your workloads need, such as a Hugging Face
token or an API key for an evaluation. Nestor accepts the value once, encrypts
it and never returns it.

```sh
echo "$HF_TOKEN" | nestor secrets create --name hf
nestor secrets list
nestor secrets delete sec_…
```

Reference a Secret by ID:

- in a [training run](/training/runs) or [Run](/runs) with `--secret HF_TOKEN=sec_…`,
  which sets an environment variable for your program;
- in a [container Endpoint](/inference/containers) as a registry pull credential
  or a secret environment variable.

Secret values never appear in run documents, logs, events, Operations or audit
records. Values attached to a run are also removed from its logs if your program
prints them. A Secret in use by an Endpoint cannot be deleted; to rotate, create
a new Secret and update what uses it.
