# Create an API key

> Step by step: create an Ur Next Door API key in Settings > API keys on the website or in the app, copy it once, and store it in UND_API_KEY.

Source: https://docs.urnextdoor.com/getting-started/create-api-key/

You create API keys yourself, in your account settings, on the website or in the app. This page walks through both, then shows how to store the key so tools can use it without it ever appearing in your code.

## Before you start

- You need an active Ur Next Door account. Any plan works, including Free.
- You can hold up to **5 active keys** at a time. Revoked and expired keys do not count toward the 5.
- Decide which tool will use the key. Create one key per tool (for example one for Claude Code and one for Zapier), so you can revoke one without breaking the others.

## Create a key on the website

1. Sign in at [urnextdoor.com](https://urnextdoor.com).
2. Open **Settings**, then the **API keys** tab. The direct address is `https://urnextdoor.com/settings/api-keys`.
3. Select **Create API key** and fill in the dialog:
   - **Name.** Something that tells you later where the key lives, for example `Claude Code on my laptop` or `Zapier: weekly poll`.
   - **This key may.** Tick only what the tool needs: **Create content** (scope `content`), **Upload images** (`media`), **Manage scheduled** (`schedule`) and **Read lookups** (`read`). All four are ticked to start with. For an AI agent that writes posts with images, keep Create content, Upload images and Read lookups; keep Manage scheduled if it should also move or cancel scheduled items. See [Scopes](https://docs.urnextdoor.com/getting-started/scopes.md).
   - **Expires.** 30 days, 90 days (the default), 1 year, or never. Shorter is safer; you can always create a new key later.
4. Select **Create key**. The dialog changes to **Your new API key** and shows the full key **once**, starting with `und_sk_`.
5. Select **Copy** next to the key and keep it somewhere safe for the next step, then select **Done**. If you try to close the dialog without copying, it asks you to confirm. Ur Next Door stores only a fingerprint (a hash) of the key, so nobody, including support, can show it to you again.

> **Copy it now:**
>
> If you close the dialog without copying the key, it cannot be recovered. Revoke it and create a new one.

After you create it, the key appears in your list with its name, the first characters (for example `und_sk_7Hq2x`), the last four characters, its scopes, its status, when it was created, when it was last used and when it expires. We also email you whenever a new key is created on your account, so you notice a key you did not make.

## Create a key in the app

1. Open the Ur Next Door app and sign in.
2. Go to **Settings** and open the **API keys** tab.
3. Fill in the same three fields: **Name**, **Scopes** and **Expiry**.
4. Create the key and copy it with the copy control. It is shown only once.
5. Send it to the computer that will use it in a way only you can read, for example a password manager. Avoid pasting it into chats, emails or notes apps that sync to other people.

> **Note:**
>
> Keys made in the app and on the website are the same kind of key and appear in both lists. Revoking one in either place revokes it everywhere.

## Store the key in UND_API_KEY

Every example in these docs reads the key from an environment variable named `UND_API_KEY`. That keeps the key out of your code, your prompts and your shell history.

### macOS and Linux

```bash
# Paste the key when asked. It is not shown on screen and not saved in your history.
read -rs UND_API_KEY && export UND_API_KEY

# Check that it is set by printing only its first 12 characters
echo "${UND_API_KEY:0:12}..."
```

This lasts until you close the terminal. To keep it, add a line `export UND_API_KEY="und_sk_..."` to your shell profile (`~/.zshrc` on macOS, `~/.bashrc` on most Linux systems) with a text editor, and make the file readable only by you with `chmod 600 ~/.zshrc`. Open a new terminal afterwards.

### Windows

1. Press the Windows key and search for **Edit environment variables for your account**.
2. Under **User variables**, choose **New**.
3. Set the name to `UND_API_KEY` and paste the key as the value. Save.
4. Close and reopen your terminal, editor or AI tool so it picks up the variable.

In PowerShell you can set it for the current window only:

```powershell
$env:UND_API_KEY = Read-Host -Prompt "Paste your Ur Next Door API key"
```

### In a project folder

Many tools read a `.env` file in the project folder:

```text
UND_API_KEY=und_sk_...
```

Add `.env` to your `.gitignore` before you create the file, so the key is never committed.

## Check that the key works

`GET /api/v1/me` works with any valid key and tells you which member and key you are using:

**cURL**

```bash
curl "https://urnextdoor.com/api/v1/me" \
  -H "Authorization: Bearer $UND_API_KEY"
```

**JavaScript**

```js
const res = await fetch("https://urnextdoor.com/api/v1/me", {
  headers: {
    Authorization: `Bearer ${process.env.UND_API_KEY}`,
  },
});
console.log(res.status, await res.json());
```

**Python**

```python
import os

import requests

api_key = os.environ["UND_API_KEY"]

response = requests.get(
    "https://urnextdoor.com/api/v1/me",
    headers={
        "Authorization": f"Bearer {api_key}",
    },
    timeout=30,
)
print(response.status_code, response.json())
```

**PHP**

```php
<?php
$apiKey = getenv('UND_API_KEY');

$ch = curl_init('https://urnextdoor.com/api/v1/me');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
    ],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);

echo $status, PHP_EOL, $body, PHP_EOL;
```

Sample response: `200 OK`

```json
{
  "ok": true,
  "user": {
    "id": 7,
    "username": "aarav",
    "display_name": "Aarav",
    "plan": "free",
    "profile_url": "https://urnextdoor.com/users/aarav"
  },
  "key": {
    "id": 3,
    "name": "Claude Code",
    "prefix": "und_sk_7Hq2x",
    "scopes": [
      "content",
      "media",
      "schedule",
      "read"
    ],
    "created_at": "2026-10-15T09:00:00Z",
    "expires_at": "2027-01-13T09:00:00Z"
  },
  "request_id": "9f8e7d6c5b4a3921"
}
```

A `401` with `missing_api_key` means the header was not sent (usually the variable is empty in that terminal). A `401` with `invalid_api_key` means the key was mistyped, revoked or expired.

## Manage, rotate and revoke keys

- **Revoke** a key from the API keys tab whenever you stop using it, or at once if you think it leaked. It stops working immediately.
- **Rotate** by creating a new key, updating `UND_API_KEY` where it is used, checking `GET /api/v1/me`, then revoking the old key.
- **Recent requests** on the same tab lists each recent call: time, method, route, status, error code, the key prefix, the client and how long it took. Use it to confirm a tool is doing what you expect.

More in [Keep your API key safe](https://docs.urnextdoor.com/security.md).

## Frequently asked questions

### I lost my key. Can I see it again?

No. Only a fingerprint of the key is stored, so it cannot be shown again. Revoke the lost key and create a new one.

### How many keys can I have?

Up to 5 active keys at a time. Revoked and expired keys do not count.

### What happens when a key expires?

Requests with it answer 401 with the code invalid_api_key. Create a new key and update the tool that used the old one.

### Do my keys keep working after I reset my password?

No. Resetting your password revokes all of your API keys, in case the reset happened because your account was at risk. Create new keys afterwards.

### Can I change the scopes of an existing key?

Create a new key with the scopes you want, switch your tool to it, and revoke the old key.

## Next steps

- [Make your first request](https://docs.urnextdoor.com/getting-started/first-request.md) with your new key.
- Connect it to an AI tool: [Claude Code](https://docs.urnextdoor.com/ai/claude-code.md), [Codex CLI](https://docs.urnextdoor.com/ai/codex-cli.md) or [ChatGPT](https://docs.urnextdoor.com/ai/chatgpt-actions.md).
- Read [Keep your API key safe](https://docs.urnextdoor.com/security.md).
