개발자 레퍼런스

백엔드에서 토큰 발급하기

입장 토큰을 발급하는 지원되는 방식 — 그리고 빠지는 순간 단일 세션 강제가 조용히 꺼지는 단 하나의 필드.

UTD Stream 개발자로 돌아가기

왜 백엔드에서?

서버 시크릿은 절대 앱에 담기지 않습니다. APK에 포함된 키는 추출되어 누구의 신원으로든 도용될 수 있습니다.

기기 정보를 전달하세요

서버는 기기를 볼 수 없습니다. 앱이 값을 여러분의 서버로 보내고, 서버가 같은 요청에 담아 전달합니다.

실패는 조용합니다

Without device_id the token still succeeds, but the engine cannot tell a reconnect from a takeover: the newest session replaces the old one, yet the old device is not removed from the room and there is no takeover cooldown. Nothing errors, so nobody notices.

What your backend must forward

Your backend sits between the engine and the handset, so these reach us only if you put them in the token request body.

필드What it isIf you leave it out
device_idA stable id per app install. It lets the engine tell a reconnect from a takeover.The newest session still replaces the old one, but the old device is not removed from the room and there is no 10-second takeover cooldown. The token rate-limit key falls back to your server's IP. Not rejected today; strongly recommended.
client_ipThe end user's public IP, sent in the request body, only on a Server-Secret request.Sets the participant's country and, with geo-routing, the nearest media node. A missing, private or malformed value is ignored silently and your server's address is used. Never rely on X-Forwarded-For.
device_model, os, os_version, app_versionOptional device facts the engine cannot see through your backend.Nothing breaks; per-handset quality analysis simply has less to work with.

토큰 요청 필드

헤더에 서버 시크릿을 담아 /api/v1/token 으로 POST 하세요.

필드수준의미
user_idstring필수Who the token is for. Your own user id. (Previously `identity` — still accepted.)
room_idstring필수Which room they are joining. (Previously `room_name` — still accepted.)
device_idstring권장A stable id for the PHYSICAL DEVICE (max 200 chars) — not the user, and not the session. With it, a second device taking over inside 10 seconds is refused with 429 (session_cooldown) and the same device reconnecting reuses its session. Without it the request still succeeds, but the engine cannot tell a reconnect from a takeover: the newest session replaces the old one (the old session's user_token then gets 401 session_superseded), yet the old device is not removed from the room and there is no cooldown. The token rate-limit key also falls back to the caller's IP — from a backend, one address for all its users. Not required today; strongly recommended.
client_ipstring권장The END USER's public IP address, forwarded from your server. We see the address of whoever calls this endpoint — which, once you mint from your backend, is your data centre for every one of your users. That address decides the country we stamp on the participant AND which media node a new room opens on, so leaving it out can place a room as if all your users sat in your own data centre instead of where they are. Only honoured on a server-authenticated request (never app_key, where the handset's own address is already correct), and a private or malformed value is ignored rather than rejected.
device_modelstring권장e.g. SM-A175F. Feeds per-handset quality analysis — which models have audio or video trouble.
osstring권장android | ios.
os_versionstring권장e.g. 14.
app_versionstring권장Your app's version, so a regression can be traced to a release.
namestring선택The participant's display name, shown to other participants.
display_namestring선택The ROOM's display name, used when the room is created. It does not name the participant — use name for that.
rolestring선택host | admin | guest | audience | visitor (default audience). A request, not a grant: an admin claim from a client is ignored (you get audience). Appoint moderators from your backend with PUT /rooms/:room/participants/:id/role.
typestring선택audio_room | live_stream. Legacy kits send `service` (+ `kind`) instead and the type is derived.

서버 쪽

시크릿은 여기에만 존재합니다. 표시된 필드는 앱에서 오며, 서버가 스스로 알 수 없습니다.

