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

# Provision a client company as a tenant

> Creates the tenant of a client company, identified by its NIT, and stores the client's written authorization of the partner (date, text version and where the partner keeps the signed copy). **Idempotent per NIT**: when this partner already has a tenant for the NIT, the same company data answers `200` with `created: false` and issues no key (a key is shown once and never stored); other data answers `409 tenant_nit_conflict`. The tenant starts in the DIAN test stage with no issuer: set it with the tenant's test key (`PUT /v1/tenant/issuer`), and its NIT must be this one (`409 issuer_nit_locked` otherwise).



## OpenAPI

````yaml /openapi.json post /v1/partner/tenants
openapi: 3.1.0
info:
  description: >
    Cufea issues Colombian electronic invoices and related documents through the
    DIAN.

    Every API key drives one stage: `cufea_sandbox_` keys Cufea's simulated DIAN
    (no

    certificate or DIAN credentials needed), `cufea_test_` keys the DIAN
    habilitación (test)

    environment and `cufea_prod_` keys the DIAN production environment, which
    opens per tenant

    only after the operator promotes it. A key sees only the documents of its
    own stage.


    **Cufea owns** the DIAN logic: XML generation, CUFE/CUDE, signing,
    submission, status

    tracking, numbering, credit/debit notes and RADIAN events. It keeps a
    minimal registry

    (numbering, event chain, state, signed XML and DIAN responses) and always
    returns the

    signed XML.


    Credit (91) and debit (92) notes reference an invoice the DIAN accepted;
    they carry their

    own CUDE and are numbered by the client's series.


    How a document reaches the DIAN depends on the stage. In the test stage,
    until the DIAN

    accepts the tenant's habilitacion test set, the worker sends every invoice
    and note with

    SendTestSetAsync to that set and polls GetStatusZip for the answer. The
    first GetStatusZip

    answer that says the set "se encuentra Aceptado" records the acceptance; the
    DIAN closes that

    document without validating it (state `closed`, never accepted), so create
    it again: from then

    on, and always in production, documents go with SendBillSync, whose answer
    is final.


    **You own** your business data (customers, products, accounting), your RUT,
    your

    numbering resolution and your DIAN habilitacion.


    Authenticate every request except `/v1/health` with `Authorization: Bearer
    <api key>`.

    Resellers provision their clients' tenants under `/v1/partner` with a
    partner key

    (`cufea_partner_`), which only those routes accept (see the `partner`
    section).

    Errors are `application/problem+json` (RFC 9457) and carry a `request_id`
    that matches

    the `X-Request-ID` response header; quote it when asking for support.


    Each API key (tenant or partner) has its own quota, 120 requests per minute
    by default, in a

    fixed window aligned to the minute. Every response of a route that takes a
    key carries

    `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` (whole
    seconds until the

    window restarts); over the quota the answer is `429 rate_limited` with
    `Retry-After` in whole

    seconds. The edge also limits requests per client IP.


    Creating and sending documents accept an `Idempotency-Key` header: a retry
    with the same key

    and body returns the stored answer (with `Idempotent-Replayed: true`)
    instead of acting twice.

    Sending is asynchronous: it answers `202` and a worker talks to the DIAN;
    follow the outcome

    by reading the document back or by registering a webhook endpoint, whose
    deliveries are

    signed with `X-Cufea-Signature` (see the `webhooks` section).


    The guides, the error catalog and this reference live at
    https://docs.cufea.com. New here?

    Sign up in the developer console for a sandbox key and follow the quickstart

    (https://docs.cufea.com/quickstart): a first invoice, its status and a
    verified webhook in

    minutes.
  summary: 'DIAN electronic invoicing: sandbox, test and production stages'
  title: Cufea API
  version: 0.8.0
servers:
  - description: Cufea API
    url: https://api.cufea.com
security: []
tags:
  - description: Service liveness.
    name: system
  - description: >-
      The account behind the API key: its configuration, secrets (write-only)
      and API keys.
    name: tenant
  - description: >-
      Register HTTPS endpoints that receive signed event deliveries
      (`invoice.accepted`, `invoice.rejected`, `note.accepted`, `note.rejected`,
      `event.registered`, and the buyer email outcomes `invoice.delivered`,
      `invoice.delivery_failed`, `note.delivered`, `note.delivery_failed`). The
      signing secret is shown once, on create. The payload and the signature are
      described under the document's `webhooks` section.
    name: webhooks
  - description: >-
      Create signed sales invoices, send them to the DIAN (queued), follow their
      status and get their AttachedDocument. Creating and sending accept an
      `Idempotency-Key` header.
    name: invoices
  - description: >-
      Create signed credit (91) and debit (92) notes on an accepted invoice,
      send them to the DIAN (queued: SendTestSetAsync to the test set until the
      DIAN accepts it, then SendBillSync) and read them back. Creating and
      sending accept an `Idempotency-Key` header.
    name: notes
  - description: >-
      Find an invoice or note by the `reference` you gave on create, e.g. to
      learn for sure whether a create whose answer was lost created the
      document.
    name: documents
  - description: >-
      Schedule RADIAN events (030-034) on an accepted invoice, re-queue a saved
      one and read the event chain. Creating accepts an `Idempotency-Key`
      header.
    name: events
  - description: >-
      For resellers: provision each client company as a tenant of its own (its
      NIT, its certificate) on the client's written authorization, and manage
      that tenant's API keys. Authenticate with a partner key
      (`cufea_partner_`), which the operator issues; it creates no documents and
      reads no secrets.
    name: partner
paths:
  /v1/partner/tenants:
    post:
      tags:
        - partner
      summary: Provision a client company as a tenant
      description: >-
        Creates the tenant of a client company, identified by its NIT, and
        stores the client's written authorization of the partner (date, text
        version and where the partner keeps the signed copy). **Idempotent per
        NIT**: when this partner already has a tenant for the NIT, the same
        company data answers `200` with `created: false` and issues no key (a
        key is shown once and never stored); other data answers `409
        tenant_nit_conflict`. The tenant starts in the DIAN test stage with no
        issuer: set it with the tenant's test key (`PUT /v1/tenant/issuer`), and
        its NIT must be this one (`409 issuer_nit_locked` otherwise).
      operationId: create_tenant_v1_partner_tenants_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartnerTenantIn'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerTenantCreated'
          description: 'The partner already had this tenant (`created: false`).'
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerTenantCreated'
          description: Successful Response
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '401':
          content:
            application/problem+json:
              example:
                code: unauthorized
                detail: Missing or invalid API key.
                request_id: 3668a7374b1e4314b2f932a5620da1f1
                status: 401
                title: Unauthorized
                type: urn:cufea:problem:unauthorized
              schema:
                $ref: '#/components/schemas/Problem'
          description: Missing or invalid partner key.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The partner reached its tenant limit (`partner_tenant_limit`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            The NIT already has a tenant with other data
            (`tenant_nit_conflict`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '422':
          content:
            application/problem+json:
              example:
                code: validation_error
                detail: >-
                  The request is not valid; see `errors` for the offending
                  fields.
                errors:
                  - loc:
                      - body
                      - customer
                    msg: Field required
                  - loc:
                      - body
                      - lines
                    msg: List should have at least 1 item after validation, not 0
                request_id: 88272d6eb903438690d3193e3113270a
                status: 422
                title: Request validation failed
                type: urn:cufea:problem:validation_error
              schema:
                $ref: '#/components/schemas/ValidationProblem'
          description: >-
            Malformed (`validation_error`) or a check digit that does not match
            the NIT (`tenant_invalid`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '429':
          content:
            application/problem+json:
              example:
                code: rate_limited
                detail: >-
                  This API key made more than 120 requests in the current
                  window. Retry after 17 seconds.
                request_id: 5d1c0b6f2e8a4f0c9a7b3e2d1c0f9a8b
                status: 429
                title: Too Many Requests
                type: urn:cufea:problem:rate_limited
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            This API key is over its quota for the current window
            (`rate_limited`). Wait `Retry-After` seconds; a create or send
            retried with its `Idempotency-Key` is safe.
          headers:
            Retry-After:
              $ref: '#/components/headers/Retry-After'
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: Partner services not configured.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
      security:
        - PartnerKeyAuth: []
components:
  schemas:
    PartnerTenantIn:
      additionalProperties: false
      description: >-
        The client company to provision. One tenant per NIT and partner:
        repeating the call

        with the same data answers the existing tenant (`200`, `created:
        false`).
      properties:
        authorization:
          $ref: '#/components/schemas/ClientAuthorizationIn'
        check_digit:
          description: The NIT's check digit (DV), DIAN modulo 11.
          examples:
            - '8'
          pattern: ^[0-9]$
          title: Check Digit
          type: string
        contact_email:
          description: The client's contact email address.
          maxLength: 254
          minLength: 3
          title: Contact Email
          type: string
        issue_keys:
          description: >-
            Stages whose API keys to issue now, each once (a new tenant is in
            test, so production keys come after its promotion). Only a create
            issues them: a repeated call issues none.
          items:
            enum:
              - sandbox
              - test
            type: string
          maxItems: 2
          title: Issue Keys
          type: array
        legal_name:
          description: The client's legal name (razón social); also the tenant's name.
          maxLength: 450
          minLength: 1
          title: Legal Name
          type: string
        nit:
          description: The client's NIT, digits only, without the check digit.
          examples:
            - '900123456'
          pattern: ^[0-9]{5,15}$
          title: Nit
          type: string
      required:
        - nit
        - check_digit
        - legal_name
        - contact_email
        - authorization
      title: PartnerTenantIn
      type: object
    PartnerTenantCreated:
      properties:
        active_keys:
          description: >-
            The tenant's keys that are not revoked: id, prefix and stage, never
            the key.
          items:
            $ref: '#/components/schemas/ApiKeyInfo'
          title: Active Keys
          type: array
        api_keys:
          description: >-
            The keys issued by this call, **shown once**. Empty on a repeated
            call.
          items:
            $ref: '#/components/schemas/ApiKeyCreated'
          title: Api Keys
          type: array
        check_digit:
          title: Check Digit
          type: string
        contact_email:
          title: Contact Email
          type: string
        created:
          description: True when this call created the tenant.
          title: Created
          type: boolean
        created_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Created At
        dian_environment:
          description: '`test` until the tenant is promoted, `production` afterwards.'
          enum:
            - test
            - production
          title: Dian Environment
          type: string
        legal_name:
          title: Legal Name
          type: string
        nit:
          title: Nit
          type: string
        status:
          enum:
            - active
            - suspended
          title: Status
          type: string
        tenant_id:
          format: uuid
          title: Tenant Id
          type: string
        test_set_accepted:
          description: >-
            Whether the DIAN accepted the habilitación test set of the issuer's
            current TestSetId.
          title: Test Set Accepted
          type: boolean
      required:
        - tenant_id
        - nit
        - check_digit
        - legal_name
        - contact_email
        - status
        - dian_environment
        - test_set_accepted
        - created
      title: PartnerTenantCreated
      type: object
    Problem:
      description: Error body (`application/problem+json`, RFC 9457).
      properties:
        code:
          description: Stable machine-readable error code.
          title: Code
          type: string
        detail:
          description: Explanation specific to this occurrence.
          title: Detail
          type: string
        dian:
          anyOf:
            - $ref: '#/components/schemas/DianDetail'
            - type: 'null'
          description: Present only when the DIAN rejected a document.
        request_id:
          description: Value of the `X-Request-ID` response header.
          title: Request Id
          type: string
        status:
          description: HTTP status code.
          title: Status
          type: integer
        title:
          description: Short, human-readable summary of the problem kind.
          title: Title
          type: string
        type:
          description: Stable URI identifying the problem kind.
          title: Type
          type: string
      required:
        - type
        - title
        - status
        - code
        - detail
        - request_id
      title: Problem
      type: object
    ValidationProblem:
      description: A 422 problem. `errors` is present when `code` is `validation_error`.
      properties:
        code:
          description: Stable machine-readable error code.
          title: Code
          type: string
        detail:
          description: Explanation specific to this occurrence.
          title: Detail
          type: string
        dian:
          anyOf:
            - $ref: '#/components/schemas/DianDetail'
            - type: 'null'
          default: null
          description: Present only when the DIAN rejected a document.
        errors:
          anyOf:
            - items:
                $ref: '#/components/schemas/FieldError'
              type: array
            - type: 'null'
          default: null
          description: The offending fields, for `validation_error` only.
          title: Errors
        request_id:
          description: Value of the `X-Request-ID` response header.
          title: Request Id
          type: string
        status:
          description: HTTP status code.
          title: Status
          type: integer
        title:
          description: Short, human-readable summary of the problem kind.
          title: Title
          type: string
        type:
          description: Stable URI identifying the problem kind.
          title: Type
          type: string
      required:
        - type
        - title
        - status
        - code
        - detail
        - request_id
      title: ValidationProblem
      type: object
    ClientAuthorizationIn:
      additionalProperties: false
      description: >-
        The client's written authorization of the partner. Cufea stores these
        facts,

        append-only; it does not verify the signature, the partner answers for
        it.
      properties:
        authorized_at:
          description: When the client signed the authorization (with its time zone).
          examples:
            - '2026-11-20T15:04:00-05:00'
          format: date-time
          title: Authorized At
          type: string
        evidence_ref:
          description: Where the partner keeps the signed copy (an id in its own system).
          examples:
            - fhyra:company/8812/consents/31
          maxLength: 500
          minLength: 1
          title: Evidence Ref
          type: string
        evidence_sha256:
          anyOf:
            - pattern: ^[0-9a-f]{64}$
              type: string
            - type: 'null'
          description: Optional SHA-256 (lowercase hex) of the signed copy.
          title: Evidence Sha256
        text_version:
          description: The version of the authorization text the client accepted.
          examples:
            - fhyra-mandato-fe-v1
          maxLength: 120
          minLength: 1
          title: Text Version
          type: string
      required:
        - authorized_at
        - text_version
        - evidence_ref
      title: ClientAuthorizationIn
      type: object
    ApiKeyInfo:
      description: 'An API key as listed: never the key itself nor its hash.'
      properties:
        id:
          format: uuid
          title: Id
          type: string
        prefix:
          description: >-
            Public lookup prefix, the part after `cufea_sandbox_`, `cufea_test_`
            or `cufea_prod_` (or the legacy `cfa_test_`).
          title: Prefix
          type: string
        revoked:
          title: Revoked
          type: boolean
        revoked_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Revoked At
        stage:
          description: The one stage the key drives.
          enum:
            - sandbox
            - test
            - production
          title: Stage
          type: string
      required:
        - id
        - prefix
        - stage
        - revoked
      title: ApiKeyInfo
      type: object
    ApiKeyCreated:
      properties:
        api_key:
          description: 'The full key. Shown ONCE, here: it cannot be retrieved again.'
          title: Api Key
          type: string
        id:
          format: uuid
          title: Id
          type: string
        prefix:
          description: >-
            Public lookup prefix, the part after `cufea_sandbox_`, `cufea_test_`
            or `cufea_prod_` (or the legacy `cfa_test_`).
          title: Prefix
          type: string
        revoked:
          title: Revoked
          type: boolean
        revoked_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Revoked At
        stage:
          description: The one stage the key drives.
          enum:
            - sandbox
            - test
            - production
          title: Stage
          type: string
      required:
        - id
        - prefix
        - stage
        - revoked
        - api_key
      title: ApiKeyCreated
      type: object
    DianDetail:
      description: A DIAN rejection rule and its text, relayed verbatim to the client.
      properties:
        rule:
          description: DIAN validation rule code, for example `FAD06`.
          title: Rule
          type: string
        text:
          description: Rule description as returned by the DIAN.
          title: Text
          type: string
      required:
        - rule
        - text
      title: DianDetail
      type: object
    FieldError:
      description: One offending field of a request that failed validation.
      properties:
        loc:
          description: Where the field is, e.g. `["body", "lines"]`.
          items:
            type: string
          title: Loc
          type: array
        msg:
          description: What is wrong with it. The submitted value is never echoed.
          title: Msg
          type: string
      required:
        - loc
        - msg
      title: FieldError
      type: object
  headers:
    X-RateLimit-Limit:
      description: >-
        Requests this API key may make in the current window (120 per minute by
        default).
      example: 120
      schema:
        minimum: 1
        type: integer
    X-RateLimit-Remaining:
      description: Requests this API key has left in the current window.
      example: 119
      schema:
        minimum: 0
        type: integer
    X-RateLimit-Reset:
      description: Whole seconds until the window restarts and the quota is full again.
      example: 17
      schema:
        minimum: 1
        type: integer
    Retry-After:
      description: >-
        Whole seconds to wait before the next request (RFC 9110
        `delay-seconds`); equals `X-RateLimit-Reset`.
      example: 17
      schema:
        minimum: 1
        type: integer
  securitySchemes:
    PartnerKeyAuth:
      bearerFormat: partner key
      description: >-
        Send your Cufea partner key as `Authorization: Bearer
        cufea_partner_...`. Only the `/v1/partner` routes accept it.
      scheme: bearer
      type: http

````

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