# Authentication

Every request to the License API sends a publishable key in the `Seatify-Publishable-Key` header. The publishable key tells the License API which product is calling.

## Publishable keys

A publishable key belongs to one [product](../../concepts/products/#publishable-keys). Create the key on the product in the dashboard. Put the key in the build configuration of your application.

A publishable key is not a secret. It ships inside your application, and anyone can read it.

| Header | Required | Description |
| --- | --- | --- |
| `Seatify-Publishable-Key` | Yes | The publishable key of the product. |

## Two keys

Every endpoint except [Ping](../ping/) sends two keys:

| Key | Where | Purpose |
| --- | --- | --- |
| Publishable key | The `Seatify-Publishable-Key` header | It names the product that is calling. |
| License key | The `key` field of the request body | It proves the right to use the product. |

The License API looks for the license only in the product that the publishable key names. A license of another product is not valid. The answer has the status 200 and the reason `product_mismatch`.

An unknown license key also answers with the status 200. The answer has the reason `license_not_found`. The status 401 always means that the publishable key is wrong. See [Claim a license](../licenses/claim/).

## Retired and deleted keys

A product can have more than one publishable key. For example, you can give each platform or each build its own key. The [activity log](../../concepts/activity/) records which key made each request.

A retired key still works. Applications that already ship with it keep working. To stop a key from working, delete it. The License API then answers every request with that key with the status 401.

## Errors

| Status | Message | Description |
| --- | --- | --- |
| 401 | `A publishable key is required.` | The request has no `Seatify-Publishable-Key` header, or the header is empty. |
| 401 | `The publishable key is not valid.` | No product has this key. The key was deleted, or it has a typing error. |

The body has the error format of the License API. See [Errors](../#errors).

## Unsigned answers

A 401 answer has no signature. It never grants access. Your application trusts only a 200 answer with a valid signature. See [Verify signed responses](../../guides/signatures/verify-signed-responses/).

## Example

Check a publishable key with [Ping](../ping/). The answer names the product of the key.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl https://license.seatify.dev/v1/ping \
  -H "Seatify-Publishable-Key: $SEATIFY_PUBLISHABLE_KEY"
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
var request = URLRequest(url: URL(string: "https://license.seatify.dev/v1/ping")!)
request.setValue(publishableKey, forHTTPHeaderField: "Seatify-Publishable-Key")

let (data, response) = try await URLSession.shared.data(for: request)
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Seatify-Publishable-Key", publishableKey);

using var response = await client.GetAsync("https://license.seatify.dev/v1/ping");
var body = await response.Content.ReadAsStringAsync();
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
req, err := http.NewRequest("GET", "https://license.seatify.dev/v1/ping", nil)
if err != nil {
	return err
}
req.Header.Set("Seatify-Publishable-Key", publishableKey)

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const response = await fetch("https://license.seatify.dev/v1/ping", {
  headers: { "Seatify-Publishable-Key": publishableKey },
});
const body = await response.json();
```
{{< /tab >}}
{{< /tabs >}}

A valid key answers with the status 200:

```json
{
  "message": "pong",
  "api": "license",
  "product": {
    "id": "<product id>",
    "name": "Atlas Server",
    "code": "ATLAS"
  }
}
```

A request without the header answers with the status 401:

```json
{
  "message": "A publishable key is required."
}
```

