> ## 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 link with a product

> From nothing to a payable URL in one call. The product is identified by its `key`: a new key creates it, a known one reuses it, and pricing that differs from the current one publishes a new version. Links already shared keep selling the price they advertised.

Every call creates a new link, so you can have one URL per campaign. The response carries the `url` to send the payer; you do not need to pass your account slug.




## OpenAPI

````yaml /api-reference/openapi.en.json post /payment-links
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:
  /payment-links:
    post:
      tags:
        - Catalog
      summary: Create a link with a product
      description: >
        From nothing to a payable URL in one call. The product is identified by
        its `key`: a new key creates it, a known one reuses it, and pricing that
        differs from the current one publishes a new version. Links already
        shared keep selling the price they advertised.


        Every call creates a new link, so you can have one URL per campaign. The
        response carries the `url` to send the payer; you do not need to pass
        your account slug.
      operationId: createPaymentLinkWithProduct
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePaymentLinkWithProductRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentLink'
          description: Link created.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
          description: >-
            Invalid product definition: a missing `key`, a `billingCycle` that
            contradicts the `pricingModel`, or a price the model requires is
            missing.
      security:
        - BearerAuth: []
components:
  schemas:
    CreatePaymentLinkWithProductRequest:
      type: object
      required:
        - product
      properties:
        product:
          $ref: '#/components/schemas/InlineProductSpec'
          description: The product, defined inline and identified by its `key`.
        successUrl:
          type:
            - string
            - 'null'
          maxLength: 2048
          description: >-
            Where the payer goes after paying, with `?status=success&invoice=…`
            appended. Absolute `http(s)` URL.
        cancelUrl:
          type:
            - string
            - 'null'
          maxLength: 2048
          description: >-
            Offered to the payer as "back to the store" while the checkout is
            open. Absolute `http(s)` URL.
    PaymentLink:
      type: object
      properties:
        id:
          type: string
          format: uuid
        productId:
          type: string
          format: uuid
        token:
          type: string
          description: The link's public token, part of the `url`.
        url:
          type: string
          description: >-
            The address to send the payer. Use this value instead of building
            the URL yourself.
        productVersionId:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            The product version this link sells, fixed at creation. Publishing a
            new version does not reprice a link already issued. When `null`, the
            link sells the latest published version at payment time.
        active:
          type: boolean
          description: '`false` once revoked.'
        revokedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the link was revoked.
        createdAt:
          type: string
          format: date-time
        successUrl:
          type:
            - string
            - 'null'
          description: >-
            Where the payer goes after paying, with `?status=success&invoice=…`
            appended.
        cancelUrl:
          type:
            - string
            - 'null'
          description: >-
            Offered to the payer as "back to the store" while the checkout is
            open; also the `?status=error` destination when the charge expires
            in the embedded checkout.
      description: >-
        A reusable, revocable payment link bound to a product. Anyone holding it
        can open the checkout; it is meant to be copied and shared.
    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").
    InlineProductSpec:
      type: object
      required:
        - key
        - pricingModel
      properties:
        key:
          type: string
          description: >-
            Stable product key, unique in your account. Required: it is what
            makes two calls for the same product resolve to one product.
        name:
          type: string
          description: Display name. Defaults to `key`.
        type:
          type: string
          enum:
            - agent
            - item
          description: '`item` (default) or `agent`.'
        description:
          type:
            - string
            - 'null'
        pricingModel:
          type: string
          enum:
            - subscription
            - one_time
            - usage
            - prepaid
          description: '`subscription`, `one_time`, `usage` or `prepaid`.'
        currency:
          type: string
          minLength: 3
          maxLength: 3
          description: '3-letter ISO 4217 code. Default: `BRL`.'
        billingCycle:
          type:
            - string
            - 'null'
          enum:
            - weekly
            - monthly
            - annual
            - null
          description: Required for `subscription` and `prepaid`; omit it for other models.
        basePrice:
          type:
            - string
            - 'null'
          description: Base price as a decimal string (`"49.90"`).
        meters:
          type: array
          items:
            $ref: '#/components/schemas/InlineMeterSpec'
          description: >-
            The product's meters, created once by `name`. A meter that already
            exists is not changed by this call.
        prices:
          type: array
          items:
            $ref: '#/components/schemas/InlinePriceSpec'
          description: >-
            The version's complete price list. A list that differs from the
            current version publishes a new version. Omit the field to leave
            prices alone; an empty array means "no prices".
      description: >-
        A product defined on link creation, identified by its `key`. A new key
        creates the product; a known key reuses it, and pricing that differs
        from the current version publishes a new version. Links already in
        circulation keep selling what they advertised.
    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`.
    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.
    InlineMeterSpec:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: The key you send in `track()`. Cannot change after creation.
        displayName:
          type: string
        unit:
          type: string
          enum:
            - token
            - request
            - unit
          description: '`token`, `request` or `unit`.'
        aggregation:
          type: string
          enum:
            - sum
            - count
            - unique_count
            - max
            - last
          description: '`sum`, `count`, `unique_count`, `max` or `last`.'
        valueProperty:
          type:
            - string
            - 'null'
          description: Event field carrying the numeric value. Unused with `count`.
    InlinePriceSpec:
      type: object
      required:
        - meter
        - model
      properties:
        meter:
          type: string
          description: >-
            The `name` of the meter this price rates. Required: an amount with
            no meter is the product's `basePrice`.
        model:
          type: string
          enum:
            - flat
            - per_unit
            - tiered
            - volume
            - package
          description: '`flat`, `per_unit`, `tiered`, `volume` or `package`.'
        unitAmount:
          type:
            - string
            - 'null'
          description: Amount per unit as a decimal string.
        tiers:
          type: object
          description: Price tiers for `tiered`, `volume` and `package`.
        currency:
          type: string
          minLength: 3
          maxLength: 3
          description: Optional; defaults to the product's currency.
  responses:
    Unauthorized:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      description: Missing or invalid API key.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your account's secret key: `Authorization: Bearer sk_test_…` or
        `sk_live_…`. Server-side only.

````