---
title: "Image Editor Authentication"
description: "How the Topol Image Editor authorizes itself with your API key or a short-lived nonce, whether it runs inside the email editor or on its own."
url: https://docs.topol.io/email-editor/guide/image-editor-authentication.html
---

# Image editor authentication

**The image editor proves its licence itself, on every load and on every request to its backend.** It does not inherit anything from the page that embeds it: when it opens inside the email editor, the email editor is just another host passing credentials through. This is what makes the image editor usable as a standalone plugin.

## Credentials

Two ways to authenticate, chosen by what the host passes:

| Host passes | What the editor sends | When to use |
| --- | --- | --- |
| `authorize.apiKey` only | The API key as a bearer token | Simple integrations; the key is checked against its allowed domains |
| `getNonce` callback | A short-lived `nc_…` nonce, refreshed before it expires | Recommended; required if the key must never sit in the page |

```js
const editor = Tim({
  config: {
    authorize: {
      apiKey: "YOUR_API_KEY",
      entityId: "42", // your end user, for usage accounting
    },
    // ... other options
  },
  // Optional: turns on nonce authentication (see the email editor guide).
  async getNonce() {
    const res = await fetch("/api/topol/nonce", { method: "POST" });
    const { nonce } = await res.json();
    return nonce;
  },
  onEditorError({ source, message }) {
    console.error(source, message);
  },
});
```

The image editor accepts the same nonces your backend signs with the Secret key for the email editor, as described in [Nonce Authentication](https://docs.topol.io/email-editor/guide/nonce-authentication.html), and uses the same callback shape. Write `exp` as whole seconds: the image backend rejects a nonce whose `exp` has a fractional part.

## What happens at load

1.  The editor resolves the hostname of the embedding page.
2.  It calls `GET /auth/me` on its backend with the bearer token, the hostname and the user id.
3.  On success the editor opens. On failure it stays closed, calls `close()` and reports through `onEditorError` with `source: "authorize"`.

Every later request to the image backend carries the same credentials. That covers the AI tools (background removal, object removal and object replacement) and the image and icon proxies. Icon search queries Iconify directly and sends no credentials. A nonce that expired mid-session is refreshed through `getNonce` once and the request is retried.

## Allowed domains

Your API key is bound to the domains configured for it in Topol. The editor sends the embedding page's hostname in the `X-Topol-Hostname` header, so the check works even though the editor itself runs in an iframe on Topol's CDN. Inside the Topol email and landing page editors the image editor's parent is their iframe on Topol's own domain; those editors have already checked the key against your domains when they opened, so the image backend accepts them without a second domain check. See [Allowed Domains](https://docs.topol.io/email-editor/guide/allowed-domains.html).

## Inside the email editor

The email and landing page editors pass their own `authorize` options and `getNonce` callback to the image editor automatically. Nothing to configure; if the credential is rejected, the image editor does not open and the host shows an error notification.
