# SDK and HTTP integration (/docs/entitlements/sdk)

`@comecero/entitlements` is coming soon. It is not published on npm yet, so you cannot install or import it today. Use the [check API](/docs/entitlements/check-api) over plain HTTP instead.

Comecero staff must turn entitlements on for your shop before you set up features, feature sets and overrides. Ask support to enable it. Metered features also need usage billing turned on.

## Server [#server]

Call `GET https://usage.comecero.com/v1/entitlements` with a [usage key](/docs/usage-billing/set-up#5-create-a-usage-key), not a Comecero API token:

```bash
curl "https://usage.comecero.com/v1/entitlements?customer_id=user_8412&feature=sso" \
  -H "Authorization: Bearer $COMECERO_USAGE_KEY"
```

With Node.js 18 or later, or another server runtime with `fetch`, no package is needed:

```javascript
const url = new URL("https://usage.comecero.com/v1/entitlements");
url.searchParams.set("customer_id", "user_8412");
url.searchParams.set("feature", "sso");

const response = await fetch(url, {
  headers: { Authorization: `Bearer ${process.env.COMECERO_USAGE_KEY}` },
  signal: AbortSignal.timeout(2000),
});
if (!response.ok) throw new Error(`Entitlement check failed: ${response.status}`);
const answer = await response.json();
const sso = answer.entitlements.find((row) => row.feature === "sso");
const allowed = sso?.has_access === true;
```

Use the customer's [`external_id`](/docs/entitlements#your-id-for-the-customer), or their Comecero `customer_id` when none is set. The key selects the shop and live or test mode. Omit `feature` to read every feature. Read the returned `has_access` before doing the work on your server.

## Cache and errors [#cache-and-errors]

- Cache a successful answer for at most 60 seconds, or until the earliest `valid_until` in its rows, whichever comes first.
- When an all-feature answer has `reason: "usage_not_read"`, ask for that feature alone. A finite hard limit stays denied while its usage cannot be read.
- On `429`, wait for the `Retry-After` seconds before retrying. Retry temporary network failures or `503` with a bounded delay. Do not retry invalid input or an unknown feature as if access were granted.
- Decide how your app handles an outage. Denying access until a successful check avoids granting access without an answer. Reusing an earlier answer can keep paying customers working, but may retain access after a cancellation or expired override.

These are rules for your integration to implement. The HTTP examples above make one request and do not add caching or retries.

## Pages [#pages]

Keep the usage key on your server. A browser page should ask your backend, which reads the signed-in customer's id from your session and calls the check API for that customer. Do not let a query parameter choose another customer.

A page check helps show or hide controls. Always check again on your server before doing the work.

## Webhooks [#webhooks]

Subscribe to [`entitlement:changed`](/api/webhooks/entitlement-changed) with `active: true`. [Check the signature](/docs/guides/webhooks#check-the-signature) using the raw body before parsing JSON. The signing key is the subscription's `signature_key`, or your account's key.

Drop an `event_id` you have already handled and keep the highest `data.version` for each customer. Clear cached answers for `data.external_id` when a new change arrives. Deliveries can arrive twice or out of order. See [when access changes](/docs/entitlements#when-access-changes).
