Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Chat gives you two ways to build, depending on where your code runs:
- Client SDK runs in your client app. Clients use it to connect, join rooms, send and read messages, and listen for events.
- REST API runs on your server. Use it for server-side and administrative tasks, such as managing rooms, members, users, and roles.
Client SDK
The JavaScript client SDK is published as the @azure/web-pubsub-chat-client npm package. It exposes
a ChatClient that connects with a client access URL, then creates rooms, sends and reads messages,
and raises events. For a walkthrough, see Get started with Azure Web PubSub chat.
For the full API, source, and samples, see the SDK repo on GitHub.
REST API
Azure Web PubSub chat data-plane REST API manages chat resources from your server: rooms, members, messages, users, and roles. There's no dedicated Chat REST client yet, so you call these endpoints with any HTTP client.
The chat REST API lives on the same resource endpoint and hub route as the Web PubSub data-plane REST
API ({endpoint}/api/hubs/{hub}/chat/...), and it authenticates the same way as that API: with an
access key or a Microsoft Entra ID token. For how to get the token and sign each request, see
Using the REST API.
Note
For the detailed REST API specification, see the Web PubSub chat rest api definition.
With a bearer token from either method, you call a chat endpoint with any HTTP client. For example:
const endpoint = process.env.WebPubSubEndpoint; // https://contoso.webpubsub.azure.com
const hub = "chat";
const token = "<bearer token>"; // from Microsoft Entra ID or an access key, as described above
async function chatRequest(method, path, body) {
const res = await fetch(`${endpoint}/api/hubs/${hub}/chat/${path}?api-version=2026-02-01-preview`, {
method,
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
throw new Error(`Chat API ${method} ${path} failed: ${res.status}`);
}
return res.status === 204 ? undefined : res.json();
}
// Example: create a room, then add a member
await chatRequest("PUT", "rooms/falcon", { title: "Project Falcon" });
await chatRequest("PUT", "rooms/falcon/members/bob", { roleName: "room.member" });