Edit

Chat SDKs and REST API

Azure Web PubSub Chat provides three development surfaces. Choose one based on where your code runs and the operations it performs.

Surface Runs in Use it to
Client SDK Client applications Connect over WebSockets, create rooms, manage room members, exchange messages, read history, and handle real-time events.
Service SDK Server applications Manage roles, users, rooms, members, conversations, and persisted messages, and generate client access URLs.
REST API Server applications Perform the same administrative operations directly over HTTP.

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, creates rooms, sends and reads messages, and raises real-time events.

For a walkthrough, see Get started with Azure Web PubSub Chat. For the full API, source, and samples, see the Chat client SDK source repository.

Note

The client package @azure/web-pubsub-chat-client is different from the server-side JavaScript service package @azure/web-pubsub-chat.

Service SDKs

Chat service SDKs wrap the data-plane REST API in language-specific clients. They run in a trusted server environment and can authenticate with a connection string, an access key, or Microsoft Entra ID.

Important

Azure Web PubSub Chat and the available Chat service SDKs are in preview. Beta SDK APIs can change before general availability.

Language Package Status Reference
Python azure-messaging-webpubsubchatservice Preview Chat service SDK for Python
JavaScript @azure/web-pubsub-chat Preview Chat service SDK for JavaScript
.NET Azure.Messaging.WebPubSub.Chat Preview Chat service SDK for .NET
Java com.azure:azure-messaging-webpubsub-chat Preview Chat service SDK for Java

The standard Web PubSub service SDKs don't expose Chat-specific resources. Use a Chat service SDK or the Chat REST API when you work with roles, users, rooms, members, conversations, or persisted messages.

REST API

The Azure Web PubSub Chat data-plane REST API manages Chat resources from your server. Use it directly when a Chat service SDK isn't available for your language.

The Chat REST API uses the same resource endpoint and hub route as the Web PubSub data-plane REST API ({endpoint}/api/hubs/{hub}/chat/...). Authenticate with an access key or a Microsoft Entra ID token. For information about getting a token and signing each request, see Using the REST API.

Note

For the detailed REST API specification, see the Web PubSub Chat REST API reference.

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" });

Next steps