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

# Create and stamp a CFDI 4.0 invoice via the configured PAC

> Authenticate with either a Supabase session (send the `X-Organization-Id` header, must be a member of that organization) or an API key (external integrations, requires the `write:invoices` scope — the organization is resolved from the key). The customer can be sent inline (`customer`) or referenced by ID (`customerId`).



## OpenAPI

````yaml https://api.timbrix.mx/api/openapi.json post /invoices
openapi: 3.0.0
info:
  title: Timbrix API
  description: >-
    API de facturación electrónica CFDI 4.0 para México, con servidor OAuth2
    para gestionar organizaciones, miembros y webhooks. Compatible con agentes
    de IA — ver la extensión `x-ai-agent-friendly` en la raíz de esta spec.


    REST API with OAuth2 server for managing organizations, members, and
    webhooks.
  version: '1.0'
  contact: {}
servers: []
security: []
tags:
  - name: organizations
    description: Organization management endpoints
  - name: oauth
    description: OAuth2 authentication and authorization
  - name: webhooks
    description: Webhook configuration and delivery
  - name: users
    description: User information endpoints
  - name: api-keys
    description: API Keys management and validation
paths:
  /invoices:
    post:
      tags:
        - invoices
      summary: Create and stamp a CFDI 4.0 invoice via the configured PAC
      description: >-
        Authenticate with either a Supabase session (send the
        `X-Organization-Id` header, must be a member of that organization) or an
        API key (external integrations, requires the `write:invoices` scope —
        the organization is resolved from the key). The customer can be sent
        inline (`customer`) or referenced by ID (`customerId`).
      operationId: InvoicesController_create
      parameters:
        - name: X-Organization-Id
          in: header
          description: >-
            Required for Supabase session auth. Ignored when authenticating with
            an API key (the organization resolves from the key).
          required: false
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInvoiceDto'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvoiceResponseDto'
        '400':
          description: >-
            Invalid invoice payload, or missing X-Organization-Id header for a
            session request
        '404':
          description: customerId not found
        '503':
          description: PAC unavailable
      security:
        - apiKey: []
        - bearer: []
components:
  schemas:
    CreateInvoiceDto:
      type: object
      properties:
        type:
          type: string
          example: I
          enum:
            - I
            - E
            - T
          description: 'Ingreso, Egreso, or Traslado (default: I)'
        relatedInvoiceUuid:
          type: string
          example: d3bfbc57-44af-4390-a064-f0afab85e5df
          description: >-
            Required when `type` is `E` (Egreso/nota de crédito) — UUID fiscal
            of the original Ingreso CFDI it credits. Must belong to this
            organization and be a vigente Ingreso.
        series:
          type: string
          example: A
        folioNumber:
          type: string
          example: '1'
        date:
          type: string
          example: '2026-07-30T22:50:00'
        paymentForm:
          type: string
          example: '01'
          description: >-
            SAT forma de pago catalog code — required unless `type` is `T`
            (Traslado)
        paymentMethod:
          type: string
          example: PUE
          enum:
            - PUE
            - PPD
          description: 'Default: PUE'
        currency:
          type: string
          example: MXN
          description: 'Default: MXN'
        exchange:
          type: number
          example: 1
          description: 'Default: 1'
        export:
          type: string
          example: '01'
          description: 'SAT clave de exportación catalog code — default: 01'
        use:
          type: string
          example: G03
          description: SAT uso CFDI catalog code
        customer:
          $ref: '#/components/schemas/InvoiceCustomerDto'
        customerId:
          type: string
          description: Existing customer ID — mutually exclusive with `customer`
        items:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceItemDto'
        idempotencyKey:
          type: string
          description: >-
            Client-supplied key to safely retry this request without
            double-stamping. If an invoice was already created for this
            organization with the same key, that invoice is returned instead of
            stamping again.
          example: order-8421-attempt-1
      required:
        - series
        - folioNumber
        - date
        - use
        - items
    InvoiceResponseDto:
      type: object
      properties:
        id:
          type: string
          description: Timbrix invoice record ID
          example: 0f2a1c3e-1a2b-4c3d-9e8f-1234567890ab
        uuid:
          type: string
          description: Folio fiscal UUID asignado por el SAT vía PAC
          example: d3bfbc57-44af-4390-a064-f0afab85e5df
        status:
          type: string
          enum:
            - valid
          example: valid
        type:
          type: string
          enum:
            - I
            - E
            - T
          example: I
          description: I = Ingreso, E = Egreso, T = Traslado
        series:
          type: string
          example: A
        folioNumber:
          type: string
          example: '1'
        total:
          type: number
          example: 116
        date:
          type: string
          example: '2026-07-30T22:50:00'
        xml:
          type: string
          description: XML del CFDI timbrado (UTF-8)
        createdAt:
          type: string
          example: '2026-07-30T22:50:03.412Z'
        environment:
          type: string
          enum:
            - sandbox
            - production
          example: production
          description: >-
            Ambiente en el que se timbró el CFDI. Los CFDI de sandbox no tienen
            validez fiscal ante el SAT.
      required:
        - id
        - uuid
        - status
        - type
        - series
        - folioNumber
        - total
        - date
        - xml
        - createdAt
        - environment
    InvoiceCustomerDto:
      type: object
      properties:
        legalName:
          type: string
          example: ESCUELA KEMPER URGATE SA DE CV
        taxId:
          type: string
          example: EKU9003173C9
        taxSystem:
          type: string
          example: '601'
          description: >-
            SAT régimen fiscal code — required unless the customer is público en
            general
        zip:
          type: string
          example: '45079'
      required:
        - legalName
        - taxId
    InvoiceItemDto:
      type: object
      properties:
        quantity:
          type: number
          example: 1
        productId:
          type: string
          description: >-
            Existing product/service ID — mutually exclusive with
            `productKey`/`unitKey`/`description`/`unitPrice` (inline concept
            data)
        description:
          type: string
          example: Servicio de consultoría
          description: Required unless `productId` is provided
        unitPrice:
          type: number
          example: 100
          description: Required unless `productId` is provided
        amount:
          type: number
          example: 100
        productKey:
          type: string
          example: '84111506'
          description: Required unless `productId` is provided
        unitKey:
          type: string
          example: E48
          description: Required unless `productId` is provided
        unit:
          type: string
          example: E48
        taxObject:
          type: string
          example: '02'
        taxes:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceTaxDto'
      required:
        - quantity
        - amount
    InvoiceTaxDto:
      type: object
      properties:
        type:
          type: string
          example: '002'
        factorType:
          type: string
          example: Tasa
        rate:
          type: string
          example: '0.160000'
        base:
          type: number
          example: 100
        amount:
          type: number
          example: 16
        withholding:
          type: boolean
          description: >-
            true = retención (Impuestos.Retenciones), false/omitted = traslado
            (Impuestos.Traslados)
          example: false
      required:
        - type
        - factorType
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: 'API Key for authentication (format: sk_...)'
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http

````