跳到正文

实时通信

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

概览

基础路径: 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"

方法

rtc.room.create

POST /v1/rtc/room/create

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

参数

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

返回

Room { room, name, max_participants, created_at }

示例

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

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
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": "..."}'

rtc.room.get

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

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

参数

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

返回

Room

示例

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

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

rtc.room.list

GET /v1/rtc/room/list

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

参数

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

返回

{ items: Room[], next_cursor?: string }

示例

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

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

rtc.room.delete

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

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

参数

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

返回

{ ok: boolean }

示例

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

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

rtc.token.issue

POST /v1/rtc/token/issue

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

参数

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

返回

AccessToken { token, room, identity, expires_at }

示例

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

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
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": "...", "identity": "..."}'

rtc.recording.start

POST /v1/rtc/recording/start

对房间启动服务端合成录制(LiveKit Egress);其他 vendor 返回明确的不支持错误。

参数

名称类型必填说明
roomstring
必填
房间 id。
layoutstring可选录制合成布局。
audio_onlyboolean可选仅录制音频。
output_uristring可选存储目标(s3://、gs:// 等)。
vendorstring可选显式 vendor 锁定。
metadataRecord<string, unknown>可选任意键值元数据。
idempotency_keystring可选客户端提供的幂等键。

返回

Recording { recording, room, status }

示例

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

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

rtc.recording.stop

POST /v1/rtc/recording/stop/{recording}

停止进行中的录制。

参数

名称类型必填说明
recordingstring
必填
录制 id。

返回

Recording { recording, status, output_uri? }

示例

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

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

rtc.participant.list

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

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

参数

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

返回

{ items: Array<{ identity, display_name?, joined_at }> }

示例

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

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

rtc.participant.kick

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

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

参数

名称类型必填说明
roomstring
必填
房间 id。
identitystring
必填
参与者唯一身份 / uid。
vendorstring可选显式 vendor 锁定。

返回

{ ok: boolean }

示例

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

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
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": "...", "identity": "..."}'
高级:指定 vendor

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

GET /v1/discovery/{capability}

rtc.room.create

rtc.token.issue

rtc.recording.start

rtc.participant.kick

全部能力

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

能力端点说明
rtc.participant.kickPOST /v1/rtc/participant/kick/{room}Forcibly remove (kick) a participant from a room.
rtc.participant.listGET /v1/rtc/participant/list/{room}List participants currently in a room.
rtc.recording.startPOST /v1/rtc/recording/startStart a server-side composite recording of a room (LiveKit Egress); other vendors return an honest unsupported error.
rtc.recording.stopPOST /v1/rtc/recording/stop/{recording}Stop an in-progress recording.
rtc.room.createPOST /v1/rtc/room/createCreate 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.
rtc.room.deleteDELETE /v1/rtc/room/delete/{room}Close an RTC room (vendors without a delete API auto-close when empty).
rtc.room.getGET /v1/rtc/room/get/{room}Fetch a single RTC room's state and live occupancy.
rtc.room.listGET /v1/rtc/room/listList active RTC rooms / channels for the account.
rtc.token.issuePOST /v1/rtc/token/issueMint a per-participant join token (vendor-native JWT/AccessToken2/token04, signed locally). Billed per participant-minute conceptually; bandwidth/egress floored at cost.

完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 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://console.infrai.cc (Google/
GitHub sign-in grants $2 free credit). 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_pk_proj_..."  # <- 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":"..."}))

# 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":"...","identity":"..."}))

# 3) rtc.recording.start — POST /v1/rtc/recording/start · Start a server-side composite recording of a room (LiveKit Egress); other vendors return an honest unsupported error.
r3 = show("rtc.recording.start", infrai("POST", "/v1/rtc/recording/start", {"room":"..."}))

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