What is an Access Key?
The access key (clave de acceso) is a unique 49-digit numeric identifier required for all electronic documents submitted to Ecuador’s SRI. It serves as a unique fingerprint for each invoice and is used throughout the authorization process.Open Factura automatically generates valid access keys when you use the
generateInvoice() function.Access Key Structure
The access key is composed of 49 digits organized in the following segments:| Segment | Length | Description | Example |
|---|---|---|---|
| Date | 8 digits | Emission date (DDMMYYYY) | 01122024 |
| Document Type | 2 digits | Type of document | 01 |
| RUC | 13 digits | Tax identification number | 1234567890001 |
| Environment | 1 digit | Testing (1) or Production (2) | 1 |
| Establishment | 3 digits | Establishment code | 001 |
| Emission Point | 3 digits | Point of emission | 001 |
| Sequential | 9 digits | Sequential document number | 000000001 |
| Numeric Code | 8 digits | Random verification code | 12345678 |
| Emission Type | 1 digit | Emission type (always 1) | 1 |
| Verification Digit | 1 digit | Modulo 11 checksum | 7 |
Generation Process
Open Factura generates access keys using thegenerateAccessKey() function defined in src/utils/utils.ts:21.
Input Parameters
Generation Steps
The access key is generated following these steps:1. Format the Date
Convert the emission date to DDMMYYYY format:2. Concatenate Base Components
The first 41 digits are built by concatenating:3. Generate Random Numeric Code
An 8-digit random number is generated for additional uniqueness:4. Calculate Verification Digit
The final digit is calculated using the Modulo 11 algorithm:The verification digit algorithm multiplies each digit by a factor cycling from 7 down to 2, calculates the sum modulo 11, and applies special rules for values of 10 and 11.
Complete Generation Function
Here’s the complete access key generation function fromsrc/utils/utils.ts:21:
Example
Let’s generate an access key for an invoice: Input Data:- Date: December 1, 2024
- Document Type: 01 (Invoice)
- RUC: 1234567890001
- Environment: 1 (Testing)
- Establishment: 001
- Emission Point: 001
- Sequential: 000000001
- Random Code: 45678901 (generated)
01122024- Date (01/12/2024)01- Invoice1234567890001- RUC1- Testing environment001- Establishment001- Emission point000000001- Sequential45678901- Random code1- Emission type7- Verification digit
Usage in Open Factura
ThegenerateInvoice() function automatically creates the access key:
Document Type Codes
ThecodDoc parameter specifies the document type:
01- FACTURA (Invoice)03- LIQUIDACIÓN DE COMPRA DE BIENES Y PRESTACIÓN DE SERVICIOS04- NOTA DE CRÉDITO (Credit Note)05- NOTA DE DÉBITO (Debit Note)06- GUÍA DE REMISIÓN (Delivery Guide)07- COMPROBANTE DE RETENCIÓN (Withholding Receipt)
Environment Types
The environment code indicates where the document will be processed:1- Testing (Pruebas): Use for development and testing2- Production (Producción): Use for actual business operations
You must enable the testing or production environment in your SRI account before submitting documents. See the SRI Endpoints documentation for activation instructions.
Best Practices
- Sequential Control: Maintain strict control over sequential numbers to avoid duplicates
- Date Accuracy: Always use the actual emission date - this cannot be changed later
- Environment Matching: Ensure the environment in the access key matches the SRI endpoint you’re using
- Storage: Store the access key with your invoice records for future reference and authorization checks
Next Steps
Invoice Structure
Learn about the complete invoice data structure
SRI Endpoints
Configure endpoints for document submission