Node.js
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.usage();
if (error) {
console.error("Get usage failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve parent-account usage for the current billing period.
response = mailchannels.Usage.retrieve()
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve parent-account usage for the current billing period.
$response = $client->usage->retrieve();
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/usage \
--header 'X-Api-Key: <x-api-key>'{
"monthly_limit": 10000,
"total_usage": 5000,
"period_end_date": "2025-04-11",
"period_start_date": "2025-03-12"
}Retrieve Usage Stats
Retrieves usage statistics during the current billing period.
GET
/
usage
Node.js
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.usage();
if (error) {
console.error("Get usage failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve parent-account usage for the current billing period.
response = mailchannels.Usage.retrieve()
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve parent-account usage for the current billing period.
$response = $client->usage->retrieve();
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/usage \
--header 'X-Api-Key: <x-api-key>'{
"monthly_limit": 10000,
"total_usage": 5000,
"period_end_date": "2025-04-11",
"period_start_date": "2025-03-12"
}Headers
Response
Successfully returned the usage stats.
The effective monthly limit for the current billing period. A limit of zero means the account cannot send any messages. For sub-accounts with no explicit limit set (i.e., -1), the monthly limit for the parent account is returned.
Example:
10000
The total usage for the current billing period.
Example:
5000
The end date of the current billing period (ISO 8601 format).
Example:
"2025-04-11"
The start date of the current billing period (ISO 8601 format).
Example:
"2025-03-12"
Was this page helpful?

