Get Project Usage for a Specific User
Use this endpoint to retrieve the current billing-cycle usage (in bytes) for a specific user (identified by username) in a particular TURN Server project. You can authenticate by providing either the secretKey (for your entire application) or the projectApiKey (for a specific project).
GET
https://<appname>.metered.live/api/v2/turn/project/:projectId/current_usage_for_user
<appname> - Replace with the name of your app.
:projectId - The unique ID of the project whose usage you want to retrieve for a particular user.
Request
GET /api/v2/turn/project/:projectId/current_usage_for_user
Path Parameter
| Parameter | Description | Data Type |
|---|---|---|
projectId | The unique ID of the project (must be a valid ObjectId) | String |
Query Parameters (Authentication)
| Parameter | Description | Data Type |
|---|---|---|
secretKey | Your application's secret key, found in Dashboard → Developers → Secret Key. Only one of secretKey or projectApiKey is required. | String |
projectApiKey | The API key for the specific project. Only one of secretKey or projectApiKey is required. | String |
Other Query Parameters
| Parameter | Description | Data Type |
|---|---|---|
username | The TURN username for which you want to retrieve usage data (required). | String |
Example:
GET /api/v2/turn/project/:projectId/current_usage_for_user?secretKey=<YOUR_SECRET_KEY>&username=user123
Retrieves the usage data for user123 in the specified project.
Responses
Success Response
A JSON object with the following fields:
| Field | Description | Data Type |
|---|---|---|
label | The label associated with this credential (if any). | String or null |
usageInBytes | The total usage (in bytes) for the specified username during the current billing cycle. May be returned as a string—parse as needed. | String or Number |
HTTP Status: 200 OK
Example Success Response
{
"label": "my-labeled-credential",
"usageInBytes": "1234567"
}
Error Responses
| HTTP Status | Message | Description |
|---|---|---|
| 400 | please pass the username query parameter | Occurs when username is missing from the query parameters. |
| 401 | credential not found | The specified username does not exist in the project under this application. |
Code Examples
cURL
curl -X GET "https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/current_usage_for_user?secretKey=<YOUR_SECRET_KEY>&username=user123"
JavaScript (Fetch)
fetch(`https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/current_usage_for_user?projectApiKey=<PROJECT_API_KEY>&username=user123`)
.then(response => response.json())
.then(data => {
console.log("Credential Label:", data.label);
console.log("Usage in Bytes:", data.usageInBytes);
})
.catch(error => console.error("Error:", error));