turn.createCredentials
Create temporary STUN/TURN ICE server credentials.
On this page
Import and client
import { RelayServer } from '@relayrtc/node'
const relay = new RelayServer({
apiUrl: process.env.RELAYRTC_API_URL!,
apiKey: process.env.RELAYRTC_SECRET_KEY!,
})Requirements
A secret key with tokens:create. The requested resource must belong to that key's project environment.
Parameters
| Option | Type | Default / requirement | Purpose |
|---|---|---|---|
| roomId | string | Optional with sessionId | Room of the active session. |
| sessionId | string | Optional with roomId | Active participant session. |
| participantId | string | Optional; requires roomId and sessionId | Require the session to belong to this participant. |
Every method accepts RequestOptions as its final argument.
Example
const roomId = 'room_example'
const sessionId = 'session_example'
const participantId = 'participant_example'
const result = await relay.turn.createCredentials({ roomId, sessionId, participantId })Resolve participantId from your authenticated application session or a trusted backend record. Do not forward an unverified participant ID from the caller. Omitting it preserves the existing room/session scope without the additional participant match.
Returns
Promise<TurnCredentials>. Returns TURN credentials. URLs, username, lifetime and password depend on the deployment.
Behavior
Supply both roomId and sessionId for session-bound credentials or send {} for environment-scoped credentials. When supplied, participantId must match the participant owning that active session in the key's project/environment. A mismatch returns 404; supplying it without room/session IDs is invalid.
Use matching Node SDK and API builds that support the optional participant check. The check does not replace application authentication or authorize the caller on its own.
Supply initial browser credentials through turnCredentials or fetch them with refreshTurnCredentials. Signaling alone does not supply them automatically. Keep the secret API key on your backend. See TURN configuration.
REST equivalent
POST /v1/turn/credentials. Failures throw RelayApiError.