In Honduras, every business that issues fiscal invoices must obtain a CAI (Código de Autorización de Impresión) from the Servicio de Administración de Rentas (SAR). The CAI is a government-issued authorization code that defines the range of invoice numbers a business is permitted to print and the date by which those invoices must be issued. Credith builds CAI compliance directly into the bill creation flow — a sale cannot be posted without a valid, active CAI Range attached to the store, and every generated invoice number is traceable back to the authorizing CAI.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/RoyGeova07/Credith/llms.txt
Use this file to discover all available pages before exploring further.
Two-Level Structure: CAI → CAI Range → Bill
Authorization flow:
CAI (government authorization code + expiry)
→ one or more CAI Ranges (min/max bill number sequences)
→ Bills (each stamped with a CAI Range ID and an incrementing number)A bill’s final printed number follows the format:
{store_number}-{machine_number}-{document_type}-{bill_number}
e.g. 001-001-01-00000042The cais Table
Each CAI record represents a single government authorization issued to a store.
| Field | Type | Description |
|---|---|---|
cai_id | UUID | Primary key |
government_id | STRING(75) | The official CAI code issued by SAR. Must be unique across the system. |
expiration_date | DATE | The date after which the CAI is no longer valid for new invoices. Must be in the future at creation time. |
document_type | STRING(10) | Invoice document type code, defaults to '01'. Used in the formatted bill number. |
is_active | BOOLEAN | Whether this CAI is currently active for the store. Only one CAI can be active per store. |
store_id | UUID | FK → stores.store_id. The store this CAI belongs to. |
The cai_ranges Table
Each CAI Range defines a contiguous sequence of bill numbers authorized under a specific CAI.
| Field | Type | Description |
|---|---|---|
cai_range_id | UUID | Primary key |
min_range | INTEGER | The first bill number in this authorized sequence. |
max_range | INTEGER | The last bill number in this authorized sequence. |
current_number | INTEGER | The count of bills already issued under this range. Starts at 0; the next bill number is calculated as min_range + current_number. |
is_active | BOOLEAN | Whether this range is the active one for its CAI. Only one range can be active per CAI. |
cai_id | UUID | FK → cais.cai_id. |
Single Active CAI Enforcement
Only one CAI can be active per store at any given time. When a new CAI is created, the system deactivates all previously active CAIs for that store inside a database transaction:isRenewal: true flag, the API returns 409 Conflict:
POST /api/cai-ranges automatically deactivates the previous active range for that CAI.
Atomic Bill Number Increment
During bill creation (POST /api/bills), the system acquires a SELECT ... FOR UPDATE lock on the active CAI Range row and atomically increments current_number. The next bill number is derived as minRange + currentNumber:
Range Overlap Prevention
When creating a new CAI or CAI Range, Credith checks that the newminRange is strictly greater than the highest maxRange ever registered for that store — across all CAIs, not just the active one. This prevents invoice number gaps and overlaps in the audit trail:
Modifying and Deleting CAI Ranges
Updating or deleting a CAI Range is blocked if any bills have already been issued against it. This protects the immutability of issued fiscal documents:deleteCaiRange() and to deleteCai() (which checks all child ranges).
API Reference
| Method | Endpoint | Description |
|---|---|---|
POST | /api/cais | Create a new CAI + initial range. Deactivates current active CAI for the store. Validates governmentId uniqueness, future expiry, positive non-overlapping range. Accepts isRenewal: true to replace an active CAI. |
GET | /api/cais | List CAIs with pagination. Pass ?history=true to see all historical CAIs; default returns only the latest per store. |
DELETE | /api/cais/:id | Delete a CAI and all its ranges. Blocked if any range has associated bills. |
POST | /api/cai-ranges | Add a new range to an active, non-expired CAI. Deactivates the previous active range. |
GET | /api/cais/:caiId/ranges | List all ranges for a specific CAI (paginated). |
GET | /api/cai-ranges/:id | Get a single CAI Range by UUID. |
PUT | /api/cai-ranges/:id | Extend max_range. Blocked if bills exist or new max ≤ current max. |
DELETE | /api/cai-ranges/:id | Delete a range. Blocked if bills exist. |