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

# Create an invoice

> Creates an ad-hoc invoice for a customer. Callers can supply line items, a billing period, purchase order number, and an initial status (`draft` or `issued`). Requesting `issued` releases the invoice for issuance, which completes asynchronously — the response returns the invoice in `processing` and it settles to `issued` shortly after, observable via the Get Invoice endpoint. Alternatively, pass `tax_calculation_id` to turn a persisted tax calculation into an invoice: its line items, tax, and buyer are pinned and the invoice is issued synchronously; add a `payment` and `status: paid` to record settlement and mark it paid in the same call.



## OpenAPI

````yaml /api-reference/specs/2026-04-01.json post /invoices
openapi: 3.1.0
info:
  description: >-
    Alguna is the AI-native quote-to-revenue platform for B2B companies: CPQ,
    subscription and usage-based billing, invoicing, payment collection, and
    revenue recognition in one system of record. The API operates on one
    versioned agreement per customer: quotes, subscriptions and their versions,
    usage, invoices, payments, and revenue schedules read from it. Official
    SDKs: TypeScript (@alguna/sdk), Python (alguna), Go
    (github.com/alguna-io/alguna-go), Rust (alguna), and the alguna CLI
    (@alguna/cli).
  title: Alguna Public API
  version: '2026-04-01'
servers:
  - url: https://api.alguna.io
    x-fern-server-name: Production
security:
  - bearerAuth: []
tags:
  - name: Billing Events and Metrics
  - name: Checkout Sessions
  - name: Credit Notes
  - name: Credits
  - name: Customer Portal Sessions
  - name: Customers
  - name: Feedback
  - name: Insights
  - name: Integrations
  - name: Invoices
  - name: Merchants
  - name: Payments
  - name: Plans
  - name: Product Bundles
  - name: Products
  - name: Quotes
  - name: Refunds
  - name: Revenue Schedules
  - name: Subscription Changes
  - name: Subscription Versions
  - name: Subscriptions
  - name: Tags
  - name: Tax
  - name: Users
  - name: Wallet Grants
  - name: Wallets
paths:
  /invoices:
    post:
      tags:
        - Invoices
      summary: Create an invoice
      description: >-
        Creates an ad-hoc invoice for a customer. Callers can supply line items,
        a billing period, purchase order number, and an initial status (`draft`
        or `issued`). Requesting `issued` releases the invoice for issuance,
        which completes asynchronously — the response returns the invoice in
        `processing` and it settles to `issued` shortly after, observable via
        the Get Invoice endpoint. Alternatively, pass `tax_calculation_id` to
        turn a persisted tax calculation into an invoice: its line items, tax,
        and buyer are pinned and the invoice is issued synchronously; add a
        `payment` and `status: paid` to record settlement and mark it paid in
        the same call.
      operationId: create-invoice
      parameters:
        - in: header
          name: Alguna-Version
          required: true
          schema:
            enum:
              - '2026-04-01'
            type: string
        - in: header
          name: Idempotency-Key
          schema:
            description: >-
              A unique string that makes a retried write safe. If you send the
              same request with the same key within 24 hours, the API returns
              the stored response and does not run the request again. A 5xx or
              429 response is not stored, so a retry with that key runs the
              request again.
            example: ik_a1b2c3d4e5f6
            maxLength: 255
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInvoiceRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvoiceResponse'
          description: Success
          headers:
            Idempotency-Key:
              description: Echo of the idempotency key provided in the request
              schema:
                type: string
            Idempotent-Replayed:
              description: >-
                Whether this response was replayed from a previous request
                (true) or freshly executed (false)
              schema:
                type: boolean
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorResponse'
                  - $ref: '#/components/schemas/GatewayErrorResponse'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Forbidden — the organization does not have access to this feature
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not Found
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            Conflict — a request with this idempotency key is currently being
            processed
          headers:
            Retry-After:
              description: >-
                Seconds to wait before retrying with the same idempotency key.
                Sent only when a request with this key is still being processed;
                a 409 without it is a conflict that a retry will not resolve.
              schema:
                type: integer
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unprocessable Entity
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal Server Error
        '502':
          description: >-
            Bad Gateway — sent by the infrastructure in front of the API; the
            body is not JSON. Safe to retry.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            Service Unavailable — a dependency is temporarily unavailable. Retry
            with backoff.
        '504':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: >-
            Gateway Timeout — the request did not finish in time. Retry with
            backoff; use an idempotency key for writes.
