Skip to content

Server API

This page explains the server-side APIs used by AI Chat. Role management and device-role binding APIs are documented in Apifox. This page only expands the AI Chat connection credential API.

Authentication (TGV1-HMAC-SHA256)

The signing method is the same as Tange Cloud OpenAPI server-side signing. See 服务端API接口签名算法Demo.

Role and Device-Role Binding APIs

For role management, device-role binding, and device-role query APIs, see the Tange OpenAPI Documentation (Apifox).

Request Connection Credentials

Request a short-lived peer_id and token for the device to establish a TiRTC connection. Credentials are short-lived (typically minutes); the device should use them as soon as possible.

  • Endpoint: POST https://api-tirtc.tange365.com/v1/token/aichat

Request Headers

HeaderDescription
Content-Typeapplication/json
AuthorizationTGV1 authorization line
X-Tg-AlgorithmAlgorithm name, fixed as TGV1-HMAC-SHA256
X-Tg-DateRequest time (UTC format)
X-Tg-App-IdApplication ID; must match the credential app_id
X-Tg-Content-Sha256SHA-256 hash of the request body (lowercase hex)
X-Tg-Signed-HeadersList of header names included in the signature

For the format and signing steps for these TGV1-related headers, see Authentication (TGV1-HMAC-SHA256).

Request Body

json
{
  "device_id": "DEMO_DEVICE_01",
  "role_id": "role_xxx"
}
FieldTypeRequiredDescription
device_idstringYesDevice ID. Must be registered and bound to your application on the Tange platform.
role_idstringYesRole ID from the console role configuration or device-role binding query.

Response Example

json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "peer_id": "whips://aichat?device_id=DEMO_DEVICE_01&role_id=role_xxx",
    "token": "v1.{payload}.{signature}"
  }
}

Send only peer_id and token to the device via a secure channel. Do not pass the whole response. Credentials are short-lived; use them promptly to avoid connection failures due to expiration.

Error Codes

Common Errors for /v1/token/aichat

Error CodeHTTP StatusDescription
AuthFailure.SignatureFailure401Signature verification failed. Check CanonicalURI, X-Tg-Date time offset, and Body SHA-256.
AuthFailure.TokenExpired401The timestamp in the request signature has expired. Ensure X-Tg-Date is within the allowed range.
InvalidParameter400Invalid request parameters, e.g. device_id or role_id is empty.
ResourceNotFound.Device404Device is not registered or not bound to the current application.
ResourceNotFound.Role404Role does not exist or has not been published.
LimitExceeded429Request rate limit exceeded. Reduce call frequency and retry.
InternalError500Platform internal error. Contact technical support with the request_id.

For role management and device-role binding errors, see the Tange OpenAPI Documentation (Apifox).

AI Chat