> ## 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.

# Backend

> Integrate PriceOS in your backend with our [Node.js SDK](https://www.npmjs.com/package/priceos) or [API](/api-reference).

Integrating PriceOS on your backend is the most secure way to use PriceOS and gives you access to all of our API capabilities.

<Tabs>
  <Tab title="Node.js">
    <Steps>
      <Step title="Install">
        [Create an API key](https://app.priceos.com/settings/api-keys) in the PriceOS dashboard and add to your environment variables.

        ```bash title=".env" theme={null}
        PRICEOS_API_KEY=pos_ab234cdef...
        ```

        <CodeGroup>
          ```bash npm theme={null}
          npm i priceos
          ```

          ```bash pnpm theme={null}
          pnpm add priceos
          ```

          ```bash yarn theme={null}
          yarn add priceos
          ```

          ```bash bun theme={null}
          bun add priceos
          ```
        </CodeGroup>
      </Step>

      <Step title="Generate types (optional, but highly recommended)">
        <CodeGroup>
          ```bash npm theme={null}
          npx priceos generate-types
          ```

          ```bash pnpm theme={null}
          pnpm dlx priceos generate-types
          ```

          ```bash yarn theme={null}
          yarn dlx priceos generate-types
          ```

          ```bash bun theme={null}
          bunx priceos generate-types
          ```
        </CodeGroup>

        This will generate a local types file that you can include so all of your features are fully typed.

        Run with the `--help` option to see more configuration options.

        <Tip>
          Remember to regenerate types any time you create a new feature.
        </Tip>
      </Step>

      <Step title="Create SDK client">
        <CodeGroup>
          ```ts Typed theme={null}
          import { PriceOS } from "priceos";
          import type { MyFeatures } from "./priceos.types";

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

          ```ts Untyped theme={null}
          import { PriceOS } from "priceos";

          export const priceos = new PriceOS(process.env.PRICEOS_API_KEY!);
          ```
        </CodeGroup>
      </Step>

      <Step title="Evaluate feature access">
        <CodeGroup>
          ```ts Boolean features theme={null}

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

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

          ```ts Limit features theme={null}
          const { hasAccess, usage } = await priceos.features.getAccess(
            "customer_123", // Your internal customer ID
            "credits" // Feature key
          );

          if (hasAccess && !usage.hasReachedLimit) {
            // Allow access
          }
          ```
        </CodeGroup>

        <Tip>For optimized performance, we recommend implementing a cache if feature access is evaluated frequently (or use our [React hooks](/react-integration), which has a built-in cache).</Tip>
        <Note>Be sure to read [Linking Stripe Customers](/linking-stripe-customers) to learn how to link Stripe customers to your own internal ID.</Note>

        For more details, see [Evaluating Feature Access](/evaluating-feature-access).
      </Step>

      <Step title="Track usage (optional)">
        Only if you're using PriceOS to track your customers' usage for limit features.

        <CodeGroup>
          ```ts Limit features theme={null}
          await priceos.usage.track({
            customerId: "customer_123",
            featureKey: "team_seats",
            amount: 1,
          });
          ```
        </CodeGroup>

        For more details, see [Tracking Usage](/tracking-usage).
      </Step>
    </Steps>
  </Tab>

  <Tab title="API">
    <Steps>
      <Step title="Create API key">
        [Create an API key](https://app.priceos.com/settings/api-keys) in the PriceOS dashboard and add to your environment variables.

        ```bash title=".env" theme={null}
        PRICEOS_API_KEY=pos_ab234cdef...
        ```
      </Step>

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

          ```js JavaScript theme={null}
          const response = await fetch(
            "https://api.priceos.com/v1/feature-access?customerId=customer_123",
            {
              headers: {
                "x-api-key": process.env.PRICEOS_API_KEY,
              },
            }
          );

          const featureAccess = await response.json();
          ```

          ```py Python theme={null}
          import requests

          response = requests.get(
            "https://api.priceos.com/v1/feature-access",
            params={"customerId": "customer_123"},
            headers={"x-api-key": "PRICEOS_API_KEY"},
          )

          feature_access = response.json()
          ```
        </CodeGroup>

        For more details, see [Evaluating Feature Access](/evaluating-feature-access) and [Linking Stripe Customers](/linking-stripe-customers).
      </Step>

      <Step title="Track usage">
        <CodeGroup>
          ```bash cURL theme={null}
          curl -X POST "https://api.priceos.com/v1/usage" \
            -H "x-api-key: PRICEOS_API_KEY" \
            -H "Content-Type: application/json" \
            -d '{
              "customerId": "customer_123",
              "featureKey": "team_seats",
              "amount": 1
            }'
          ```

          ```js JavaScript theme={null}
          const response = await fetch("https://api.priceos.com/v1/usage", {
            method: "POST",
            headers: {
              "x-api-key": process.env.PRICEOS_API_KEY,
              "Content-Type": "application/json",
            },
            body: JSON.stringify({
              customerId: "customer_123",
              featureKey: "team_seats",
              amount: 1,
            }),
          });

          const result = await response.json();
          ```

          ```py Python theme={null}
          import requests

          response = requests.post(
            "https://api.priceos.com/v1/usage",
            headers={
              "x-api-key": "PRICEOS_API_KEY",
              "Content-Type": "application/json",
            },
            json={
              "customerId": "customer_123",
              "featureKey": "team_seats",
              "amount": 1,
            },
          )

          result = response.json()
          ```
        </CodeGroup>

        For more details, see [Tracking Usage](/tracking-usage).
      </Step>
    </Steps>
  </Tab>
</Tabs>
