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

# Evaluating Feature Access

> Learn how to evaluate feature access in your application using our [API](/api-reference).

<Note>Be sure to check out [Linking Stripe Customers](/linking-stripe-customers) to learn more about how to identify Stripe customers with your own internal customer ID. </Note>

## Evaluating access for a single feature

<Tabs>
  <Tab title="Boolean features">
    <CodeGroup>
      ```tsx React theme={null}
      import { useFeatureAccess } from "priceos/react";
      import type { MyFeatures } from "./priceos.types";

      export function PrioritySupportButton() {
        const { hasAccess, isLoading } = useFeatureAccess<MyFeatures>("priority_support");

        const onClick = () => {
          if (!hasAccess){
            // Customer does not have access
          }

          // Allow action
        }

        if (isLoading) return <div>Loading...</div>;

        return (
          <button onClick={onClick}>
            Contact support
          </button>
        );
      }
      ```

      ```ts Node.js theme={null}
      import { PriceOS } from "priceos";
      import type { MyFeatures } from "./priceos.types";

      const priceos = new PriceOS<MyFeatures>(process.env.PRICEOS_API_KEY!);

      const { hasAccess } = await priceos.features.getAccess(
        "customer_123", // Your internal customer ID
        "priority_support" // Feature key
      );

      if (hasAccess) {
        // Allow action
      }
      ```

      ```bash cURL theme={null}
      curl -X GET "https://api.priceos.com/v1/feature-access?customerId=customer_123" \
        -H "x-api-key: PRICEOS_API_KEY"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Limit features">
    <Note> `usage` will be included if you're using PriceOS to track usage for that feature.</Note>

    <CodeGroup>
      ```tsx React theme={null}
      import { useFeatureAccess } from "priceos/react";
      import type { MyFeatures } from "./priceos.types";

      export function CreateNewButton() {
        const { 
          hasAccess, 
          usage, 
          limit, 
          isLoading 
        } = useFeatureAccess<MyFeatures>("credits");

        const onClick = () => {
          if (!hasAccess){
            // Customer does not have access
          }

          // If using PriceOS to track usage...
          if (usage?.hasReachedLimit){
            // Customer has hit usage limit
          }

          // If using your own system to track usage...
          if (currentUsage >= limit){
            // Customer has hit usage limit
          }

        }

        return (
          <button onClick={onClick}>
            Create new
          </button>
        );
      }
      ```

      ```ts Node.js theme={null}
      import { PriceOS } from "priceos";
      import type { MyFeatures } from "./priceos.types";

      const priceos = new PriceOS<MyFeatures>(process.env.PRICEOS_API_KEY!);
      const { hasAccess, usage, limit } = await priceos.features.getAccess(
        "customer_123", // Your internal customer ID
        "credits"
      );

      if (!hasAccess){
        // Customer does not have access
      }

      // If using PriceOS to track usage...
      if (usage?.hasReachedLimit){
        // Customer has hit usage limit
      }

      // If using your own system to track usage...
      if (currentUsage >= limit){
        // Customer has hit usage limit
      }

      ```

      ```bash cURL theme={null}
      curl -X GET "https://api.priceos.com/v1/feature-access?customerId=customer_123" \
        -H "x-api-key: PRICEOS_API_KEY"
      ```
    </CodeGroup>

    <Warning>The `hasAccess` field indicates whether the customer has access to the feature in general. It does not indicate that the usage limit has been reached. Use the `usage.hasReachedLimit` field for that.</Warning>
  </Tab>
</Tabs>

***

## Evaluate access for all features

<Tabs>
  <Tab title="Boolean features">
    Boolean features are simple on/off checks using `hasAccess`.

    <CodeGroup>
      ```tsx React theme={null}
      import { useFeatureAccess } from "priceos/react";
      import type { MyFeatures } from "./priceos.types";

      export function PrioritySupportButton() {
        const { featureAccess, isLoading } = useFeatureAccess<MyFeatures>();

        const onClick = () => {
          const hasAccess = featureAccess.priority_support.hasAccess;

          if (hasAccess){
            // Allow action
          }
       
        }

        if (isLoading) return <div>Loading...</div>;

        return <button onClick={onClick}>Contact support</button>;
      }
      ```

      ```ts Node.js theme={null}
      import { PriceOS } from "priceos";
      import type { MyFeatures } from "./priceos.types";

      const priceos = new PriceOS<MyFeatures>(process.env.PRICEOS_API_KEY!);
      const featureAccess = await priceos.features.getAccess(
        "customer_123" // Your internal customer ID
      );

      if (featureAccess.priority_support.hasAccess) {
        // Allow action
      }
      ```

      ```bash cURL theme={null}
      curl -X GET "https://api.priceos.com/v1/feature-access?customerId=customer_123" \
        -H "x-api-key: PRICEOS_API_KEY"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Limit features">
    Limit features return usage data and the current limit window.

    <CodeGroup>
      ```tsx React theme={null}
      import { useFeatureAccess } from "priceos/react";
      import type { MyFeatures } from "./priceos.types";

      export function CreateNewButton() {
        const { featureAccess, isLoading } = useFeatureAccess<MyFeatures>();

        const onClick = () => {
          const { hasAccess, usage, limit } = featureAccess.credits ?? {}
          
          if (!hasAccess){
            // Customer does not have access
          }

          // If using PriceOS to track usage...
          if (usage?.hasReachedLimit){
            // Customer has hit usage limit
          }

          // If using your own system to track usage...
          if (currentUsage >= limit){
            // Customer has hit usage limit
          }
        }

        if (isLoading) return <div>Loading...</div>;

        return <button onClick={onClick}>Create new</button>;
      }
      ```

      ```ts Node.js theme={null}
      import { PriceOS } from "priceos";
      import type { MyFeatures } from "./priceos.types";

      const priceos = new PriceOS<MyFeatures>(process.env.PRICEOS_API_KEY!);
      const featureAccess = await priceos.features.getAccess(
        "customer_123" // Your internal customer ID
      );

      const { hasAccess, usage, limit } = featureAccess.credits;

      if (!hasAccess){
        // Customer does not have access
      }

      // If using PriceOS to track usage...
      if (usage?.hasReachedLimit){
        // Customer has hit usage limit
      }

      // If using your own system to track usage...
      if (currentUsage >= limit){
        // Customer has hit usage limit
      }
      ```

      ```bash cURL theme={null}
      curl -X GET "https://api.priceos.com/v1/feature-access?customerId=customer_123" \
        -H "x-api-key: PRICEOS_API_KEY"
      ```
    </CodeGroup>

    <Warning>The `hasAccess` field indicates whether the customer has access to the feature in general. It does not indicate that the usage limit has been reached. Use the `usage.hasReachedLimit` field for that.</Warning>
  </Tab>
</Tabs>
