---
url: https://docs.sunlicense.com/guide/self-hosted-link.md
---
# Connect a self-hosted SunLicense

If you run **SunLicense on your own server** (the self-hosted SunLicense, sometimes called v1), version 1.4.0 and newer
can link to a SunLicense Cloud organization. Your server keeps working exactly as before and never needs Cloud to
validate a license. Linking adds services that are hard to run on one server: license emails without an SMTP
server, offsite backups, a backup answer for your plugins when your server is down, uptime alerts, every Cloud store
integration, and a free HTTPS address.

Nothing moves when you link. If you'd rather move everything to Cloud, see [SunLicense v1 and Cloud](/v1).

## Connect your server

On your SunLicense server, open **Integrations** › **SunLicense Cloud** › **Connect**. There are two ways:

**I have a SunLicense Cloud account**

1. Open [app.sunlicense.com/connect/v1](https://app.sunlicense.com/connect/v1) and sign in.
2. If you're in several organizations, pick the one this server belongs to. You need to be its Owner or an Admin.
3. Click **Show connect code** and paste the 8-character code (like `K7QM-4XPA`) into your server.

A code works once and for 10 minutes, whatever address your server runs on (an IP and port, behind NAT, no domain
needed). You can also make one in the dashboard under **Settings** › **Connections** › **Connect a self-hosted
SunLicense**.

**Create one for me**

Your server makes a new Cloud organization named after your brand and links to it straight away, without an email
or password ([guest account](/guide/guest-accounts)). The SunLicense Cloud card then shows **Claim your account**:
open it to add your email and password. Until you claim it and confirm the email, services that reach people
(license emails, store deliveries) stay off. A linked guest account counts as used every day, so it isn't deleted
while your server is linked.

Already have a Cloud account? Open the claim link and use your existing email: the guest account, with its link,
moves into your organization.

## What a linked server can use

Each service is a switch on the SunLicense Cloud card in your server. All of them follow your organization's
[plan](/guide/plans); none of them ever blocks a license check.

| Service | What it does |
|---|---|
| **License emails** | Your server sends keys, expiry reminders, revocations and key recovery through Cloud, in your brand ("Acme via SunLicense"), without an SMTP server. Counted toward your plan's customer emails per day, at most 5 a day to one address. If you also set up SMTP, you choose which one sends. |
| **Offsite backups** | After each automatic backup, your server encrypts it with a recovery code only you hold, then uploads it. Cloud stores ciphertext it can't open. |
| **Backup validation** | Your server keeps a copy of its licenses in Cloud, so Cloud can answer your plugins when your server can't. Mirrored products are read-only in Cloud. |
| **Uptime alerts** | An email to your organization's Owners when your server stops checking in for 5 minutes, and one when it's back. |
| **Store integrations** | Tebex, Stripe, Ko-fi, Payhip and the other Cloud [integrations](/integrations/) deliver purchases to your server, which issues the license and emails the key. |
| **Free HTTPS address** | A `<name>.v1.sunlicense.com` address for your plugins, which forwards to your server and falls back to Cloud's copy when your server is down. |

Your organization's emails show up in **Customers** › **Email log** like any other customer email.

## HTTPS address {#https-address}

Most SunLicense servers answer plugins on plain HTTP at an IP and port. With an HTTPS address your plugins call
`https://<name>.v1.sunlicense.com/api/…` instead, and Cloud passes each request to your server over its link: no
domain, certificate or open port of your own. Pick the name on your server (**Integrations** › **SunLicense Cloud**)
or in the dashboard under **Settings** › **Connections** › **HTTPS address** (Owners and Admins).

* **Names**: 3 to 32 characters, lowercase letters, digits and hyphens, not starting or ending with a hyphen. One
  address per organization. Names we use ourselves or that look official (`api`, `admin`, `support`, `sunlicense`…)
  and offensive ones aren't available.
* **What it serves**: your server's license checks (`/api/v1/validate`, `/api/v2/validate`, `/api/v3/validate`,
  `/api/v4/validate`, `/api/v4/keys`, `/api/v2/ping`, `/api/v2/healthy`) and its BuiltByBit webhook
  (`/api/v1/bbb/…`). Nothing else: your admin panel is never on our domain. Requests up to 64 KB.
