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

# Create a subscription

> Subscribes the customer to the product and opens the first billing period. The response carries the subscription and that period.

`customerId` is the customer's product enrollment id (from `POST /metering/products/{productID}/customers`), not the customer id.




## OpenAPI

````yaml /api-reference/openapi.en.json post /billing/products/{productID}/subscriptions
openapi: 3.1.0
info:
  title: Infi API
  version: 0.0.1
  description: >
    The Infi REST API: catalog, customers, usage metering, subscriptions,

    invoices, payments and checkout.


    **Authentication.** Send your secret key as `Authorization: Bearer
    sk_test_…`

    (sandbox) or `sk_live_…` (production). The key prefix selects the
    environment.

    Checkout routes (`/pay/*`) and `/public/*` take no key: they run in the

    payer's browser.


    **Idempotency.** Every request that changes data requires an

    `Idempotency-Key` header. A retry with the same key returns the original

    response instead of running again.


    **Amounts.** Money and quantities travel as decimal strings (`"150.00"`,

    `"0.0001"`), never as floating-point numbers.


    **Errors.** The body carries `error_code` (stable, branch on it), `message`

    (for humans) and `tracer_id` (send it to support). Rate-limit and
    idempotency

    errors are nested under `error`, with `code` and `request_id`.
servers:
  - url: https://api-sandbox.beinfi.com
    description: Sandbox
  - url: https://api.beinfi.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Catalog
  - name: Customers
  - name: Metering
  - name: Subscriptions
  - name: Invoices
  - name: Payments
  - name: Checkout
  - name: Coupons
  - name: Billing
  - name: Account
  - name: Webhooks
  - name: Test account
  - name: Rail
  - name: Storefronts
