6 min read

Usage Statistics

Get detailed usage statistics and analytics for your credit consumption

Retrieve detailed usage statistics and analytics for your credit consumption, including breakdowns by time period and document type.

GET/v1/credits/usage

Request

Headers

ParameterTypeDescription
X-API-Keyrequired
stringYour API key for authentication

Query Parameters

ParameterTypeDescription
period
stringTime period for statistics: daily, weekly, monthly
Default: monthly
startDate
stringStart date for statistics (ISO 8601 format)
Default: 30 days ago
endDate
stringEnd date for statistics (ISO 8601 format)
Default: today
groupBy
stringGroup results by: date, documentType, both
Default: date

Example Requests

curl
# Get monthly usage statistics (default)
curl -X GET "https://api.docurift.com/v1/credits/usage" \
-H "X-API-Key: frc_your_api_key_here"

# Get daily breakdown for last 7 days
curl -X GET "https://api.docurift.com/v1/credits/usage?period=daily&startDate=2024-01-19" \
-H "X-API-Key: frc_your_api_key_here"

# Get usage grouped by document type
curl -X GET "https://api.docurift.com/v1/credits/usage?groupBy=documentType" \
-H "X-API-Key: frc_your_api_key_here"

# Get weekly usage with both date and document type breakdown
curl -X GET "https://api.docurift.com/v1/credits/usage?period=weekly&groupBy=both" \
-H "X-API-Key: frc_your_api_key_here"
python
import requests
import os
from datetime import datetime, timedelta

API_KEY = os.getenv('DOCURIFT_API_KEY')
API_URL = 'https://api.docurift.com/v1'

