Skip to main content

Create TURN Credential for a Project

Use this endpoint to create a new TURN credential (username/password) under a specific project.

You can authenticate by providing either the secretKey (for your entire application) or the projectApiKey (for a specific project).


POST
https://<appname>.metered.live/api/v2/turn/project/:projectId/credential

<appname> - Replace with the name of your app.

:projectId - The unique ID of the project under which the credential is to be created.


Request

POST /api/v2/turn/project/:projectId/credential

Path Parameter

ParameterDescriptionData Type
projectIdThe unique ID of the projectString

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.String

Note: Only one of secretKey or projectApiKey is required.

Body Parameters

ParameterDescriptionTypeRequired
expiryInSecondsTime (in seconds) after which the credential automatically expires. Must be a positive integer. If omitted, the credential does not auto-expire.NumberNo
labelA custom label to associate with the credential. Useful for identifying or filtering credentials later.StringNo
Example Request Body
{
"expiryInSeconds": 3600,
"label": "my-labeled-credential"
}

Responses

Success Response

A JSON object containing the newly created credential details:

FieldDescriptionData Type
usernameThe TURN username for this credential.String
passwordThe TURN password for this credential.String
expiryInSecondsNumber of seconds after which this credential expires (if provided).Number
labelCustom label provided for this credential (if provided).String
apiKeyThe API key used when creating this credential.String

HTTP Status: 200 OK

Example Success Response
{
"username": "c7e21d0a812c0c3fdb3af925",
"password": "lrwWgwswMGQDXA1w",
"expiryInSeconds": 3600,
"label": "my-labeled-credential",
"apiKey": "7fd90780bfa95adb5df34015e2810b71c30f"
}

Error Responses

HTTP StatusMessageDescription
400Invalid projectIdThe projectId is not a valid MongoDB ObjectId.
400Project not foundNo project matching the given credentials (secretKey or projectApiKey) was found.
400please enter a positive integer value for expiryInSecondsThe expiryInSeconds body parameter is not a valid positive integer.
403Maximum credential limit reached. Upgrade to paid plan to create more credentialsThe number of active credentials for your current plan has exceeded its limit.
400Invalid request. Not subscribed to any turn server planThe application is not subscribed to a TURN server plan.

Code Examples

cURL

curl -X POST "https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/credential?secretKey=<YOUR_SECRET_KEY>" \
-H "Content-Type: application/json" \
-d '{
"expiryInSeconds": 3600,
"label": "my-labeled-credential"
}'

JavaScript (Fetch)

fetch(
`https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/credential?projectApiKey=<PROJECT_API_KEY>`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
expiryInSeconds: 3600,
label: "my-labeled-credential",
}),
}
)
.then((response) => response.json())
.then((data) => console.log("New Credential:", data))
.catch((error) => console.error("Error:", error));