跳到正文

实时通信

实时音视频房间、按参与者的访问令牌与参与者管理,覆盖 LiveKit / Agora / Zego。

1. 概览

基础路径: https://api.infrai.cc/v1/rtc
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/rtc capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/rtc/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. 方法 (7)

2.1rtc.room.create

POST /v1/rtc/room/create

在所选 RTC vendor 上创建实时音视频房间。部分 vendor(Agora/Zego)无持久房间对象——房间在首次加入时具现,记录为合成。

参数

名称类型必填说明
namestring
必填
房间名称(账户内唯一)。
≥ 1 chars
max_participantsnumber可选最大并发参与者数。
≥ 1
empty_timeout_snumber可选空闲多少秒后自动关闭。
≥ 0
metadataRecord<string, unknown>可选任意键值元数据。
regionstring可选承载房间的边缘区域。
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选显式 vendor 锁定。
idempotency_keystring可选客户端提供的幂等键。

返回

Room { room, name, max_participants, created_at }
名称类型说明
room_idstring供应商房间 SID,无 SID 时为房间名。
namestring资源的可读名称
≥ 1 chars
vendor"livekit" | "agora" | "tencent_rtc" | "zego"处理此请求的供应商
state"active" | "closed"当前生命周期状态
max_participantsinteger | null房间允许的最大参与人数
≥ 0
num_participantsinteger房间当前参与人数
≥ 0default: 0
created_atstring | null资源创建时间(ISO 8601)
metadataobject | null附加在此资源上的任意键值元数据

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/rtc/room/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "example"}'

2.2rtc.room.get

GET /v1/rtc/room/get/{room}

获取单个 RTC 房间的状态与实时在线人数。

参数

名称类型必填说明
roomstring
必填
房间 id。

返回

Room
名称类型说明
room_idstring供应商房间 SID,无 SID 时为房间名。
namestring资源的可读名称
≥ 1 chars
vendor"livekit" | "agora" | "tencent_rtc" | "zego"处理此请求的供应商
state"active" | "closed"当前生命周期状态
max_participantsinteger | null房间允许的最大参与人数
≥ 0
num_participantsinteger房间当前参与人数
≥ 0default: 0
created_atstring | null资源创建时间(ISO 8601)
metadataobject | null附加在此资源上的任意键值元数据

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/rtc/room/get/ROOM \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.3rtc.room.list

GET /v1/rtc/room/list

列出账户下活跃的 RTC 房间 / 频道。

参数

名称类型必填说明
cursorstring可选不透明分页游标。
limitnumber可选返回条目的最大数量。

返回

{ items: Room[], next_cursor?: string }
名称类型说明
itemsobject[]RTC room records列表
next_cursorstring | null下一页游标;null 表示最后一页

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/rtc/room/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.4rtc.room.delete

DELETE /v1/rtc/room/delete/{room}

关闭 RTC 房间(无删除 API 的 vendor 会在空闲时自动关闭)。

参数

名称类型必填说明
roomstring
必填
房间 id。

返回

{ ok: boolean }
名称类型说明
room_idstring供应商房间 SID,无 SID 时为房间名。
namestring已删除的房间名称
≥ 1 chars
vendor"livekit" | "agora" | "tencent_rtc" | "zego"处理此请求的供应商
state"active" | "closed"删除后的生命周期状态(始终为 "closed";无删除 API 的供应商在空闲时自动关闭)
max_participantsinteger | null房间允许的最大参与人数
≥ 0
num_participantsinteger房间当前参与人数
≥ 0default: 0
created_atstring | null此资源创建的 ISO 8601 时间戳
metadataobject | null附加在此资源上的任意键值元数据

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/rtc/room/delete/ROOM \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.5rtc.token.issue

POST /v1/rtc/token/issue

为单个参与者签发加入令牌(vendor 原生 JWT/AccessToken2/token04,本地签名)。概念上按参与者分钟计费;带宽 / 出口按成本兜底。

参数

名称类型必填说明
roomstring
必填
房间 id。
≥ 1 chars
identitystring
必填
参与者唯一身份 / uid。
≥ 1 chars
display_namestring可选参与者可读名称。
ttl_snumber可选令牌有效时长(秒)。
≥ 1default: 3600
can_publishboolean可选允许参与者发布媒体流。
default: true
can_subscribeboolean可选允许参与者订阅媒体流。
default: true
can_publish_databoolean可选允许参与者发布数据消息。
default: true
is_adminboolean可选授予参与者管理员权限。
default: false
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选显式 vendor 锁定。
metadataRecord<string, unknown>可选任意键值元数据。

返回

AccessToken { token, room, identity, expires_at }
名称类型说明
tokenstring认证或验证令牌
≥ 1 chars
roomstring房间名称或标识符
identitystring参与者身份字符串
vendor"livekit" | "agora" | "tencent_rtc" | "zego"处理此请求的供应商
expires_atstring | null资源或令牌过期时间(ISO 8601)
format: date-time
ws_urlstring | null客户端连接的供应商 WebSocket/信令 URL。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/rtc/token/issue \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"room": "sample", "identity": "sample"}'

2.6rtc.participant.list

GET /v1/rtc/participant/list/{room}