# Get usage statistics for the last 30 days
start_date = (datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d')
end_date = datetime.now().strftime('%Y-%m-%d')

response = requests.get(
  f'{API_URL}/credits/usage',
  headers={'X-API-Key': API_KEY},
  params={
      'period': 'daily',
      'startDate': start_date,
      'endDate': end_date,
      'groupBy': 'both'
  }
)

data = response.json()
stats = data['data']

print(f"Total pages processed: {stats['summary']['totalPages']}")
print(f"Total credits used: {stats['summary']['totalCredits']}")
print(f"Documents processed: {stats['summary']['totalDocuments']}")

# Show breakdown by document type
print("\nBy document type:")
for doc_type, info in stats['byDocumentType'].items():
  print(f"  {doc_type}: {info['pages']} pages ({info['credits']} credits)")
javascript
const API_KEY = process.env.DOCURIFT_API_KEY;
const API_URL = 'https://api.docurift.com/v1';

async function getUsageStats(options = {}) {
const params = new URLSearchParams({
  period: options.period || 'monthly',
  groupBy: options.groupBy || 'date',
  ...(options.startDate && { startDate: options.startDate }),
  ...(options.endDate && { endDate: options.endDate })
});

const response = await fetch(
  `${API_URL}/credits/usage?${params}`,
  {
    headers: { 'X-API-Key': API_KEY }
  }
);

return await response.json();
}

// Get daily usage for current month
const now = new Date();
const firstOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const stats = await getUsageStats({
period: 'daily',
startDate: firstOfMonth.toISOString().split('T')[0],
groupBy: 'both'
});

console.log('Summary:', stats.data.summary);
console.log('Daily breakdown:', stats.data.byPeriod);
console.log('By document type:', stats.data.byDocumentType);

// Calculate average daily usage
const dailyData = stats.data.byPeriod;
const avgDaily = stats.data.summary.totalCredits / dailyData.length;
console.log(`Average daily usage: ${avgDaily.toFixed(1)} credits`);

Response

response.json
{
"success": true,
"data": {
  "summary": {
    "totalCredits": 127,
    "totalPages": 127,
    "totalDocuments": 45,
    "averagePerDocument": 2.8,
    "period": {
      "start": "2024-01-01T00:00:00Z",
      "end": "2024-01-26T23:59:59Z"
    }
  },
  "byPeriod": [
    {
      "date": "2024-01-26",
      "credits": 12,
      "pages": 12,
      "documents": 4
    },
    {
      "date": "2024-01-25",
      "credits": 8,
      "pages": 8,
      "documents": 3
    },
    {
      "date": "2024-01-24",
      "credits": 15,
      "pages": 15,
      "documents": 5
    }
  ],
  "byDocumentType": {
    "invoice": {
      "credits": 65,
      "pages": 65,
      "documents": 25,
      "percentage": 51.2
    },
    "bill_of_lading": {
      "credits": 32,
      "pages": 32,
      "documents": 10,
      "percentage": 25.2
    },
    "packing_list": {
      "credits": 18,
      "pages": 18,
      "documents": 6,
      "percentage": 14.2
    },
    "general": {
      "credits": 12,
      "pages": 12,
      "documents": 4,
      "percentage": 9.4
    }
  }
}
}

Response Fields

ParameterTypeDescription
summary
objectOverall usage summary for the requested period
summary.totalCredits
integerTotal credits consumed in the period
summary.totalPages
integerTotal pages processed in the period
summary.totalDocuments
integerTotal documents processed in the period
summary.averagePerDocument
floatAverage pages per document
summary.period
objectStart and end timestamps of the statistics period
byPeriod
arrayUsage breakdown by time period (daily/weekly/monthly)
byPeriod[].date
stringDate or period start date
byPeriod[].credits
integerCredits used in this period
byPeriod[].pages
integerPages processed in this period
byPeriod[].documents
integerDocuments processed in this period
byDocumentType
objectUsage breakdown by document type
byDocumentType[type].credits
integerCredits used for this document type
byDocumentType[type].pages
integerPages processed for this document type
byDocumentType[type].documents
integerNumber of documents of this type
byDocumentType[type].percentage
floatPercentage of total usage for this type
💡

Credits Never Expire

Remember, all your credits never expire. Use this endpoint to track consumption patterns and plan your credit purchases accordingly.

Document Types

The following document types may appear in the usage breakdown:

| Type | Description | |------|-------------| | invoice | Commercial invoices and billing documents | | bill_of_lading | Bills of lading and shipping documents | | packing_list | Packing lists and item manifests | | delivery_order | Delivery orders and instructions | | certificate_of_origin | Origin certificates | | customs_declaration | Customs and duty documents | | freight_invoice | Freight and shipping invoices | | air_waybill | Air cargo documents | | sea_waybill | Ocean freight documents | | shipping_manifest | Shipping manifests | | general | Unclassified or general documents |

Period Options

| Period | Grouping | Example Output | |--------|----------|----------------| | daily | By day | 2024-01-26, 2024-01-25, ... | | weekly | By week start (Monday) | 2024-01-22, 2024-01-15, ... | | monthly | By month | 2024-01, 2023-12, ... |

Error Responses

error.json
{
"success": false,
"error": {
  "code": "INVALID_DATE_RANGE",
  "message": "startDate must be before endDate"
}
}

Error Codes

| Code | HTTP Status | Description | |------|-------------|-------------| | UNAUTHORIZED | 401 | Missing or invalid API key | | INVALID_API_KEY | 401 | API key is malformed or does not exist | | INVALID_PARAMETER | 400 | Invalid query parameter value | | INVALID_DATE_FORMAT | 400 | Date parameters must be ISO 8601 format | | INVALID_DATE_RANGE | 400 | startDate must be before endDate | | DATE_RANGE_TOO_LARGE | 400 | Date range exceeds maximum (1 year) | | RATE_LIMIT_EXCEEDED | 429 | Too many requests, please retry later | | INTERNAL_ERROR | 500 | Server error, please retry or contact support |

Use Cases

Monthly Billing Reports

Generate monthly usage reports for cost tracking:

# Get monthly usage for the year
response = requests.get(
    f'{API_URL}/credits/usage',
    headers={'X-API-Key': API_KEY},
    params={
        'period': 'monthly',
        'startDate': '2024-01-01',
        'endDate': '2024-12-31'
    }
)

Document Type Analysis

Analyze which document types consume the most credits:

response = requests.get(
    f'{API_URL}/credits/usage',
    headers={'X-API-Key': API_KEY},
    params={'groupBy': 'documentType'}
)

for doc_type, stats in response.json()['data']['byDocumentType'].items():
    print(f"{doc_type}: {stats['percentage']:.1f}% of usage")

Usage Forecasting

Use daily usage data to forecast future credit needs:

const stats = await getUsageStats({ period: 'daily', groupBy: 'date' });
const avgDaily = stats.data.summary.totalCredits / stats.data.byPeriod.length;
const projectedMonthly = avgDaily * 30;
console.log(`Projected monthly usage: ${projectedMonthly} credits`);

Next Steps