# Limit concurrent runs

This guide limits how many copies of your application run at the same time on one device. At the end, your application reports each copy when it starts, sends process heartbeats while it runs and reports the exit when it closes. Seatify refuses a new copy when the device is at the limit.

## Before you start

- Your application claims and validates licenses. See [Add your application](../add-your-application/).
- The [policy](../../../concepts/policies/#heartbeats-and-processes) binds devices and has a process interval. The process interval turns on process tracking. Set a process limit per device to limit the copies. See [Concurrent runs](../../../concepts/concurrent-runs/).

The examples call `https://license.seatify.dev`. In curl, the keys, the fingerprint and the process ID are the variables `$SEATIFY_PUBLISHABLE_KEY`, `$LICENSE_KEY`, `$DEVICE_FINGERPRINT` and `$PROCESS_ID`. In the other languages, they are variables of your application.

## Choose a process ID

Each copy of your application sends a process ID. The ID identifies the copy on the device. Send the same ID in the spawn, in each heartbeat and in the exit.

The process ID from the operating system works:

| Language | Process ID |
| --- | --- |
| Swift | `ProcessInfo.processInfo.processIdentifier` |
| C# | `Environment.ProcessId` |
| Go | `os.Getpid()` |
| JavaScript (Node.js) | `process.pid` |

Send the ID as a string, such as `"4242"`. A number fails with the status 400. A runtime without a process ID can send its own identifier. For example, it can create a random UUID when it starts.

The process ID is case-sensitive. The operating system can give the ID of a stopped copy to a new copy. If the old copy stopped without an exit, Seatify treats the two as one process. The new copy then takes no extra slot.

## Steps

{{% steps %}}

### Claim the license

The device must claim the license before the first spawn. A spawn from a device that has not claimed fails with `not_claimed`. See [Claim the license](../add-your-application/#claim-the-license).

The claim answer shows whether the policy tracks processes. `process_heartbeat.tracked` is `true` when the policy has a process interval.

### Spawn the process

Spawn the process each time your application starts, after the validation. Send the stored license key, the fingerprint and the process ID.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl https://license.seatify.dev/v1/processes/spawn \
  -H "Seatify-Publishable-Key: $SEATIFY_PUBLISHABLE_KEY" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "key": "$LICENSE_KEY",
  "device": { "fingerprint": "$DEVICE_FINGERPRINT" },
  "process": { "pid": "$PROCESS_ID" }
}
EOF
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
import Foundation

struct ProcessCheck: Decodable {
    let valid: Bool
    let reason: String?
}

let processID = String(ProcessInfo.processInfo.processIdentifier)

let body: [String: Any] = [
    "key": licenseKey,
    "device": ["fingerprint": fingerprint],
    "process": ["pid": processID],
]

var request = URLRequest(url: URL(string: "https://license.seatify.dev/v1/processes/spawn")!)
request.httpMethod = "POST"
request.setValue(publishableKey, forHTTPHeaderField: "Seatify-Publishable-Key")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: body)

let (data, _) = try await URLSession.shared.data(for: request)
let check = try JSONDecoder().decode(ProcessCheck.self, from: data)
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Seatify-Publishable-Key", publishableKey);

var processId = Environment.ProcessId.ToString();

var response = await client.PostAsJsonAsync("https://license.seatify.dev/v1/processes/spawn", new
{
    key = licenseKey,
    device = new { fingerprint },
    process = new { pid = processId },
});
var check = await response.Content.ReadFromJsonAsync<ProcessCheck>();

record ProcessCheck(bool Valid, string? Reason);
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
processID := strconv.Itoa(os.Getpid())

body, err := json.Marshal(map[string]any{
	"key":     licenseKey,
	"device":  map[string]string{"fingerprint": fingerprint},
	"process": map[string]string{"pid": processID},
})
if err != nil {
	return err
}

req, err := http.NewRequest("POST", "https://license.seatify.dev/v1/processes/spawn", bytes.NewReader(body))
if err != nil {
	return err
}
req.Header.Set("Seatify-Publishable-Key", publishableKey)
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

var check struct {
	Valid  bool    `json:"valid"`
	Reason *string `json:"reason"`
}
err = json.NewDecoder(res.Body).Decode(&check)
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const processId = String(process.pid);