components:
  schemas:
    CreateInvoiceRequest:
      properties:
        autopay_timing:
          allOf:
            - $ref: '#/components/schemas/AutopayTiming'
          description: >-
            When auto-pay charges the invoice. on_issue: when the invoice is
            issued. on_due_date: on the invoice's due date. Omit it to inherit
            the customer's Autopay Timing. Not allowed with tax_calculation_id.
          example: on_due_date
          nullable: true
        billing_period_end:
          description: >-
            End of the invoice's billing period, exclusive: for a period through
            31 January send 2026-02-01T00:00:00Z. Send with
            billing_period_start.
          example: '2026-02-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        billing_period_start:
          description: >-
            Start of the invoice's billing period, inclusive. Send with
            billing_period_end.
          example: '2026-01-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        currency:
          description: ISO 4217 currency code; required unless tax_calculation_id is set
          example: USD
          type: string
        customer_id:
          description: >-
            Existing customer to bill. On the tax_calculation_id path, leave
            empty to mint a guest customer from the calculation's buyer.
          type: string
        description:
          description: Invoice description or memo
          nullable: true
          type: string
        issue_date:
          description: Date to issue the invoice
          format: date-time
          nullable: true
          type: string
        line_items:
          description: Line items to include on the invoice
          items:
            $ref: '#/components/schemas/CreateInvoiceLineItemRequest'
          type: array
        merchant_id:
          description: >-
            Existing sub-merchant the invoice is issued for; you remain the
            seller of record. Create the merchant before referencing it here.
            Optional alongside tax_calculation_id, where it must match the
            merchant the calculation was made for. Requires the merchants
            entitlement
          example: mrch_01H8XGJWBWBAQ4PLwXYZ
          nullable: true
          type: string
        payment:
          allOf:
            - $ref: '#/components/schemas/InvoicePaymentRequest'
          description: >-
            Record the customer's already-settled payment and mark the invoice
            paid in the same call; requires tax_calculation_id
          nullable: true
        purchase_order_number:
          description: Purchase order number
          nullable: true
          type: string
        status:
          description: >-
            Initial invoice status. Defaults to draft. Setting issued releases
            the invoice for issuance, which completes asynchronously: the
            response returns the invoice in processing, and it settles to issued
            shortly after — poll the Get Invoice endpoint to observe the final
            status. paid is only valid on the tax_calculation_id path and must
            be sent together with a payment.
          enum:
            - draft
            - issued
            - paid
          nullable: true
          type: string
        tax_calculation_id:
          description: >-
            Id of a persisted tax calculation; its stored line items, tax
            amounts, and buyer become the invoice, which is issued synchronously
            with no recalculation. Mutually exclusive with line_items (the
            calculation supplies them). Leave status unset or set it to issued
            to issue the invoice; set status to paid together with a payment to
            also mark it paid.
          nullable: true
          type: string
      type: object
    InvoiceResponse:
      properties:
        amount_paid:
          description: Amount that has been paid
          example: '0.00'
          type: string
        amount_remaining:
          description: Remaining amount due
          example: '110.00'
          type: string
        autopay_timing:
          allOf:
            - $ref: '#/components/schemas/AutopayTiming'
          description: >-
            When auto-pay charges the invoice. Before issue, it is null when the
            invoice inherits the value of its subscription or customer. At
            issue, the resolved value is saved on the invoice. Invoices issued
            without a value are charged when they are issued.
          example: on_due_date
          nullable: true
        billing_period:
          description: Formatted billing period string
          type: string
        billing_period_end:
          description: End of the billing period
          format: date-time
          nullable: true
          type: string
        billing_period_start:
          description: Start of the billing period
          format: date-time
          nullable: true
          type: string
        created_at:
          description: Timestamp when the invoice was created
          format: date-time
          type: string
        currency:
          description: ISO 4217 currency code
          example: USD
          type: string
        customer_id:
          description: Customer this invoice belongs to
          type: string
        description:
          description: Invoice description or memo
          type: string
        due_date:
          description: Date the invoice payment is due
          format: date-time
          nullable: true
          type: string
        external_id:
          description: Identifier in the external payment provider
          type: string
        external_provider:
          description: External payment provider name
          type: string
        external_reference:
          description: Customer-facing invoice reference number
          type: string
        external_url:
          description: URL to the invoice in the external system
          type: string
        id:
          description: Unique identifier for the invoice
          type: string
        invoicing_date:
          description: Date the invoice is scheduled for processing
          format: date-time
          nullable: true
          type: string
        issue_date:
          description: Date the invoice was issued
          format: date-time
          nullable: true
          type: string
        line_items:
          description: Line items on this invoice
          items:
            $ref: '#/components/schemas/LineItemResponse'
          type: array
        merchant_id:
          description: >-
            Sub-merchant the invoice was issued for; you remain the seller of
            record
          example: mrch_01H8XGJWBWBAQ4PLwXYZ
          nullable: true
          type: string
        paid_date:
          description: Date the invoice was paid
          format: date-time
          nullable: true
          type: string
        purchase_order_number:
          description: Purchase order number
          nullable: true
          type: string
        status:
          allOf:
            - $ref: '#/components/schemas/InvoiceStatus'
          description: Current status of the invoice
        subtotal:
          description: Sum of all line item totals before tax
          example: '100.00'
          type: string
        tax:
          description: Total tax amount
          example: '10.00'
          type: string
        tax_calculation_id:
          description: Id of the tax calculation this invoice was created from, if any
          nullable: true
          type: string
        total:
          description: Total amount including tax
          example: '110.00'
          type: string
        updated_at:
          description: Timestamp when the invoice was last updated
          format: date-time
          type: string
      required:
        - amount_paid
        - amount_remaining
        - billing_period
        - created_at
        - currency
        - customer_id
        - description
        - id
        - line_items
        - status
        - subtotal
        - tax
        - total
        - updated_at
      type: object
    ErrorResponse:
      description: The body of every error the API returns.
      properties:
        code:
          description: >-
            Machine-readable error code, such as `not_found` or
            `invoice_already_issued`. New codes may be added at any time, so
            handle a code you do not know by its HTTP status.
          type: string
        detail:
          description: Explanation of what went wrong
          type: string
        request_id:
          description: >-
            Identifies the request, as the `X-Request-Id` response header does.
            Quote it when contacting support.
          type: string
        status:
          description: HTTP status code of the response
          format: int64
          type: integer
        title:
          description: >-
            HTTP status text. Sent only by version, idempotency and
            credit-refusal errors.
          type: string
        type:
          description: Always `about:blank`. Sent only by version and idempotency errors.
          type: string
      required:
        - status
        - detail
      type: object
    GatewayErrorResponse:
      description: >-
        Returned by the API gateway when a request carries no valid API key,
        before the API handles it.
      properties:
        code:
          description: Machine-readable error code, e.g. `unauthenticated`
          type: string
        details:
          nullable: true
          type: object
        message:
          description: Explanation of what went wrong
          type: string
      required:
        - code
        - message
      type: object
    AutopayTiming:
      enum:
        - on_issue
        - on_due_date
      type: string
    CreateInvoiceLineItemRequest:
      properties:
        billing_period_end:
          description: >-
            End of the service period this line covers, exclusive: for a period
            through 31 January send 2026-02-01T00:00:00Z. Send with
            billing_period_start.
          example: '2026-02-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        billing_period_start:
          description: >-
            Start of the service period this line covers, inclusive. Send with
            billing_period_end.
          example: '2026-01-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        description:
          description: Description of the line item
          nullable: true
          type: string
        product_id:
          description: Associated product identifier
          nullable: true
          type: string
        quantity:
          description: Quantity of the line item
          example: '1'
          type: string
        unit_price:
          description: >-
            Unit price of the line item, excluding tax. Tax is calculated on top
            of it.
          example: '100.00'
          type: string
      required:
        - quantity
        - unit_price
      type: object
    InvoicePaymentRequest:
      properties:
        note:
          description: Free-text note about the payment
          nullable: true
          type: string
        paid_at:
          description: Business date of the payment; defaults to now
          format: date-time
          nullable: true
          type: string
        reference:
          description: Your payment reference (e.g. PSP charge id)
          nullable: true
          type: string
        source:
          description: How the customer paid
          enum:
            - bank_transfer
            - payment_card
            - cash
            - cheque
            - other
          example: payment_card
          type: string
      required:
        - source
      type: object
    LineItemResponse:
      properties:
        amount_excluding_tax:
          description: Amount for this line before tax (quantity x unit price)
          example: '73.98'
          type: string
        amount_including_tax:
          description: >-
            Amount for this line including its tax. This is the figure a full
            credit of the line returns.
          example: '80.55'
          type: string
        billing_period_end:
          description: End of the service period this line covers, exclusive
          format: date-time
          nullable: true
          type: string
        billing_period_start:
          description: Start of the service period this line covers, inclusive
          format: date-time
          nullable: true
          type: string
        description:
          description: Description of the line item
          type: string
        id:
          description: Unique identifier for the line item
          type: string
        is_editable:
          description: Whether this line item can be manually edited
          type: boolean
        product_id:
          description: Associated product identifier
          nullable: true
          type: string
        quantity:
          description: Quantity of the line item
          example: '1'
          type: string
        tax_amount:
          description: Tax charged on this line
          example: '6.57'
          nullable: true
          type: string
        tax_rate:
          description: Percentage rate the tax was charged at
          example: '8.875'
          nullable: true
          type: string
        total_price:
          deprecated: true
          description: >-
            Deprecated: use amount_excluding_tax, which carries the same value.
            Despite the name this excludes tax.
          example: '100.00'
          type: string
        unit_price:
          description: Unit price of the line item, excluding tax
          example: '100.00'
          type: string
      required:
        - amount_excluding_tax
        - amount_including_tax
        - description
        - id
        - is_editable
        - quantity
        - total_price
        - unit_price
      type: object
    InvoiceStatus:
      enum:
        - draft
        - upcoming
        - pending_approval
        - scheduled
        - processing
        - issued
        - void
        - paid
        - canceled
        - overdue
      type: string
  securitySchemes:
    bearerAuth:
      bearerFormat: API Key
      description: API key authentication. Pass your API key as a Bearer token.
      scheme: bearer
      type: http
      x-fern-bearer:
        env: ALGUNA_API_KEY
        name: apiKey

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.