Represents a file containing usage events that has been uploaded for processing.
Upload usage events using files
Follow these steps to upload usage event files:
Step 1: Request an usage_file object using the upload endpoint. This returns an url.
Step 2: Create a CSV file containing the usage event records. Ensure that the file meets the expected format and complies with the file upload constraints. Only text/csv files are supported.
Step 3: Upload the CSV file using the returned url.
Make an HTTP PUT request to the upload URL. Include the file in the request body as binary data (raw file content).
Step 4: Check the uploaded usage_file_status using the retrieve_file_processing_status endpoint.
Important : Learn more about ingesting usage events from Amazon S3.
Best practices
- We recommend not to create empty files which contain only header rows.
- We recommend uploading files in batches of 100,000 events per file or lesser to ensure optimal performance.
- We recommend ensuring that no row contains extra columns without corresponding headers.
File upload constraints
- File names should not contain any special characters except for underscores
_and hyphens-. - File names must be under 150 characters and include the appropriate extensions, such as
.csv. - The supported delimiter for CSV file format is comma(,).
- The file must not exceed 1 GB size or 1 million records. The lesser of the two limits applies.
- The uploaded data will be processed at the rate of 10,000 events per minute.
To process more usage events than the limit mentioned above, contact support at support@chargebee.com
File field constraints
- Make sure your file follows the sample file format:
| deduplication_id | subscription_id | usage_timestamp | input_tokens | output_tokens |
| 123e4567-e89b-12d3 | Sub-01 | 1741156511000 | 100 | 100 |
| 987f6543-b21c-34a5 | Sub-02 | 1741156511001 | 859 | 194 |
-
Learn more about
deduplication_id,subscription_id, andusage_timestamp. -
Each row must include
deduplication_id,subscription_id, andusage_timestamp. Rows missing any of these fields are flagged as failed events. -
Any top-level fields in the event row that are not a recognized field (
deduplication_id,subscription_id, andusage_timestamp) will automatically be added to theproperties.Field Naming Guidelines: Ensure that your file's column headers follow the required naming rules to avoid processing issues:
- Start with: a lowercase letter (
a-z)
- Start with: a lowercase letter (
-
May include:
- Lowercase letters (
a-z) - Numbers (
0-9) - Underscores (
_)
- Lowercase letters (
| Valid Examples | Invalid Examples |
input_tokens | InputTokens |
output_tokens | Output Tokens |
feature_usage_1 | 123output |
output_value | output@value |
input_value | input-value |
Validating and handling errors
When uploading a usage events file using the API, certain validation checks are performed. If issues are detected, the upload or processing may fail. The following sections explain the possible error scenarios and how they are handled.
| Error Code | Description |
|---|---|
INVALID_FILE | This error occurs in the following scenarios:
|
DUPLICATE_COLUMNS | This error occurs when the file contains duplicate column headers, which must be unique. Error Message: "Duplicate columns found: [list of duplicates]. Please remove duplicates from your file before uploading again." |
RECORD_LIMIT_EXCEEDED | This error occurs when the number of records in the uploaded file exceeds the system-defined limit. The [limit] placeholder specifies the maximum allowed records. Error Message: "The number of records exceeds the allowed limit of [limit]. Please reduce the number of records in the file and try uploading again." |
PARTIAL_FAILURE | This error indicates that some records in the file failed to process, while others were processed successfully. Review the failed records in the UI or failed queue for more details. Error Message: "Some records in the file could not be processed successfully. Please check the failed records in the [UI/Failed Queue] for more details." |
COMPLETE_FAILURE | This error indicates that all records in the uploaded file failed to process. Review the file, fix the issues, and try uploading it again. Error Message: "All records in the file failed to process. Please check the failed records in the [UI/Failed Queue] for more details." |
INVALID_COLUMNS | This error indicates that the file contains invalid column headers. Error Message: "Invalid columns found: [list of invalid headers]. Please correct column names in your file before uploading again." |
Note: Usage events flagged as failed appear in the Usages > Failed Events section of the Admin UI Dashboard.
Sample Usage fileJSON
Usage files attributes
Indicates the format of a file.
Note:
Currently, only text/csv
is supported.
A short, machine-readable code that indicates the reason for the failure. Learn more about the error codes.
A descriptive, human-readable message explaining the failure. Learn more about the error messages.
Current status of the usage file.
The file is queued for upload.
The file has been imported.
The file is currently being processed.
The file processing is completed.
The file failed to process.
Timestamp when the file processing was completed.
Amazon S3 path in your bucket where the error file containing error codes is uploaded.
Pre-signed URL for the error_file
containing error_codes.
The link is valid for 60 minutes.