> ## Documentation Index
> Fetch the complete documentation index at: https://docs.unprice.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Check access

> Use entitlements, record usage, and consume usage in the request path.

Use this guide when you already have a customer mapped to a plan version and want to gate one
feature in your app.

## Replace plan branches with feature checks

Without Unprice, pricing logic often leaks into product code:

```ts theme={null}
if (customer.plan === "PRO") {
  return runTokenGeneration();
}

return new Response("Upgrade required", { status: 403 });
```

With Unprice, your code checks the feature slug. The customer's plan version and entitlement state
stay outside the product branch.

```ts theme={null}
const { result, error } = await unprice.access.check({
  customerId: customer.unpriceCustomerId,
  featureSlug: "ai-messages"
});

if (error) {
  throw new Error(error.message);
}

if (!result.allowed) {
  return new Response("Feature unavailable", { status: 403 });
}

return runTokenGeneration();
```

## Report or enforce usage

Use `usage.record` when you only need async usage evidence:

```ts theme={null}
await unprice.usage.record({
  customerId: customer.unpriceCustomerId,
  eventSlug: "completions",
  idempotencyKey: request.id,
  properties: {
    aiMessages: 1,
    aiGenerations: 2,
    aiTools: 3,
    inputTokens: 1840,
    outputTokens: 620
  }
});
```

Use `usage.consume` when the request path must deny over-limit or over-budget usage:

```ts theme={null}
const { result, error } = await unprice.usage.consume({
  customerId: customer.unpriceCustomerId,
  featureSlug: "ai-messages",
  eventSlug: "completions",
  idempotencyKey: request.id,
  properties: {
    aiMessages: 1,
    inputTokens: 1840,
    outputTokens: 620
  }
});

if (error) {
  throw new Error(error.message);
}

if (!result.allowed) {
  return new Response("Usage limit reached", { status: 429 });
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Choose the runtime call" icon="code" href="/quickstart/choose-operation">
    Compare `access.check`, `usage.record`, `usage.consume`, and budgeted runs.
  </Card>

  <Card title="Access check SDK" icon="shield-check" href="/libraries/ts/sdk/access/check">
    See the full `access.check` request and response shape.
  </Card>
</CardGroup>
