> For the complete documentation index, see [llms.txt](https://docs.loomgate.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.loomgate.io/en/getting-started/api-keys.md).

# API keys and authentication

Secret key, publishable key, client secret and how to send them.

Loomgate uses three kinds of credentials:

| Type            | Format                     | Where to use it                  | Allows                                                                         |
| --------------- | -------------------------- | -------------------------------- | ------------------------------------------------------------------------------ |
| Secret key      | `sk_live_` + 32 characters | Your server only                 | All server routes: create, update and confirm payments, refunds, read balance… |
| Publishable key | `pk_live_` + 32 characters | The browser (safe to expose)     | Only the `/partner/v1/client/*` routes that `loomgate.js` calls                |
| Client secret   | `lg_cs_…`                  | The browser, for **one** payment | Show the card form and confirm that payment only                               |

Send the key in the `Authorization` header:

```http
Authorization: Bearer sk_live_…
```

## Create and revoke keys

In the merchant dashboard, [**API key**](https://app.loomgate.io/api-keys) section:

* **Create a new key pair**: each time you get one secret key and one publishable key. The secret key is shown exactly once; if you lose it, create a new pair.
* **Revoke**: a revoked key is rejected immediately with `api_key_revoked`. To rotate keys without downtime, create a new pair, deploy it to your server, and only then revoke the old pair.
* The key list shows only the last 4 characters of the secret key.

{% hint style="danger" %}
The secret key can create payments and refunds on your account. Never put it in browser code, mobile apps, source repositories or logs. If you suspect it has leaked, revoke it immediately.
{% endhint %}

## Client secret

Each payment has its own `client_secret`, returned only in the response that creates the payment (and when the same `Idempotency-Key` is sent again). Your server passes it to the browser of the right buyer; `loomgate.js` uses it together with your publishable key. The publishable key must belong to the same account as the payment, otherwise the API returns `payment_intent_not_found`.

## Authentication errors

| Error code              | HTTP | Meaning                                                  |
| ----------------------- | ---- | -------------------------------------------------------- |
| `invalid_api_key`       | 401  | Missing `Authorization` header, or the key doesn't exist |
| `api_key_revoked`       | 401  | The key has been revoked                                 |
| `invalid_client_secret` | 401  | `client_secret` is wrong or doesn't match the payment    |

Repeated failed authentication from one IP address is rate limited (see the rate limits section of the [API reference](/en/api-reference.md)).


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.loomgate.io/en/getting-started/api-keys.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
