# Server API: billing

Source: https://docs.neode.sk/development/api-reference/server-billing/
Last updated: 2026-12-03

> 20 operations. Billing packages, contracts, billed sessions and work reports on the server API.

These routes are on the server API, port 21114 (21121 in Docker). They take an API key in `X-API-Key` or a sign-in token; see [The HTTP API](https://docs.neode.sk/development/api.md#signing-in).

Billing packages, contracts, billed sessions and work reports on the server API.

## GET /api/billing/check

Check whether a device may start a billed session.

Answers allowed: true without a contract, and when billing is not set up on the server.

On the server API, port 21114. Needs `device.connect`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `device_id` | query | string | yes | The device |

**200**: Done (`application/json`)

[BillingConnectionCheck](https://docs.neode.sk/development/api-reference/schemas.md#billingconnectioncheck).

| Error | When |
|---|---|
| 400 | device_id is missing (device_id required) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/contracts

List billing contracts.

On the server API, port 21114. Needs `billing.view`.

| Parameter | In | Type | What it is |
|---|---|---|---|
| `target_type` | query | string, one of `device_group`, `org`, `device`, `folder` | Only contracts of this kind of target |
| `target_key` | query | string | With target_type: only the contract of this target |
| `org_id` | query | string | Only the contract of this organization; ignored when target_type and target_key are given |
| `status` | query | string | Only contracts with this status |

**200**: Done (`application/json`)

| Field | Type | What it is |
|---|---|---|
| `contracts` | array of [BillingContract](https://docs.neode.sk/development/api-reference/schemas.md#billingcontract) | Last changed first |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## POST /api/billing/contracts

Give a billing package to a device group, organization or device.

A target has at most one contract in force.

On the server API, port 21114. Needs `billing.manage`.

Request body, `application/json`:

| Field | Type | Required | What it is |
|---|---|---|---|
| `target_type` | string, one of `device_group`, `org`, `device` |  | What the package is given to. A folder is refused. |
| `target_key` | string | yes | The device group GUID, organization id or device id |
| `org_id` | string |  | Older form: stands for target_type org with this target_key |
| `package_id` | string | yes |  |
| `status` | string |  | active when empty; default `"active"` |
| `remaining_minutes` | integer |  | The package's included minutes when 0 or missing |
| `overage_rate_minor` | integer or null |  | The contract's own price per hour beyond the included minutes, in minor units of currency: cents of EUR, yen of JPY, fils of BHD; null or left out: the package's; at least 0 |
| `hourly_rate_minor` | integer |  | Price per hour of the included minutes, in minor units of currency: cents of EUR, yen of JPY, fils of BHD; at least 0 |
| `currency` | string |  | A contract bills in its package's currency: a currency other than the package's is refused with 400 |
| `valid_from` | string (date-time) |  |  |
| `valid_until` | string (date-time) |  |  |
| `id` | string |  | A new UUID when empty |

**201**: Created (`application/json`)

[BillingContract](https://docs.neode.sk/development/api-reference/schemas.md#billingcontract).

| Error | When |
|---|---|
| 400 | The body is not JSON, target_type and target_key required, an invalid or folder target_type, or package_id required |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 409 | The target already has a contract (assignment already exists for this target) |

## PUT /api/billing/contracts/{id}

Change a billing contract.

Changes only the fields in the body.

On the server API, port 21114. Needs `billing.manage`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The contract id |

Request body, `application/json`:

The fields to change. Fields not in the body, and values of the wrong type, keep their value.

| Field | Type | What it is |
|---|---|---|
| `status` | string | Kept when empty; active or suspended |
| `remaining_minutes` | integer |  |
| `overage_rate_minor` | integer or null | The contract's own price per hour beyond the included minutes, in minor units of currency: cents of EUR, yen of JPY, fils of BHD; null or left out: the package's; at least 0 |
| `hourly_rate_minor` | integer | Price per hour of the included minutes, in minor units of currency: cents of EUR, yen of JPY, fils of BHD; at least 0 |
| `currency` | string | A contract bills in its package's currency: a currency other than the package's is refused with 400 |
| `valid_from` | string or null (date-time) | null clears it |
| `valid_until` | string or null (date-time) | null clears it |

**200**: The contract as saved (`application/json`)

[BillingContract](https://docs.neode.sk/development/api-reference/schemas.md#billingcontract).

| Error | When |
|---|---|
| 400 | The body is not JSON (invalid JSON) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 404 | There is no such contract (contract not found) |

## DELETE /api/billing/contracts/{id}

Delete a billing contract.

Answers ok for an id that does not exist too.

On the server API, port 21114. Needs `billing.manage`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The contract id |

**200**: Done (`application/json`)

| Field | Type |
|---|---|
| `ok` | `"true"` |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/packages

List billing packages.

On the server API, port 21114. Needs `billing.view`.

**200**: Done (`application/json`)

| Field | Type |
|---|---|
| `packages` | array of [BillingPackage](https://docs.neode.sk/development/api-reference/schemas.md#billingpackage) |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## POST /api/billing/packages

Make a billing package.

On the server API, port 21114. Needs `billing.manage`.

Request body, `application/json`:

| Field | Type | Required | What it is |
|---|---|---|---|
| `name` | string | yes |  |
| `description` | string |  |  |
| `included_minutes` | integer |  | Minutes per billing month |
| `rounding_minutes` | integer |  | Billing step in minutes; 10 when 0 or less; default `10` |
| `overage_rate_minor` | integer |  | Price per hour once the included minutes are used up, in minor units of currency: cents of EUR, yen of JPY, fils of BHD. The float overage_rate of earlier versions is refused with 400.; at least 0 |
| `currency` | string |  | ISO 4217 code in capitals (EUR, JPY, BHD); other codes are refused with 400. Left out: the default_currency of the billing rules (EUR unless set). It cannot change while the package has contracts (409). |
| `id` | string |  | A new UUID when empty |

**201**: Created (`application/json`)

[BillingPackage](https://docs.neode.sk/development/api-reference/schemas.md#billingpackage).

| Error | When |
|---|---|
| 400 | The body is not JSON, or name is missing or empty (name required) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## PUT /api/billing/packages/{id}

Replace a billing package.

Replaces the whole package: a field not in the body is stored empty or 0 (rounding_minutes 1). Send every field. An unknown id changes nothing and still answers 200.

On the server API, port 21114. Needs `billing.manage`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The package id |

Request body, `application/json`:

| Field | Type | What it is |
|---|---|---|
| `name` | string |  |
| `description` | string |  |
| `included_minutes` | integer | Minutes per billing month |
| `rounding_minutes` | integer | Billing step in minutes; 10 when 0 or less; default `10` |
| `overage_rate_minor` | integer | Price per hour once the included minutes are used up, in minor units of currency: cents of EUR, yen of JPY, fils of BHD. The float overage_rate of earlier versions is refused with 400.; at least 0 |
| `currency` | string | ISO 4217 code in capitals; left out: the package keeps its currency. It cannot change while the package has contracts (409). |

**200**: The body as stored; created_at and updated_at are not read back (`application/json`)

[BillingPackage](https://docs.neode.sk/development/api-reference/schemas.md#billingpackage).

| Error | When |
|---|---|
| 400 | The body is not JSON (invalid JSON) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## DELETE /api/billing/packages/{id}

Delete a billing package.

Refused while a contract uses the package. Answers ok for an id that does not exist too.

On the server API, port 21114. Needs `billing.manage`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The package id |

**200**: Done (`application/json`)

| Field | Type |
|---|---|
| `ok` | `"true"` |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 409 | A contract uses the package (package has active assignments) |

## GET /api/billing/packages/{id}/preview

Show what a package billed in one month.

On the server API, port 21114. Needs `billing.view`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The package id |
| `period` | query | string |  | The billing month, YYYY-MM; the current month in the server's time zone when missing |

**200**: Done (`application/json`)

[BillingPackagePreview](https://docs.neode.sk/development/api-reference/schemas.md#billingpackagepreview).

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 404 | There is no such package (package not found) |

## GET /api/billing/reports

List work reports.

On the server API, port 21114. Needs `billing.view`.

| Parameter | In | Type | What it is |
|---|---|---|---|
| `org_id` | query | string | Only reports of sessions of this organization |
| `limit` | query | integer | Most reports to answer, newest first. Default 100; a value above 500, 0 or below gives 100.; default `100`, at least 1, at most 500 |

**200**: Done (`application/json`)

| Field | Type |
|---|---|
| `reports` | array of [BillingWorkReport](https://docs.neode.sk/development/api-reference/schemas.md#billingworkreport) |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/reports/export

Export work reports as CSV.

Holds up to 5000 reports, each with its session. The PDF is the console's (GET /api/panel/billing/reports/export?format=pdf). The CSV is UTF-8 with a byte order mark, comma separated with CRLF line ends; times are RFC 3339 UTC with milliseconds, amounts decimal strings in the currency's major unit with the currency in the next column.

On the server API, port 21114. Needs `billing.export`.

| Parameter | In | Type | What it is |
|---|---|---|---|
| `format` | query | string, one of `csv` | default `"csv"` |
| `org_id` | query | string | Only rows of this organization |
| `device_ids` | query | string | Only rows of these devices, separated by commas; an empty value keeps none. Without it the export holds every device. |

**200**: The file billing-reports-YYYY-MM-DD.csv, dated in the server's time zone (`text/csv`)

String (binary).

| Error | When |
|---|---|
| 400 | format is not csv (format must be csv) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/rules

Show the billing rules of the server.

Rules never saved have their defaults: rounding and the work report from the server's environment, an idle threshold of 2 minutes, everything else off.

On the server API, port 21114. Needs `billing.view`.

**200**: Done (`application/json`)

| Field | Type | Required |
|---|---|---|
| `rules` | [BillingRules](https://docs.neode.sk/development/api-reference/schemas.md#billingrules) | yes |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 503 | Billing is not set up on the server (billing not enabled) |

## PUT /api/billing/rules

Change the billing rules of the server.

Rules the body leaves out keep their value. Sessions that end after the change follow the new rules.

On the server API, port 21114. Needs `billing.manage`.

Request body, `application/json`:

The rules to change; a rule left out keeps its value

| Field | Type | What it is |
|---|---|---|
| `default_rounding_minutes` | integer | The rounding step a new package starts with; at least 1, at most 240 |
| `require_work_report` | boolean | A finished session waits for the technician's work report |
| `free_seconds` | integer | Sessions with less billable time are not billed; 0: off; at least 0, at most 3600 |
| `minimum_minutes` | integer | A billed session counts at least this long; 0: off; at least 0, at most 1440 |
| `cap_minutes` | integer | A session never bills more; 0: off. Not below minimum_minutes; at least 0, at most 10080 |
| `idle_exclude` | boolean | Leave stretches without input on the device out of the billed time |
| `idle_threshold_minutes` | integer | How long a stretch without input has to be to count as idle; at least 1, at most 120 |
| `idle_bill_threshold` | boolean | Still bill the first idle_threshold_minutes of an idle stretch; off leaves out the whole stretch |

**200**: The rules as saved (`application/json`)

| Field | Type | Required |
|---|---|---|
| `rules` | [BillingRules](https://docs.neode.sk/development/api-reference/schemas.md#billingrules) | yes |

| Error | When |
|---|---|
| 400 | The body is not JSON (invalid JSON), or a rule is out of bounds (invalid billing rules: and the rule's name) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 503 | Billing is not set up on the server (billing not enabled) |

## GET /api/billing/sessions

List billed sessions.

On the server API, port 21114. Needs `billing.view`.

| Parameter | In | Type | What it is |
|---|---|---|---|
| `org_id` | query | string | Only sessions of this organization |
| `status` | query | string, one of `active`, `pending_report`, `closed` | Only sessions with this status |
| `limit` | query | integer | Most sessions to answer, newest first. Default 100; a value above 500, 0 or below gives 100.; default `100`, at least 1, at most 500 |

**200**: Done (`application/json`)

| Field | Type | What it is |
|---|---|---|
| `sessions` | array of [BillingSession](https://docs.neode.sk/development/api-reference/schemas.md#billingsession) | Newest first |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/sessions/export

Export billed sessions as CSV.

Holds up to 5000 sessions, newest first. The CSV is UTF-8 with a byte order mark, comma separated with CRLF line ends; times are RFC 3339 UTC with milliseconds, amounts decimal strings in the currency's major unit with the currency in the next column.

On the server API, port 21114. Needs `billing.export`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `format` | query | string, one of `csv` | yes | Must be csv |
| `org_id` | query | string |  | Only rows of this organization |
| `device_ids` | query | string |  | Only rows of these devices, separated by commas; an empty value keeps none. Without it the export holds every device. |

**200**: The file billing-sessions-YYYY-MM-DD.csv, dated in the server's time zone (`text/csv`)

String (binary).

| Error | When |
|---|---|
| 400 | format is not csv (only csv supported) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/sessions/pending

Show the billed session of a device that waits for its report.

On the server API, port 21114. Needs `billing.reports`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `device_id` | query | string | yes | The device |

**200**: Done (`application/json`)

| Field | Type | What it is |
|---|---|---|
| `session` | [BillingSession](https://docs.neode.sk/development/api-reference/schemas.md#billingsession) or null | The newest session of the device that waits for its report; null when none |

| Error | When |
|---|---|
| 400 | device_id is missing (device_id required) |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |

## GET /api/billing/sessions/{id}

Show a billed session with its device.

On the server API, port 21114. Needs `billing.view`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The billed session id |

**200**: Done (`application/json`)

| Field | Type | Required | What it is |
|---|---|---|---|
| `session` | [BillingSession](https://docs.neode.sk/development/api-reference/schemas.md#billingsession) |  |  |
| `device` | object or null |  | The device as the device routes show it; null when it has no row or the caller does not see it |
| `breakdown` | object |  | Only when billing is set up on the server |
| `breakdown.pauses` | array of object | yes | The stretches without input the device reported |
| `breakdown.pauses[].from` | string (date-time) | yes |  |
| `breakdown.pauses[].to` | string (date-time) |  | Only when the stretch ended |
| `breakdown.pauses[].seconds` | integer | yes |  |
| `breakdown.pauses[].unbilled_seconds` | integer | yes | How much of it the idle rules leave out |
| `breakdown.unbilled_seconds` | integer | yes | The idle time left out of the billed time |
| `breakdown.rules` | array of string | yes | The rules that changed the billed minutes: free, minimum or cap |

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 404 | There is no such session (billing session not found) |

## POST /api/billing/sessions/{id}/report

Write the work report of a billed session.

Saves the report and closes the session. The report names the caller; when the server cannot tell who called, the X-Operator-Id header, else "operator".

On the server API, port 21114. Needs `billing.reports`.

| Parameter | In | Type | Required | What it is |
|---|---|---|---|---|
| `id` | path | string | yes | The billed session id |
| `X-Operator-Id` | header | string |  | Who wrote the report, used when the server cannot tell who called |

Request body, `application/json`:

| Field | Type | Required | What it is |
|---|---|---|---|
| `summary` | string | yes | What was done; cut at 8000 bytes |
| `category` | string |  | Cut at 128 bytes |
| `ticket_ref` | string |  | Cut at 128 bytes |

**200**: Done (`application/json`)

| Field | Type |
|---|---|
| `ok` | `"true"` |

| Error | When |
|---|---|
| 400 | The body is not JSON, summary required, session already closed, report already submitted, or an unknown session |
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
| 503 | Billing is not set up on the server (billing not configured) |

## GET /api/billing/stats

Show billing totals.

On the server API, port 21114. Needs `billing.view`.

**200**: Done (`application/json`)

[BillingStats](https://docs.neode.sk/development/api-reference/schemas.md#billingstats).

| Error | When |
|---|---|
| 401 | No credential, or one that is not valid |
| 403 | The credential's role lacks the permission |
