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

# API keys

API keys authenticate your backend against Mailofly's REST API. Each key is tied to your **organization** and inherits the creator's permissions.

**In the app:** [API keys](https://www.mailofly.com/user/api-keys)

***

## Key format

```
mf_live_1rSFBs2KtL_ZwCO8_qzl4wmjypHGhSAJ
└──────┘ └──────────────────────────────┘
 prefix          secret body
```

* Prefix **`mf_live_`** makes keys easy to spot in config files
* Full secret shown **once** at creation — stored as SHA-256 hash server-side
* Optional **expiry date** for temporary access
* **Last used** timestamp updated on each authenticated request

***

## Create & manage

1. Open [**API keys**](https://www.mailofly.com/user/api-keys)
2. **Create key** → name it (e.g. "Production CRM sync")
3. Copy the secret to your password manager or `.env`
4. Monitor usage at [**API usage**](https://www.mailofly.com/user/api-usage)

### Rotate a key

1. Create a new key
2. Update your services with the new secret
3. Delete the old key once traffic confirms the switch

***

## Authentication

```http
Authorization: Bearer mf_live_your_secret_here
```

Every API route (except `GET /api/v1` discovery) requires this header.

Requests are scoped to your organization automatically — never pass org IDs in the body.

***

## Request logging

Each call logs to `api_key_request_logs`:

| Logged        | Purpose                 |
| ------------- | ----------------------- |
| Method + path | Usage analytics         |
| Timestamp     | Audit trail             |
| Key ID        | Per-key usage breakdown |

Counts against your plan's `max_api_requests_per_month`.

***

## Security model

| Property   | Detail                                      |
| ---------- | ------------------------------------------- |
| Scope      | Organization-wide                           |
| Role       | Inherits creator's role (admin recommended) |
| Storage    | Hash only — plaintext never persisted       |
| Revocation | Instant on delete                           |

{% hint style="danger" %}
Never expose API keys in client-side JavaScript, mobile apps, or public repos. Keys belong on your server only.
{% endhint %}

***

## vs Supabase / database keys

Direct database access bypasses Mailofly's business rules — quotas, campaign logic, and plan limits. Always use Mailofly API keys so enforcement stays consistent.

***

## Related

* [API overview](https://docs.mailofly.com/api) — full endpoint reference
* [Getting started → API keys](https://docs.mailofly.com/getting-started/api-keys)
* [Compose API](https://docs.mailofly.com/api/compose) — send with `account_key`


---

# 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.mailofly.com/guides/operations/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.