* **Your server's own answers**: the status, body and signature your server gives come back to the plugin unchanged
  (v3's HMAC and v4's signature included). Every answer says who gave it in the `X-SunLicense-Answered-By` header
  (`server` or `cloud`).
* **Limits**: 2,000,000 requests a month per address, 100 at once and 25 a second on average. Past the monthly limit
  the address answers `429` until the next month. An address that is far over its rate for 10 minutes in a row is
  **suspended** (every request answers `403`) until SunDevs lifts it; ask in the [SunDevs Discord](https://dsc.gg/sundevs).
* **Usage**: checks your server answers through the address count as license checks on your
  [usage page](/guide/plans), like Cloud's own. They are never blocked by your plan.

### When your server is down (failover)

If your server isn't connected, or doesn't answer within 3 seconds, and **Backup validation** is on, Cloud answers
from its copy of your licenses, in the same shapes your plugins expect: `/api/v1` and `/api/v2` exactly as your
server would, `/api/v3` signed with your server's V3 secret, and `/api/v4` signed with your organization's
Cloud key. With backup validation off, the plugin gets `502` (not connected) or `504` (too slow) instead, so it never
sees "key not found" from an empty copy.

For v4 plugins to accept Cloud's answers they must trust Cloud's key next to your server's: SunLicense's Integration
Wizard adds it when backup validation is on. The key is listed at `https://<name>.v1.sunlicense.com/api/v4/keys`
while your server is down, and for your server at `GET /api/v1/v1-link/keys`.

If you moved to SunLicense Cloud and disconnected your server, the address keeps working: Cloud answers on it itself.

## 3 months of Lite for SunLicense owners

The first time a server links, it sends the purchase key from its `license.txt`. If that key hasn't been used for the
offer before, the organization it links to gets **3 months of the Lite plan** for free. After that it stays on its plan:
Free, unless you upgrade.

* The offer is **once per purchase key** and once per organization. A second organization linking with the same key
  still links, without the offer; the server shows why.
* If your organization already pays for Lite or more, nothing changes and the key stays unused, so you can use it
  for another organization later.
* No key (or `no_license_key_found`)? Open a ticket in the [SunDevs Discord](https://dsc.gg/sundevs) with your receipt.

We store only a fingerprint (SHA-256) of the key, never the key itself.

## See and disconnect linked servers

**Settings** › **Connections** in the dashboard lists every linked server: its brand, address, version, the services
it uses and when it last checked in. **Disconnect** (Owners and Admins) stops the link at once; your server keeps
validating licenses on its own, and you can connect it again with a new code. You can also disconnect from the server.

A server belongs to one organization at a time. To link it to another one, disconnect it first.

## What leaves your server

Only what the services you switch on need: your brand name, version and address when it links; customer email
addresses and the values of an email when it sends one; encrypted backups; license data for backup validation. Your
server only makes outbound HTTPS requests to `api.sunlicense.com`; Cloud never connects to it, except the optional
uptime check of the address you give it.

## For developers

The link uses a credential of its own, a **service account token** (`sll_…`), which works only on the link's routes
(`/api/v1/v1-link/…`) and can't sign in or reach anything else in your organization. It isn't a member and doesn't take
a seat.

Your server keeps one WebSocket open to `wss://api.sunlicense.com/api/v1/v1-link/channel`. It says hello with its
install id, version and what it takes (`purchase`, `validate`), answers Cloud's ping every 30 seconds, and receives
store purchases (acknowledged one by one, sent again until they are) and relayed license checks on it. Three missed
pings mark the server down for uptime alerts; a reconnect within a minute doesn't. A server in forwarder mode (moved to
Cloud, plugins unchanged) passes each check to `POST /api/v1/v1-link/validate/{v1|v2|v3|v4}`, and Cloud answers for
your organization in the same shapes.
