Anywear API
The Anywear API adds live virtual try-on to your own app or website. Stream a camera into Anywear and get the edited video back in real time: the shopper wearing your garment, or style transfer, subject or background replacement. Video travels over WebRTC; a WebSocket controls the live.
Base URL https://api.anywear.studio. Authenticate with an API key in the Authorization header (the key itself, no prefix). Create keys on your account page. Usage is paid from your Anywear credit balance; buy credits on the pricing page.
Pricing and limits
- 1 Anywear credit per second, counted from the moment the live starts (a successful conn_init_ack) until it ends. Credits come from your account balance (1 Pass = 10 credits).
- Minimum 10 seconds per live that starts and renders. A live that never starts, or ends with nothing rendered (billed_seconds 0), costs nothing; its held credits are returned when it ends.
- A live runs at most 120 seconds (live.live_duration). Creating a live holds credits for its duration; the unused part is returned when it ends. With a smaller balance, live_duration is shortened to what the balance covers; below 10 credits creation fails with CreditInsufficient.
- Switching the reference image inside a live is free.
- Up to 2 lives per account at the same time.
Endpoints
POST /live/s_editing/realtime- Create a live. Returns live, rtc, render_uid and client_secret.
GET /live/v1/lives/{live_id}- Read a live: status, start and end time, close_reason, and after it ends billed_seconds and credits_cost.
WSS /live/ws/live/connect?live_id=…&conn_id=…- Control channel: start, switch the reference image, hang up.
How a live works
- Create a live with your API key (server side). Keep live.id, rtc, render_uid and client_secret.
- Open the WebSocket right after creating the live: a live that is not started within about a minute ends by itself, free of charge. In a browser, pass client_secret (valid for 10 minutes) as a query parameter; on a server you may send your API key in the Authorization header instead. Choose a conn_id (letters, digits, _ and -, up to 64 characters).
- Immediately send conn_init. The server sends nothing first.
- Wait for type 2 with payload.conn_init_ack.success = true. The live is now on_live and billing starts. On error_code NOT_READY, wait a moment and send conn_init again.
- Join the RTC channel with rtc.token and rtc.user_id, publish the camera, and subscribe to render_uid to show the edited video. Publish promptly: a live that receives no video ends within seconds with close_reason render_internal_error.
- Send switch_prompt (type 13) to change the reference image. Success has no acknowledgement; the picture changes within a few seconds. Failures arrive as type 14. Do not resend on a missing acknowledgement.
- Send hangup (type 5) to end the live. It also ends by itself after live_duration seconds. If your WebSocket drops, reconnect with the same live_id and conn_id within 20 seconds and send conn_init again; otherwise the live ends. A live stays bound to the conn_id it started with; another conn_id is refused.
Create a live
POST /live/s_editing/realtime. Unknown fields are rejected.
image_url- string, required — Reference image: an http(s) URL or a data:image/(jpeg|png|webp);base64 URI. The whole request must stay under 4 MB, so use a URL for larger images.
editing_type- string — style_transfer | virtual_tryon | subject_replacement | background_replacement. Default style_transfer.
resolution- string — 540p | 720p | 1080p | 2K. Default 540p. Case-sensitive.
rtmp_urls- string[] — Up to 5 rtmp:// addresses (2048 characters each) that also receive the result. Only with the default managed channel (artc).
managed_rtc- object — { provider: artc | trtc | agora | volcengine, enable_recording?: boolean }. Default provider artc.
customer_rtc / rtc_info- object — Use your own RTC channel instead of a managed one (the two are the same; pass one). The response then has rtc: null and render_uid: "".
curl https://api.anywear.studio/live/s_editing/realtime \
-H "Authorization: $ANYWEAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://shop.example/images/jacket.jpg",
"editing_type": "virtual_tryon",
"resolution": "720p"
}'{
"live": {
"id": "0b6f3f4e-6a0e-4c8e-9f0a-2b2b2b2b2b2b",
"live_duration": 120,
"status": "waiting",
"call_mode": "…",
"created_at": "2026-11-30T10:00:00.000Z",
"start_time": null,
"end_time": null,
"close_reason": null
},
"rtc": {
"app_id": "…",
"channel_id": "…",
"user_id": "…",
"token": "…",
"token_expire_at": "…",
"provider": "artc"
},
"render_uid": "…",
"client_secret": "lcs_…"
}The default managed channel (artc) is Alibaba Cloud RTC; its Web SDK is published by Alibaba Cloud (aliyun-rtc-sdk). With managed_rtc.provider you can use Tencent TRTC, Agora or Volcano Engine instead, with that vendor's SDK.
Control WebSocket
wss://api.anywear.studio/live/ws/live/connect. Every frame is JSON with type, live_id, conn_id, seq_id and payload. Acknowledgements carry the request's seq_id plus 1. Frames are limited to 16 MB.
const ws = new WebSocket(
"wss://api.anywear.studio/live/ws/live/connect?live_id=" + live.id +
"&conn_id=conn-1&client_secret=" + encodeURIComponent(client_secret)
);
ws.onopen = () => ws.send(JSON.stringify({
type: 1, live_id: live.id, conn_id: "conn-1", seq_id: 1,
payload: { conn_init: { version: 1 } }
}));1- client → server — conn_init: { version: 1 }
2- server → client — conn_init_ack: { success } or error_code (NOT_READY, SIP_READY_TIMEOUT, LIVE_ENDED, LIVE_CONN_INIT_FAILED)
13- client → server — switch_prompt: { prompts?: [{ type: "image", content }], editing_type? } — at least one of the two
14- server → client — switch_prompt failed: error_code, error_msg
5- client → server — hangup: { hangup_reason }
6- server → client — hangup: { hangup_reason } — the live was ended by the service (for example user_end after your hangup, or a render error); the socket closes next
{
"type": 13,
"live_id": "<live.id>",
"conn_id": "conn-1",
"seq_id": 2,
"payload": {
"switch_prompt": {
"prompts": [{ "type": "image", "content": "https://shop.example/images/dress.jpg" }]
}
}
}Close codes (the reason text names the case):
1000- LIVE_DURATION_REACHED / LIVE_ENDED / LIVE_CONNECTION_REPLACED — Normal end, or a newer connection with the same conn_id took over.
1008- UNAUTHORIZED / LIVE_ENDED / LIVE_CONNECTION_IN_USE / NOT_FOUND — Rejected: bad or expired credential, the live has ended, or another conn_id is connected.
1009- MESSAGE_TOO_BIG — A frame exceeded 16 MB.
1011- INTERNAL_ERROR / READY_TIMEOUT — The live could not be served. Read the live for its final status and charge.
Read a live
GET /live/v1/lives/{live_id} with any API key of the same account. waiting → on_live → ending → ended. billed_seconds and credits_cost are null until the live is settled, usually within a minute of its end. credits_cost is what was charged, including the 10-second minimum.
{
"live": {
"id": "0b6f3f4e-6a0e-4c8e-9f0a-2b2b2b2b2b2b",
"live_duration": 120,
"status": "ended",
"created_at": "…",
"start_time": "…",
"end_time": "…",
"close_reason": "user_end",
"billed_seconds": 46,
"credits_cost": 46
}
}close_reason: user_end, timeout, client_reconnect_timeout, audit_violation, render_internal_error.
Errors
{ "code": 400, "reason": "BAD_REQUEST", "message": "…", "metadata": {} }400- BAD_REQUEST — Invalid body or fields.
400- CreditInsufficient — Not enough credits to start a live.
401- UNAUTHORIZED — Missing or invalid API key.
404- NOT_FOUND — Unknown live_id for this account.
413- BAD_REQUEST — The request body is larger than 4 MB.
429- TOO_MANY_LIVES — More than 2 lives running. End one first.
503- SERVICE_BUSY / SERVICE_UNAVAILABLE — Temporarily unavailable. Retry later; nothing was charged.