Represents a file containing usage events that has been uploaded for processing.
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_upload_status
endpoint.
_
and hyphens -
..csv
.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
, and usage_timestamp
.
Any top-level fields in the event row that are not a recognized field (deduplication_id
, subscription_id
, and usage_timestamp
) will automatically be added to the properties
.
Each row must include deduplication_id
, subscription_id
, and usage_timestamp
. Rows missing any of these fields are flagged as failed events.
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." |
Usage events flagged as failed appear in the Usages > Failed Events section of the Admin UI Dashboard.
{
"id": "6fa7df05-9d4a-4c29-a161-bded616459c4",
"name": "usage_events-1743661346062.csv",
"mime_type": "text/csv",
"upload_details": {
"url": "https://cb-prod-us-e1-fileservice-temporaryfiles-store.s3.amazonaws.com/staged_file/{site}/01JR2NJ25PA7WKQCW5G6H0TR99/usage_events-1743661346062.csv?X-Amz-Security-Token=/....",
"expires_at": 1743662040000
}
}
This endpoint returns an upload URL for uploading usage events files, allowing you to upload files in supported formats. The file is processed asynchronously, and its status can be tracked using the retrieve_upload_status
endpoint.
Before uploading, review the following guidelines and constraints:
Name of the file being uploaded.
file_name
except for underscores _
and hyphens -
.Example:
Valid file name | Invalid file name |
merchant_data.csv | merchant@data.csv |
sales_report-2024.csv | sales&report-2024.csv |
customer_details_file.csv | customer!details#file.csv |