> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tranthor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Write Key Restrictions

> Limit your write key to your own apps and websites, so a copied key stops working elsewhere.

Your write key is public: it ships inside your apps and on your website. A restriction lists the apps and websites the key may be used from. Requests from anywhere else are refused.

> [!NOTE]
>
> A restriction stops casual reuse of your key, such as someone pasting it into their own app or site. It does not prove who a customer is: anything outside a browser can claim any app ID or origin. To prove that events come from the customer they name, use [identity verification](https://docs.tranthor.com/guide/identity-verification.md).

## Add a restriction

1. In Tranthor, open **Settings > API keys**.
2. Under **Public write key**, find **Restrict this key**.
3. Add your mobile apps under **Allowed app IDs**, and your websites under **Allowed websites**.
4. Select **Save**. Restrictions apply within 30 seconds.

Each list holds at most 20 entries. Both lists empty means the key works from anywhere, which is the default.

## How requests are matched

A request from a browser carries an `Origin` header. Tranthor matches it against **Allowed websites**. Any other request must send an app ID that is in **Allowed app IDs**.

| Request | Allowed when |
| - | - |
| From a website (has an `Origin`) | The origin matches an allowed website. |
| From a mobile app or a server (no `Origin`) | Its `x-tranthor-app-id` header exactly matches an allowed app ID. |

So if you fill only one list, the other kind of request is refused. With only app IDs, the key stops working on websites. With only websites, it stops working in mobile apps and on servers.

### Allowed app IDs

The iOS and Android SDKs send the app ID on every request: the bundle identifier on iOS, the package name on Android. Add those, for example `com.example.shop`. If you set `appId` in the SDK configuration, add that value instead.

If you call the API from a server with a restricted key, send an allowed value in the `x-tranthor-app-id` header.

### Allowed websites

Enter the scheme, the host and, if it is not the default, the port. No path.

| Entry | Matches |
| - | - |
| `https://shop.example.com` | Only `https://shop.example.com`. |
| `https://*.example.com` | Any subdomain, at any depth, such as `https://www.example.com` and `https://eu.shop.example.com`. Not `https://example.com` itself; add it separately. |
| `http://localhost:3000` | Your local development server. |

Entries are case-insensitive. `http` and `https` are different websites.

## When a request is refused

Tranthor answers `403` with one of these codes:

| `code` | Meaning |
| - | - |
| `write_key_origin_not_allowed` | The website is not in **Allowed websites**. |
| `write_key_app_not_allowed` | The app ID is missing or not in **Allowed app IDs**. |

The SDKs treat these as configuration errors: the batch is dropped and reported through `onError`, without retrying. Check the lists before you ship an app with a new bundle identifier or package name, or a site on a new domain.

You can also set restrictions from your backend with an [Admin API key](https://docs.tranthor.com/guide/accessing-admin-api.md). The request replaces both lists:

```bash theme={null}
curl -X PUT "https://api.tranthor.com/api/admin/settings/write-keys/restrictions" \
  -H "Authorization: Bearer <ADMIN_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "workspaceId": "<WORKSPACE_ID>",
    "writeKeyName": "<WRITE_KEY_NAME>",
    "allowedAppIds": ["com.example.shop"],
    "allowedOrigins": ["https://*.example.com"]
  }'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.