# Empire Security provisioning and usage billing API (marketplace spec)

Version 1 (2026-11-09). Base URL `https://security.eliteaiempire.com/api/partner/v1`. Operator: Elite AI Holdings LLC; Empire Security is an Elite Agentic Solutions company.

This is the vendor side of a distributor marketplace such as Pax8: the marketplace (or an MSP partner directly) creates a tenant for each end customer, changes its seats, cancels it, and reads monthly usage to bill. Pax8 does not publish its vendor integration spec (UNVERIFIED as of 2026-11-09), so this API follows the common shape (create / modify quantity / cancel / usage export) and keeps every operation idempotent so a marketplace can retry safely. Field names map one-to-one to a marketplace's subscription record, as shown below.

## Authentication
`Authorization: Bearer <key>`.
- `pk_...` partner key: issued once when the partner (or the distributor, acting as partner) signs the partner agreement (`POST /agreement`, see `/partners/api#keys`). Rotate with `POST /keys/rotate`.
- `sbx_...` sandbox key: same endpoints against an isolated sandbox. Usage is computed but never billed.

## Objects

### Tenant
| Field | Type | Notes |
|---|---|---|
| `id` | string | `ten_` + 16 hex. Ours. |
| `external_id` | string or null | The marketplace's subscription or company id. Unique per partner. |
| `name` | string | End customer name, up to 120 characters. |
| `domain` | string | End customer's primary public domain; reports scan it. |
| `offer` | string | `reports`, `reports_endpoint`, `helpdesk` or `bundle`. |
| `unit` | string | `client organization` or `endpoint` (for `reports_endpoint`). |
| `seats` | integer | Billable quantity in `unit`, 1 to 100000. |
| `status` | string | `active` or `cancelled`. |
| `created`, `updated` | string | UTC ISO 8601. |

Marketplace mapping: subscription id → `external_id`; product SKU → `offer`; quantity → `seats`; company → `name` + `domain`.

### Usage line
`tenant_id`, `external_id`, `tenant_name`, `offer`, `unit`, `seat_days`, `quantity` (= seat_days / days in month, 4 decimals), `unit_price`, `amount` (USD, 2 decimals).

## Operations

| Operation | Request | Success | Errors |
|---|---|---|---|
| Create tenant | `POST /tenants` `{"external_id","name","domain","offer","seats"}`, optional header `Idempotency-Key` | 201 + tenant, `Location` header. 200 + existing tenant if the same `external_id` exists with identical fields. | 409 `conflict` (same external_id, different fields), 409 `idempotency_conflict` (same key, different body), 422 `invalid_field` |
| Read | `GET /tenants`, `GET /tenants/{id}` (`?include_cancelled=true` for all) | 200 | 404 `not_found` |
| Change seats or offer | `PATCH /tenants/{id}` `{"seats": 25}` (also `offer`, `name`, `domain`) | 200 + tenant; a usage event is written effective now | 404, 409 `cancelled`, 422 |
| Cancel | `DELETE /tenants/{id}` | 200 + tenant with `status: cancelled`; repeating is a no-op | 404 |
| Usage export | `GET /usage?period=YYYY-MM&format=json` or `format=csv` | 200 | 422 bad period |

Usage JSON: `{"period","currency":"USD","tier","client_tenants","days_in_period","complete","lines":[...],"total","note","sandbox"}`. `complete` is false while the month is still running; the export then covers the month up to now.

## Billing rules
- Seat changes form an append-only event log. Usage for a month is the sum over events of seats × time active in that month, in seat-days (UTC).
- Tier for a month: count of distinct tenants with any active day in the month. 10 or more: Partner prices; 50 or more: Premier prices; fewer than 10: list price where one is published, otherwise the Partner price.
- Prices are those published at `https://security.eliteaiempire.com/partners` (source file `pricing/partner_program.json`).
- The export is the billing source; it is not an invoice and creates no payment object. A distributor bills its partners from it; direct partners are invoiced monthly in arrears from the same numbers.

## Example
```
KEY=pk_...
curl -s -X POST https://security.eliteaiempire.com/api/partner/v1/tenants \
  -H "Authorization: Bearer $KEY" -H "Idempotency-Key: sub-8812-create" -H "Content-Type: application/json" \
  -d '{"external_id":"sub-8812","name":"Acme Dental","domain":"acmedental.com","offer":"bundle","seats":1}'
curl -s -X PATCH https://security.eliteaiempire.com/api/partner/v1/tenants/ten_... \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d '{"offer":"reports_endpoint","seats":40}'
curl -s "https://security.eliteaiempire.com/api/partner/v1/usage?period=2026-11&format=csv" -H "Authorization: Bearer $KEY"
```

## Not in v1
- Push webhooks to the marketplace (usage is pulled).
- Single sign-on from the marketplace into the dashboard.
- Pax8-specific field names: to be mapped once Pax8 shares its vendor spec after onboarding.
