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
Parameter | Required | Data Type | Description |
---|---|---|---|
apiKey | Yes | String | The API key for authentication. Generated when you generate the credential |
region | No | String | Specify a region to fetch a specific TURN Server. If not provided, the server from the "Default Region" will be used. |
Supported Regions
"global",
"north_america",
"europe",
"eu",
"asia",
"oceania",
"us_west",
"us_central",
"us_east",
"canada_central",
"canada_east",
"europe_west",
"europe_central",
"asia_west",
"asia_east",
"canada",
"usa",
"uk",
"singapore",
"india",
"australia",
"standard"
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);
});
With Region
fetch("/api/v1/turn/credentials?apiKey=<YOUR_API_KEY>®ion=us_east")
.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);
});