paths:
  /billing/products/{productID}/subscriptions:
    parameters:
      - $ref: '#/components/parameters/ProductID'
    post:
      tags:
        - Subscriptions
      summary: Create a subscription
      description: >
        Subscribes the customer to the product and opens the first billing
        period. The response carries the subscription and that period.


        `customerId` is the customer's product enrollment id (from `POST
        /metering/products/{productID}/customers`), not the customer id.
      operationId: createSubscription
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - customerId
              properties:
                customerId:
                  type: string
                  format: uuid
                  description: The customer's enrollment id for this product.
                productVersionId:
                  type:
                    - string
                    - 'null'
                  format: uuid
                  description: >-
                    The product version the subscription bills. Defaults to the
                    latest published version.
                anchor:
                  type:
                    - string
                    - 'null'
                  format: date-time
                  description: >-
                    When the billing cycle starts, which sets the day of later
                    charges. Defaults to the time of creation.
                items:
                  type: array
                  items:
                    type: object
                    required:
                      - kind
                    properties:
                      kind:
                        type: string
                        enum:
                          - recurring_fee
                          - credit_grant
                          - metered_usage
                      timing:
                        type:
                          - string
                          - 'null'
                        enum:
                          - advance
                          - arrears
                          - null
                  description: >
                    What the subscription bills, item by item. Each item has a
                    `kind`: `recurring_fee` (a fixed fee, with `timing`
                    `advance` to bill at the start of the period or `arrears` to
                    bill at the end; defaults to `advance`), `credit_grant`
                    (credits granted each cycle) or `metered_usage` (metered
                    usage, billed at the end of the period). Only
                    `recurring_fee` takes `timing`. When omitted, items follow
                    the product's pricing model: a prepaid product bills the fee
                    up front and grants credits; any other bills the fee and
                    usage at the end of the period.
      responses:
        '201':
          content:
            application/json:
              schema:
                type: object
                properties:
                  subscription:
                    $ref: '#/components/schemas/Subscription'
                  period:
                    $ref: '#/components/schemas/SubscriptionPeriod'
          description: Created.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/ValidationFailed'
components:
  parameters:
    ProductID:
      name: productID
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Product ID.
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
      description: >-
        A unique key per operation (a UUID works). Retrying with the same key
        returns the original response.
  schemas:
    Subscription:
      type: object
      properties:
        id:
          type: string
          format: uuid
        customerId:
          type: string
          format: uuid
          description: Enrollment ID.
        productVersionId:
          type: string
          format: uuid
          description: >-
            The product version subscribed to. It sets the price billed, even if
            the product changes later.
        status:
          type: string
          enum:
            - trialing
            - active
            - past_due
            - paused
            - canceled
        billingCycle:
          type: string
          enum:
            - weekly
            - monthly
            - annual
        collectionMethod:
          type: string
          enum:
            - charge_automatically
            - send_invoice
          description: >-
            `charge_automatically` charges on its own; `send_invoice` sends the
            invoice for the customer to pay.
        billingMode:
          type: string
          enum:
            - arrears
            - advance
          description: '`advance` bills at the start of the period; `arrears`, at the end.'
        anchor:
          type: string
          format: date-time
          description: Reference date the billing periods are counted from.
        nextBillingDate:
          type:
            - string
            - 'null'
          format: date-time
          description: Next billing date.
        startedAt:
          type: string
          format: date-time
        canceledAt:
          type:
            - string
            - 'null'
          format: date-time
        items:
          type: array
          items:
            $ref: '#/components/schemas/SubscriptionItem'
          description: What the subscription bills or grants.
    SubscriptionPeriod:
      type: object
      properties:
        id:
          type: string
          format: uuid
        subscriptionId:
          type: string
          format: uuid
        periodStart:
          type: string
          format: date-time
          description: Start of the period (inclusive).
        periodEnd:
          type: string
          format: date-time
          description: End of the period (exclusive).
        status:
          type: string
          enum:
            - open
            - closed
            - invoiced
          description: >-
            `open` (collecting usage), `closed` (ended, invoice not generated
            yet) or `invoiced` (already billed).
        invoiceId:
          type:
            - string
            - 'null'
          format: uuid
          description: The invoice that billed this period
      description: >-
        One billing window of a subscription. Metered usage lands in the open
        period.
    SubscriptionItem:
      type: object
      properties:
        id:
          type: string
          format: uuid
        kind:
          type: string
          enum:
            - recurring_fee
            - credit_grant
            - metered_usage
            - prepaid_usage
          description: >-
            `recurring_fee` is the fixed recurring fee; `credit_grant`, credits
            granted each cycle; `metered_usage`, usage billed afterwards;
            `prepaid_usage`, usage paid upfront.
        timing:
          type:
            - string
            - 'null'
          enum:
            - advance
            - arrears
            - null
          description: '`advance` bills at the start of the period; `arrears`, at the end.'
        productVersionId:
          type: string
          format: uuid
          description: The product version the item comes from.
        createdAt:
          type: string
          format: date-time
        canceledAt:
          type:
            - string
            - 'null'
          format: date-time
    Error:
      type: object
      required:
        - message
        - error_code
        - tracer_id
      properties:
        message:
          type: string
          description: Human-readable sentence.
        error_code:
          $ref: '#/components/schemas/ErrorCode'
          description: Stable error code. Branch on it.
        tracer_id:
          type: string
          description: Request id. Include it when contacting support.
      description: >-
        The standard error body. It is flat (no `error` wrapper) and the trace
        id is `tracer_id`.
    ValidationError:
      type: object
      required:
        - message
        - error_code
        - tracer_id
        - errors
      properties:
        message:
          type: string
        error_code:
          $ref: '#/components/schemas/ErrorCode'
        tracer_id:
          type: string
        errors:
          type: array
          items:
            type: object
            required:
              - field
              - value
              - constraint
              - description
            properties:
              field:
                type: string
              value:
                type: string
              constraint:
                type: string
              description:
                type: string
          description: >-
            Per-field detail (`field`, `description`). Always present on a
            `422`; may be empty.
      description: >-
        Body of a `422`. Same shape as `Error`, plus `errors[]` with per-field
        detail. That is where the sentence telling you what to fix lives (for
        example, "product has no published version").
    ErrorCode:
      type: string
      examples:
        - internal_error
        - validation_failed
        - bad_request
        - unauthorized
        - forbidden
        - not_found
        - conflict
        - rate_limited
      description: >-
        Stable error code. The list is open: besides the generic codes, each
        area defines its own (`coupon_expired`, `insufficient_balance`,
        `version_not_draft`, `idempotency_key_reused`…). Handle a code you do
        not recognize by its HTTP status and show `message`; do not fail parsing
        the response.
  responses:
    BadRequest:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      description: Malformed request.
    Unauthorized:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      description: Missing or invalid API key.
    ValidationFailed:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
      description: One or more fields are invalid. Per-field detail is in `errors[]`.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your account's secret key: `Authorization: Bearer sk_test_…` or
        `sk_live_…`. Server-side only.

````