const response = await fetch("https://license.seatify.dev/v1/processes/spawn", {
  method: "POST",
  headers: {
    "Seatify-Publishable-Key": publishableKey,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    key: licenseKey,
    device: { fingerprint },
    process: { pid: processId },
  }),
});
const check = await response.json();
```
{{< /tab >}}
{{< /tabs >}}

A successful spawn answers with `valid` set to `true`:

```json
{
  "valid": true,
  "status": "active",
  "expired": false,
  "reason": null,
  "license": {
    "id": "<license id>",
    "name": "Studio team",
    "expires_at": "2026-12-20T00:00:00Z",
    "activated_at": "2026-01-22T01:50:56Z"
  },
  "entitlements": [],
  "limits": {
    "max_devices": 50,
    "max_seats": 25,
    "max_processes": 4
  },
  "device": {
    "id": "<device binding id>",
    "expires_at": "2026-09-26T07:45:15Z"
  },
  "heartbeat": {
    "required": true,
    "interval_seconds": 3600,
    "grace_seconds": 1800
  },
  "process": {
    "id": "<process id>",
    "pid": "4242",
    "expires_at": "2026-09-26T06:22:15Z"
  },
  "process_heartbeat": {
    "tracked": true,
    "interval_seconds": 300,
    "grace_seconds": 120
  }
}
```

The `process.expires_at` field shows when the lease of the process ends. The `limits.max_processes` field is the limit that applies to this device. The list of entitlements is empty in a spawn answer. Read the entitlements from the claim or the validation.

A spawn with a process ID that is already running returns the same process. It does not use another slot.

If `valid` is `false`, the `reason` field names the cause. For `process_limit_reached`, see [When the limit is reached](#when-the-limit-is-reached). For the other reasons, see [Handle the answer](#handle-the-answer).

### Send process heartbeats

Send a process heartbeat every `process_heartbeat.interval_seconds` while your application runs. Send the same body as in the spawn.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl https://license.seatify.dev/v1/processes/heartbeat \
  -H "Seatify-Publishable-Key: $SEATIFY_PUBLISHABLE_KEY" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "key": "$LICENSE_KEY",
  "device": { "fingerprint": "$DEVICE_FINGERPRINT" },
  "process": { "pid": "$PROCESS_ID" }
}
EOF
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
let body: [String: Any] = [
    "key": licenseKey,
    "device": ["fingerprint": fingerprint],
    "process": ["pid": processID],
]

var request = URLRequest(url: URL(string: "https://license.seatify.dev/v1/processes/heartbeat")!)
request.httpMethod = "POST"
request.setValue(publishableKey, forHTTPHeaderField: "Seatify-Publishable-Key")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: body)

let (data, _) = try await URLSession.shared.data(for: request)
let check = try JSONDecoder().decode(ProcessCheck.self, from: data)
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
var response = await client.PostAsJsonAsync("https://license.seatify.dev/v1/processes/heartbeat", new
{
    key = licenseKey,
    device = new { fingerprint },
    process = new { pid = processId },
});
var check = await response.Content.ReadFromJsonAsync<ProcessCheck>();
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
body, err := json.Marshal(map[string]any{
	"key":     licenseKey,
	"device":  map[string]string{"fingerprint": fingerprint},
	"process": map[string]string{"pid": processID},
})
if err != nil {
	return err
}

req, err := http.NewRequest("POST", "https://license.seatify.dev/v1/processes/heartbeat", bytes.NewReader(body))
if err != nil {
	return err
}
req.Header.Set("Seatify-Publishable-Key", publishableKey)
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

var check struct {
	Valid  bool    `json:"valid"`
	Reason *string `json:"reason"`
}
err = json.NewDecoder(res.Body).Decode(&check)
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const response = await fetch("https://license.seatify.dev/v1/processes/heartbeat", {
  method: "POST",
  headers: {
    "Seatify-Publishable-Key": publishableKey,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    key: licenseKey,
    device: { fingerprint },
    process: { pid: processId },
  }),
});
const check = await response.json();
```
{{< /tab >}}
{{< /tabs >}}

Each heartbeat starts the lease of the process again. The lease lasts for the process interval plus the process grace. The answer shows the new end of the lease in `process.expires_at`.

Process heartbeats do not replace license heartbeats. If the policy requires heartbeats, send both. See [Send heartbeats](../add-your-application/#send-heartbeats).

If the lease has ended, the heartbeat fails with `process_not_spawned`. Spawn the process again. The spawn checks the limit again. If the heartbeat fails with `not_claimed`, claim the license again, and then spawn again.

### Report the exit

Report the exit when your application closes. Send the same body as in the spawn.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl https://license.seatify.dev/v1/processes/exit \
  -H "Seatify-Publishable-Key: $SEATIFY_PUBLISHABLE_KEY" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "key": "$LICENSE_KEY",
  "device": { "fingerprint": "$DEVICE_FINGERPRINT" },
  "process": { "pid": "$PROCESS_ID" }
}
EOF
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
struct ExitResult: Decodable {
    let exited: Bool
    let reason: String?
}

