---
title: API Key
icon: code
description: Set up, configure, and run the Reloop API key microservice locally.
---
> For the complete documentation index, see [llms-docs.txt](/llms-docs.txt) or the site index [llms.txt](/llms.txt). Full docs corpus: [llms-full-docs.txt](/llms-full-docs.txt). Prefer markdown URLs (append `.md`) for agent consumption. Product skill: [skill.md](/skill.md).


Generation, hashing, validation, and revocation of developer API keys.

<Tip>
Run [`bun setup`](/docs/setup) once from the monorepo root. Env files come from `bun setup` / `bun env:setup`.
</Tip>


## Overview

| Property | Value |
| :--- | :--- |
| **Directory** | `apps/backend/api-key` |
| **Port** | `8012` |
| **Local URL** | [https://local.reloop.sh/api/api-key](https://local.reloop.sh/api/api-key) |
| **Swagger UI** | [https://local.reloop.sh/api/api-key/openapi](https://local.reloop.sh/api/api-key/openapi) |
| **Stack** | ElysiaJS · Better Auth API Key · PostgreSQL · Redis · NATS |


## Quick start

```bash
bun be:api-key:dev
```

Or `bun backend:dev` / `bun dev`.


## Environment

`apps/backend/api-key/.env` — from `bun setup` / `bun env:setup`.

```bash
PG_URL=postgresql://reloop:reloop123@localhost:5432/reloop
REDIS_URL=redis://:reloop123@localhost:6379
PORT=8012
BASE_URL="https://local.reloop.sh"
NATS_URL=nats://localhost:4222
NODE_ENV=development
```

| Variable | Required | Default |
| :--- | :--- | :--- |
| `PG_URL` | **YES** | `postgresql://...` |
| `REDIS_URL` | **YES** | `redis://...` |
| `PORT` | **YES** | `8012` |
| `BASE_URL` | **YES** | `https://local.reloop.sh` |
| `NATS_URL` | **YES** | `nats://localhost:4222` |


## Commands

| Command | Description |
| :--- | :--- |
| `bun be:api-key:dev` | Start dev server with hot reloading |
| `bun run --filter=be-api-key build` | Compile production bundle |
| `bun run --filter=be-api-key start` | Run compiled production build |
| `bun run --filter=be-api-key check-types` | TypeScript type-check |


## Architecture

| Layer | Detail |
| :--- | :--- |
| **Auth** | `@better-auth/api-key` handles SHA-256 hashing and key formatting |
| **Caching** | Validated keys are cached in Redis for fast lookups |
| **Events** | Key lifecycle events published to NATS under `api-key.*` |
| **Schema** | `apikey` table in `packages/db/src/schema/api-key.ts` |


## Next

<CardGroup cols={2}>
  <Card icon="rocket" title="Setup" href="/setup">
    One-command local bootstrap
  </Card>
  <Card icon="globe" title="Port reference" href="/setup/port">
    Gateway routes and ports
  </Card>
  <Card icon="lock" title="Auth" href="/setup/backend/auth">
    Sessions and organizations
  </Card>
  <Card icon="mail-single" title="Mail" href="/setup/backend/mail">
    API that validates keys on send
  </Card>
</CardGroup>
