Skip to main content

Get TURN Credential

API endpoint allows clients to request credentials for using the TURN server. It returns information about the TURN server and credentials including STUN and TURN server URLs, username, and password.


GET
    https://<appname>.metered.live/api/v1/turn/credentials

<appname> - replace it the name of your app.

Request

GET /api/v1/turn/credentials

Query Parameters

ParameterDescriptionData Type
apiKeyThe API key for authentication. Generated when you generate the credentialString

Responses

Success Response

HTTP Status: 200 OK

Body:

[
{
"urls": "stun:<TURN_SERVER_DOMAIN>:80"
},
{
"urls": "turn:<TURN_SERVER_DOMAIN>:80",
"username": "<USERNAME>",
"credential": "<PASSWORD>"
},
{
"urls": "turn:<TURN_SERVER_DOMAIN>:80?transport=tcp",
"username": "<USERNAME>",
"credential": "<PASSWORD>"
},
{
"urls": "turn:<TURN_SERVER_DOMAIN>:443",
"username": "<USERNAME>",
"credential": "<PASSWORD>"
},
{
"urls": "turn:<TURN_SERVER_DOMAIN>:443?transport=tcp",
"username": "<USERNAME>",
"credential": "<PASSWORD>"
}
]

Error Responses

  • Invalid API Key:

    HTTP Status: 401 Unauthorized

    Body:

    {
    "error": "Invalid API Key"
    }
  • No API Key Specified:

    HTTP Status: 400 Bad Request

    Body:

    {
    "error": "Please specify API Key"
    }

Code Examples

JavaScript (Fetch API)

fetch("/api/v1/turn/credentials?apiKey=<YOUR_API_KEY>")
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
const iceServers = await response.json();
peerConfiguration.iceServers = iceServers
})
.then((data) => {
console.log("TURN server credentials received:", data);
})
.catch((error) => {
console.error("Error fetching TURN server credentials:", error);
});