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
| Header | Description |
|---|---|
Content-Type | application/json |
Authorization | TGV1 authorization line |
X-Tg-Algorithm | Algorithm name, fixed as TGV1-HMAC-SHA256 |
X-Tg-Date | Request time (UTC format) |
X-Tg-App-Id | Application ID; must match the credential app_id |
X-Tg-Content-Sha256 | SHA-256 hash of the request body (lowercase hex) |
X-Tg-Signed-Headers | List 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
{
"device_id": "DEMO_DEVICE_01",
"role_id": "role_xxx"
}| Field | Type | Required | Description |
|---|---|---|---|
device_id | string | Yes | Device ID. Must be registered and bound to your application on the Tange platform. |
role_id | string | Yes | Role ID from the console role configuration or device-role binding query. |
Response Example
{
"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 Code | HTTP Status | Description |
|---|---|---|
AuthFailure.SignatureFailure | 401 | Signature verification failed. Check CanonicalURI, X-Tg-Date time offset, and Body SHA-256. |
AuthFailure.TokenExpired | 401 | The timestamp in the request signature has expired. Ensure X-Tg-Date is within the allowed range. |
InvalidParameter | 400 | Invalid request parameters, e.g. device_id or role_id is empty. |
ResourceNotFound.Device | 404 | Device is not registered or not bound to the current application. |
ResourceNotFound.Role | 404 | Role does not exist or has not been published. |
LimitExceeded | 429 | Request rate limit exceeded. Reduce call frequency and retry. |
InternalError | 500 | Platform internal error. Contact technical support with the request_id. |
For role management and device-role binding errors, see the Tange OpenAPI Documentation (Apifox).