列出房间中当前的参与者。

参数

名称类型必填说明
roomstring
必填
房间 id。

返回

{ items: Array<{ identity, display_name?, joined_at }> }
名称类型说明
itemsobject[]房间当前参与者(供应商无花名册读取能力时为空,如 tencent_rtc)
items[].identitystring参与者身份字符串
items[].joined_atstring | null此成员加入的 ISO 8601 时间戳
items[].state"active" | "joining" | "disconnected"此资源当前的生命周期状态
items[].is_publisherboolean参与者是否在发布媒体流
default: false
items[].display_namestring | null可读显示名称

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/rtc/participant/list/ROOM \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.7rtc.participant.kick

POST /v1/rtc/participant/kick/{room}

强制将参与者从房间移除(踢出)。

参数

名称类型必填说明
roomstring
必填
房间 id。
≥ 1 chars
identitystring
必填
参与者唯一身份 / uid。
≥ 1 chars
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选显式 vendor 锁定。

返回

{ ok: boolean }
名称类型说明
okboolean参与者是否已被踢出
identitystring | null被踢出的参与者身份

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/rtc/participant/kick/ROOM \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"room": "sample", "identity": "sample"}'
高级:指定 vendor

默认情况下 infrai 会把每次调用智能路由到最佳可用供应商——无需自己挑选 vendor。作为高级逃生口,本能力支持可选的 vendor 入参以锁定某个供应商。本能力当前所有可用 vendor 可通过该能力 id 对应的 discovery 端点实时获取——参见 discovery API

GET /v1/discovery/{capability}

rtc.room.create

rtc.token.issue

rtc.participant.kick

3. 全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

rtc.participant.kickPOST /v1/rtc/participant/kick/{room}

Forcibly remove (kick) a participant from a room.

参数 (3)
名称类型必填说明
roomstring必填Path param; the room name.
≥ 1 chars
identitystring必填Participant identity / uid to remove.
≥ 1 chars
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选Vendor that handled or will handle this request
rtc.participant.listGET /v1/rtc/participant/list/{room}

List participants currently in a room.

参数 (1)
名称类型必填说明
roomstring必填Path parameter.
rtc.room.createPOST /v1/rtc/room/create

Create a live audio/video room on the selected RTC vendor. Some vendors (Agora/Zego) have no persistent room object — the room materializes on first join and the record is synthesized.

参数 (7)
名称类型必填说明
namestring必填Room name (unique per account).
≥ 1 chars
max_participantsinteger | null可选Maximum number of participants allowed in the room
≥ 1
empty_timeout_sinteger | null可选Auto-close after this many seconds empty.
≥ 0
metadataobject | null可选Arbitrary key-value metadata attached to this resource
regionstring | null可选Geographic region where this resource is located or processed
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选Vendor that handled or will handle this request
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
rtc.room.deleteDELETE /v1/rtc/room/delete/{room}

Close an RTC room (vendors without a delete API auto-close when empty).

参数 (1)
名称类型必填说明
roomstring必填Path parameter.
rtc.room.getGET /v1/rtc/room/get/{room}

Fetch a single RTC room's state and live occupancy.

参数 (1)
名称类型必填说明
roomstring必填Path parameter.
rtc.room.listGET /v1/rtc/room/list

List active RTC rooms / channels for the account.

无请求参数。

rtc.token.issuePOST /v1/rtc/token/issue

Mint a per-participant join token (vendor-native JWT/AccessToken2/token04, signed locally). Billed per participant-minute conceptually; bandwidth/egress floored at cost.

参数 (10)
名称类型必填说明
roomstring必填Room name or identifier
≥ 1 chars
identitystring必填Unique per-participant identity / uid.
≥ 1 chars
display_namestring | null可选Human-readable display name
ttl_sinteger可选Time-to-live in seconds for the token
≥ 1default: 3600
can_publishboolean可选Whether the token grants publish permission
default: true
can_subscribeboolean可选Whether the token grants subscribe permission
default: true
can_publish_databoolean可选Whether the token grants data channel publish permission
default: true
is_adminboolean可选Whether the token grants admin privileges
default: false
vendor"livekit" | "agora" | "tencent_rtc" | "zego" | null可选Vendor that handled or will handle this request
metadataobject | null可选Arbitrary key-value metadata attached to this resource

4. 完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · rtc — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) rtc.room.create — POST /v1/rtc/room/create · Create a live audio/video room on the selected RTC vendor. Some vendors (Agora/Zego) have no persistent room object — the room materializes on first join and the record is synthesized.
r1 = show("rtc.room.create", infrai("POST", "/v1/rtc/room/create", {"name":"example"}))

# 2) rtc.token.issue — POST /v1/rtc/token/issue · Mint a per-participant join token (vendor-native JWT/AccessToken2/token04, signed locally). Billed per participant-minute conceptually; bandwidth/egress floored at cost.
r2 = show("rtc.token.issue", infrai("POST", "/v1/rtc/token/issue", {"room":"sample","identity":"sample"}))

# 3) rtc.room.list — GET /v1/rtc/room/list · List active RTC rooms / channels for the account.
r3 = show("rtc.room.list", infrai("GET", "/v1/rtc/room/list"))