let body: [String: Any] = [
    "key": licenseKey,
    "device": ["fingerprint": fingerprint],
    "process": ["pid": processID],
]

var request = URLRequest(url: URL(string: "https://license.seatify.dev/v1/processes/exit")!)
request.httpMethod = "POST"
request.setValue(publishableKey, forHTTPHeaderField: "Seatify-Publishable-Key")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: body)

let (data, _) = try await URLSession.shared.data(for: request)
let result = try JSONDecoder().decode(ExitResult.self, from: data)
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
var response = await client.PostAsJsonAsync("https://license.seatify.dev/v1/processes/exit", new
{
    key = licenseKey,
    device = new { fingerprint },
    process = new { pid = processId },
});
var result = await response.Content.ReadFromJsonAsync<ExitResult>();

record ExitResult(bool Exited, string? Reason);
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
body, err := json.Marshal(map[string]any{
	"key":     licenseKey,
	"device":  map[string]string{"fingerprint": fingerprint},
	"process": map[string]string{"pid": processID},
})
if err != nil {
	return err
}

req, err := http.NewRequest("POST", "https://license.seatify.dev/v1/processes/exit", bytes.NewReader(body))
if err != nil {
	return err
}
req.Header.Set("Seatify-Publishable-Key", publishableKey)
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

var result struct {
	Exited bool    `json:"exited"`
	Reason *string `json:"reason"`
}
err = json.NewDecoder(res.Body).Decode(&result)
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const response = await fetch("https://license.seatify.dev/v1/processes/exit", {
  method: "POST",
  headers: {
    "Seatify-Publishable-Key": publishableKey,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    key: licenseKey,
    device: { fingerprint },
    process: { pid: processId },
  }),
});
const result = await response.json();
```
{{< /tab >}}
{{< /tabs >}}

The answer has `exited` set to `true`:

```json
{
  "exited": true,
  "reason": null
}
```

The slot is free immediately. The exit also works on an expired or suspended license. If your application stops without an exit, the slot is free when the lease ends.

{{% /steps %}}

## When the limit is reached

A spawn fails with `process_limit_reached` when all slots of the device are taken. The refused spawn does not change the running processes.

1. Do not start the work of the copy. Tell the user that the limit of copies on this device is reached. You can show the limit from `limits.max_processes`.
2. Let the user close another copy, and then spawn again.

A copy that stopped without an exit keeps its slot until its lease ends. This takes at most the process interval plus the process grace.

## Handle the answer

The License API answers every licensing outcome with the status 200, a refusal too. Your application decides on `valid`, or on `exited` for an exit. The `reason` field names the cause of a refusal.

| Reason | Answered by | What your application does |
| --- | --- | --- |
| `license_not_found` | Spawn, heartbeat, exit | Ask the user to enter the key again. |
| `product_mismatch` | Spawn, heartbeat, exit | The key belongs to another product. Ask the user for the right key. |
| `expired` | Spawn, heartbeat | Tell the user that the license has expired. |
| `suspended` | Spawn, heartbeat | Tell the user that the license is suspended. |
| `process_tracking_not_enabled` | Spawn, heartbeat | The policy has no process interval. Stop reporting processes. |
| `not_claimed` | Spawn, heartbeat, exit | Claim the license again, and then spawn again. After an exit, no action is needed. |
| `process_limit_reached` | Spawn | See [When the limit is reached](#when-the-limit-is-reached). |
| `process_not_spawned` | Heartbeat, exit | Spawn the process again. After an exit, no action is needed. |

Other statuses mean that the request itself is wrong:

| Status | Cause |
| --- | --- |
| 400 | The body is not valid. The `errors` field names each field that is wrong, such as a missing device or process. A body that cannot be read has no `errors` field. A process ID sent as a number causes this. |
| 401 | The publishable key is missing or not valid. |
| 429 | Your application sent too many requests. Try again later. |

## Signed responses

Every answer with the status 200 is signed. Your application can check the signature before it trusts the answer. See [Verify signed responses](../../signatures/verify-signed-responses/).

## Next steps

- [Concurrent runs](../../../concepts/concurrent-runs/)
- [Add your application](../add-your-application/)
- [Licensing models](../licensing-models/)
- [Start a process](../../../license-api/processes/spawn/), [Send a process heartbeat](../../../license-api/processes/heartbeat/) and [End a process](../../../license-api/processes/exit/)

