Skip to main content

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

ParameterDescriptionData Type
projectIdThe unique ID of the project (must be a valid ObjectId)String

Query Parameters (Authentication)

ParameterDescriptionData Type
secretKeyYour application's secret key, found in Dashboard → Developers → Secret Key. Only one of secretKey or projectApiKey is required.String
projectApiKeyThe API key for the specific project. Only one of secretKey or projectApiKey is required.String

Other Query Parameters

ParameterDescriptionData Type
usernameThe 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:

FieldDescriptionData Type
labelThe label associated with this credential (if any).String or null
usageInBytesThe 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 StatusMessageDescription
400please pass the username query parameterOccurs when username is missing from the query parameters.
401credential not foundThe 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));