> For the complete documentation index, see [llms.txt](https://docs.gitloom.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gitloom.cloud/api-reference/keys.md). Agents can also search and read this documentation through its [MCP server](https://docs.gitloom.cloud/~gitbook/mcp).

# Keys

API key lifecycle. Listing and revoking take a dashboard session; an account-wide key may create keys scoped to one namespace.

Listing and revoking keys take a **dashboard session**; an API key gets `403 dashboard_only`. Creating one depends on who asks:

| caller                   | asks for                                     | result               |
| ------------------------ | -------------------------------------------- | -------------------- |
| dashboard session        | an account-wide key, or one with `namespace` | `201`                |
| account-wide API key     | a key with `namespace`                       | `201`                |
| account-wide API key     | an account-wide key                          | `403 dashboard_only` |
| namespace-scoped API key | any key                                      | `403 scoped_key`     |

An account-wide key minting a scoped one is how a server issues a key for one of its users without anyone opening the dashboard. A **scoped** key reads and writes only its namespace: a request that leaves `namespace` out means that one, and one that names another is refused, with `403 forbidden_namespace` on a read and `400 invalid_namespace` on a write.

{% hint style="warning" %}
**A leaked account-wide key can mint scoped keys** — any number, for any namespace — and a key does not record which key created it, so those keep working after the leaked key is revoked. After revoking a leaked key, list the account's keys in the dashboard and revoke every scoped key created since the leak; `created_at` and `namespace` identify them.
{% endhint %}

#### POST /v1/keys

The response is the **only time the secret exists outside your process**. Only its hash is stored afterward.

| field       | type             | default                                                                                                   |
| ----------- | ---------------- | --------------------------------------------------------------------------------------------------------- |
| `name`      | string           | — your label, shown in listings                                                                           |
| `env`       | `live` \| `test` | `live`                                                                                                    |
| `namespace` | string           | — confines the key to this namespace; absent makes an account-wide key; required when the caller is a key |

{% tabs %}
{% tab title="Dashboard session" %}

```bash
curl -s -X POST "$GITLOOM_API/v1/keys" -H "Authorization: Bearer $ID_TOKEN" \
  -H "content-type: application/json" -d '{"name":"production backend","env":"live"}'
```

```json
{
  "id": "3f9a2b7c1d4e6f80", "env": "live", "name": "production backend",
  "key": "gl_live_3f9a2b7c1d4e6f80_kQ8vN2xR7mZpLd3Wc0Ty5Ub9Aj1Hs4Ge",
  "namespace": "",
  "note": "store this now; it cannot be retrieved again"
}
```

{% endtab %}

{% tab title="Account-wide API key, for one namespace" %}

```bash
curl -s -X POST "$GITLOOM_API/v1/keys" -H "Authorization: Bearer $GITLOOM_KEY" \
  -H "content-type: application/json" -d '{"name":"user-8213 desktop app","namespace":"user-8213"}'
```

The response is the same shape, with `"namespace": "user-8213"`.
{% endtab %}
{% endtabs %}

`400 invalid_env` if `env` is anything but `live`/`test`; `400 invalid_namespace` for a `namespace` that is not a valid name; `403 dashboard_only` or `403 scoped_key` as in the table above.

#### GET /v1/keys

Every key on the account, including revoked ones — kept, not deleted, so an audit log's key id stays resolvable. A scoped key carries its `namespace`. Secrets are never returned. Dashboard session only.

```json
{"keys":[
  {"id":"3f9a2b7c1d4e6f80","env":"live","name":"production backend","revoked":false,"created_at":"2026-07-14T09:31:02Z"},
  {"id":"9c4e1a07b2d35f68","env":"live","name":"user-8213 desktop app","namespace":"user-8213","revoked":false,"created_at":"2026-08-02T11:40:19Z"},
  {"id":"0a1b2c3d4e5f6071","env":"test","name":"laptop","revoked":true,"created_at":"2026-06-02T17:08:44Z"}
]}
```

#### DELETE /v1/keys/{id}

`id` is the key's public middle segment, never the secret. Dashboard session only.

```bash
curl -s -X DELETE "$GITLOOM_API/v1/keys/3f9a2b7c1d4e6f80" -H "Authorization: Bearer $ID_TOKEN"
```

```json
{"id": "3f9a2b7c1d4e6f80", "revoked": true}
```

{% hint style="warning" %}
**Not instantaneous.** Authorization results are cached at the gateway for 30 seconds, so a revoked key can keep working for up to half a minute.
{% endhint %}

Once it stops working, a revoked key gets the gateway's bare `403` with `{"message":"Forbidden"}`, not the error envelope — see the [Overview](https://docs.gitloom.cloud/api-reference/overview.md). Revoking a key does not revoke the scoped keys it created.

`404 not_found` for an unknown id, or one belonging to another account — deliberately indistinguishable.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gitloom.cloud/api-reference/keys.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