mint-token.js
// Your backend — the app never sees the server secret.
const res = await fetch("https://udt-stream.com/api/v1/token", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-App-Id": process.env.UTD_APP_ID,
    "X-App-Secret": process.env.UTD_SERVER_SECRET,   // never ship this in the app
  },
  body: JSON.stringify({
    // The user comes from YOUR logged-in session, never from the request body the app sends.
    user_id: session.userId,
    room_id: roomId,
    type: "audio_room",                              // or "live_stream"

    // 🔴 The user's own public IP, not your server's. Without it every user of yours
    // is placed and geo-located as if they sat in your data centre.
    // Behind ONE trusted proxy set app.set("trust proxy", 1) and use req.ip. Do not read
    // X-Forwarded-For yourself: a client can send its own value.
    client_ip: req.ip,

    // 🔴 Forwarded FROM THE APP. Your server cannot know these on its own,
    // and without device_id the engine cannot tell a reconnect from a takeover.
    device_id: body.device_id,
    device_model: body.device_model,
    os: body.os,
    os_version: body.os_version,
    app_version: body.app_version,
  }),
});
const { token, url, user_token, ws_url } = await res.json(); // hand these to the app

기존 이름 `identity`와 `room_name`도 같은 의미로 계속 작동합니다.

앱 쪽

기기 정보를 여러분의 백엔드로 보내면 그대로 전달됩니다. 기기 식별자는 앱 재시작 후에도 동일해야 합니다.

request_token.dart
// Your app — send the device facts to YOUR backend, which forwards them to us.
final deviceId = await MyDeviceIdentity.stableId(); // persisted, survives app restarts
await myApi.post("/rooms/$roomId/token", body: {
  "device_id": deviceId,
  "device_model": deviceInfo.model,
  "os": Platform.isAndroid ? "android" : "ios",
  "os_version": deviceInfo.version,
  "app_version": packageInfo.version,
});

거부 코드 (403)

모든 거부에는 code가 있습니다. 코드를 읽으세요 — "퇴장되었습니다" 메시지는 첫 번째에만 띄워야 합니다.

코드의미조치
user_bannedThis user is banned from this room.Show them they were removed. This is the ONLY code that should produce that message.
room_type_disabledThe project does not have this room type enabled.A configuration problem, not a user problem. Never show a removal notice.
streaming_disabledThe streaming service is not enabled for this project.Same — configuration, not the user.
appkey_identity_mint_disabledYou tried to mint an identity-bearing token with the publishable app_key.Mint from your backend with your Server Secret (X-App-Id + X-App-Secret) instead, taking the user's identity from your own logged-in session. This is the path this page describes. Some older projects still carry a temporary exception; new projects do not get it.

Other codes you will meet

Branch on the HTTP status and the code field, never on the message text.

Status코드의미
401token_expiredThe user token's lifetime ended. Mint a new one.
401session_supersededA newer session exists for the same user. Do not retry with this token.
429token_rate_limited30 token requests a minute per project + user + device. Back off with jitter.
429identity_rate_limitedToken requests for one user_id across all its devices. Back off.
429session_cooldownA different device tried to take over a session set up in the last 10 seconds. Wait a few seconds.
429project_rate_limited / user_rate_limitedREST budget of the whole project / of one user. Back off.

Token errors? Check the code field in the response and the tables above. Contact support with your app_id and the time of the request.

Kit versions

As of 2026-11-29. The first published version of each kit that sends a device id, and the first that accepts a token minted by your backend (tokenProvider). Newer is recommended: check pub.dev for the latest release.

PackageSends device_idtokenProvider
utd_live_room_kit1.0.01.2.0
utd_audio_room_kit1.1.01.3.0

With tokenProvider your backend mints the token, so device_id reaches the engine only if your backend forwards it in the token request.

최신 버전

Package최신 버전
utd_stream_sdk0.8.0
utd_audio_room_kit4.2.1
utd_live_room_kit4.0.4
utd_media_client2.12.1
utd_signaling0.4.0
utd_calls_kit0.10.0
utd_chat_kit0.10.0
utd_video_effects_kit0.16.2

인증 모드

엔진은 모든 입장에 인증 모드를 기록하므로, 실제로 어느 경로인지 확인할 수 있습니다.

secret / signature / bearer

Your backend, authenticated with your server secret. The recommended path.

app_key

The device, using the publishable app key. Closed by default; some older projects still carry a temporary exception, new projects do not get it.

UTD와 함께 빌드할 준비가 되셨나요?

계정을 만들고, 마스터 지갑을 충전한 뒤, 필요한 서비스를 켜세요.