Introduction
Copied!Confused about "Introduction"?
Let us know how we can improve our documentation:
Welcome to REST API documentation for Stream Chat!
It explains the Chat API concepts.
Please note
Copied!The REST documentation is recommended for advanced users that want to write their own API clients. Have a look below at the official clients, framework integrations, and community-contributed libraries.
Always feel free to get in touch if you have questions.
Are you looking for a ready-made client or framework library?
Copied!If you're looking to get started quickly, official clients are available for most popular languages including Ruby, JavaScript, Python, PHP, Go, and more.
First steps
Copied!Confused about "First steps"?
Let us know how we can improve our documentation:
1. Complete 'Getting Started'
Copied!Before you start writing your client, we recommend that you complete the getting started tutorial. It explains the Chat API concepts, and allows you to get familiar with Stream.
2. Review Official Clients
Copied!Reviewing the official Stream API clients is a great source of inspiration for writing your own client.
A good starting point is the official JavaScript client as it runs its test suite in the browser.
You can review all of our open-source libraries at the official Stream GitHub page.
3. Browse Documentation
Copied!This documentation page includes all API endpoints and describes the three authentication available to use Stream Chat.
Got stuck? No worries at all, feel free to contact support at any time.
Basics
Copied!Confused about "Basics"?
Let us know how we can improve our documentation:
Common Parameters
Copied!Every request should contain api_key query parameter and appropriate authorization header
name | type | description | default | optional |
---|---|---|---|---|
api_key | string | Application public API key | - |
Compression
Copied!Stream API supports gzip and deflate compression, make sure that your client negotiate compression. Enabling compression can reduce significantly latency and used bandwidth and it's highly recommended.
JSON
Copied!Unless specified differently, all request body data must be JSON encoded and all responses are also JSON encoded.
Authentication
Copied!Confused about "Authentication"?
Let us know how we can improve our documentation:
API Keys and Tokens
Copied!Every API request to Stream must include: the API Key of the app performing the request and an authentication token generated using the API Key secret. Token must be a JWT token including a signature generated with the HS256 algorithm.
If you are not familiar with JWT we highly recommend reading more about it here. Libraries to generate JWT are available for most programming languages. The full list is available here.
The authentication token must include the correct claims (also called payload). A token valid for a type of request or for a user_id
might not be valid for another one. Your application should generate the appropriate token; when using client-side auth, each user should have its own unique token.
Sending an Authenticated Request
Copied!All API requests to Stream must include a query parameter called api_key
with the API Key in use. Once the token is generated correctly it is used to authenticate a request. This is done by setting two HTTP headers on the request:
Header | Value | Description |
---|---|---|
Stream-Auth-Type | jwt | Sets authentication type. Possible values: jwt, anonymous |
Authorization | <token> | Sets JWT authentication token when jwt auth type is used |
When dealing with authentication tokens, you should keep in mind that tokens are like passwords. Never share tokens with untrusted parties.
Server-side
Copied!Confused about "Server-side"?
Let us know how we can improve our documentation:
Requests from a back-end application to Stream Chat API should use Server-Side Authentication to authenticate requests.
JWT Usage for Server-side Authentication
Copied!For server-side authentication, the application should send a token that is signed with the API Secret of the Stream app. This token must not include any claim beside claims defined by JWT specifications (ie. "iat", "exp", ...).
You should never share a server-side token with any untrusted party or use it directly on the mobile or web-browser. If your API secret or server-side token gets compromised you should create a new API Key from the dashboard and delete the one that got compromised.
Some endpoints can only used with server-side auth; ie. changing the configuration of your application or perform other actions such as changing users' role.
Token Example
Copied!Here is the server-side token for a fictional application with API Secret "top-secret": eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.-hJRcjmUOcS0P-Pllpe8gnOtMINmm7Ktebd3eKUroAc
Client-side
Copied!Confused about "Client-side"?
Let us know how we can improve our documentation:
Requests from a front-end application to the Stream Chat API should use Client-Side Authentication to authenticate requests.
JWT Usage For Client-side Authentication
Copied!When using client-side auth, you generate different token to each of your user and include their string ID in the user_id
claim.
A common approach is to have your users authenticate with your app server-side and to provision a user token so that API calls to Stream can be done on their behalf directly on your mobile/web app.
For security reasons, some API endpoints and some specific actions can be performed only server-side.
User tokens will effectively authenticate the user based on the user_id claim. After that all API calls will be checked for permissions.
More information about permissions is available on Chat Documentation.
Token Example
Copied!Here is the user token for user "jack" on a fictional application with API Secret "top-secret": eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiamFjayJ9.pO3Fa8TJnPXsl62-XHK94S8hFk6dUz_2Q9au6H5xBSQ
Anonymous
Copied!Confused about "Anonymous"?
Let us know how we can improve our documentation:
Anonymous authentication allows you to use a sub-set of Chat's API without generating a user token.
Anonymous authentication works exactly as client-side auth with a couple of exceptions:
You must not send the Authorization header
You must send the
stream-auth-type
header set toanonymous
For security reasons, only a small subset of the API endpoints will be available to anonymous users.
Websocket
Copied!Confused about "Websocket"?
Let us know how we can improve our documentation:
Stream Chat uses Websocket connections to propagate chat events to all connected clients in real-time. Websockets are only used by Chat API servers to push events to users, you do not need them server-side.
Your Chat application should create a websocket connection per each user and wait until such connection is established before doing any other API call.
Websocket and Authentication
Copied!Websocket connections must include authentication information; since it is not possible to send HTTP headers or a request body; such information must be included as query parameters:
Query parameter | Value | Description |
---|---|---|
stream-auth-type | jwt | Same as Stream-Auth-Type header |
authorization | <token> | Same as Authorization header |
Websocket and User Data
Copied!Websocket connection must include the full information for the current user as well; the API endpoint will ensure that such user exists and will update it if necessary.
Websocket Hello Event
Copied!When the websocket connection is created with valid credentials and user payload; you will receive an event which includes fundamental information for later user of chat. Such message includes:
Current user's information including unread counts, the list of muted users and banned status
The
connection_id
for this session; you should store this, some API endpoints requires this parameter to be provided
Websocket Health-check events
Copied!After the websocket connection is correctly established, the client will receive health-checks messages periodically. Your Chat client should make sure that such health-check event is received not later than 30 seconds ago; if that's not the case you should close and retry connecting.
Websocket and retries
Copied!Unlike REST API calls, websocket connections are long-lived and might get closed due to internet connection errors. The recommended approach is to monitor internet connection, websocket close and error events and always retry to connect when a network issue causes the connection to break.
Websocket and Precondition Errors
Copied!If you provide invalid authentication information or invalid data payload, an error message will be sent to the client and the connection will be closed with a status 1000 Normal Closure
immediately after.
You can inspect the error message to gather more information about the failure and use that to decide what to do next. Error messages are JSON encoded and have the same schema as the ones from REST API endpoints.
When the connection is closed with such status you should not blindly retry to create the connection as it will almost certainly fail again with the same error. {
Websocket Events
Copied!Once the websocket is created, you can move on and subscribe the user to channels either by using the Query Channels
API endpoint or the Get Or Create Channel
. From that point on, you will receive events related to all channels the user is watching (ie. messages from other users, typing events, mark read events, ...).
Websocket Notification Events
Copied!You should expect the websocket connection to receive events that are not related to channels that the user is watching with the current websocket connection.
Campaigns
Copied!Create campaignbetaserver-side
Copied!Confused about "Create campaign,[object Object]"?
Let us know how we can improve our documentation:
POST /campaignsRead more: Campaigns (beta)
Request Body Schema
Copied!Responses
Copied!Create segmentserver-side
Copied!Confused about "Create segment,[object Object]"?
Let us know how we can improve our documentation:
POST /segmentsRead more: Campaigns (beta)
Request Body Schema
Copied!Responses
Copied!Delete campaignbetaserver-side
Copied!Confused about "Delete campaign,[object Object]"?
Let us know how we can improve our documentation:
DELETE /campaigns/{id}Read more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Delete segmentserver-side
Copied!Confused about "Delete segment,[object Object]"?
Let us know how we can improve our documentation:
DELETE /segments/{id}Read more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Query campaignsserver-side
Copied!Confused about "Query campaigns,[object Object]"?
Let us know how we can improve our documentation:
GET /campaignsRead more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Query recipientsserver-side
Copied!Confused about "Query recipients,[object Object]"?
Let us know how we can improve our documentation:
GET /recipientsRead more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Query segmentsserver-side
Copied!Confused about "Query segments,[object Object]"?
Let us know how we can improve our documentation:
GET /segmentsRead more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Resume campaignbetaserver-side
Copied!Confused about "Resume campaign,[object Object]"?
Let us know how we can improve our documentation:
PATCH /campaigns/{id}/resumeRead more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Schedule campaignbetaserver-side
Copied!Confused about "Schedule campaign,[object Object]"?
Let us know how we can improve our documentation:
PATCH /campaigns/{id}/scheduleRead more: Campaigns (beta)
Parameters
Copied!Request Body Schema
Copied!>=0
Responses
Copied!Stop campaignbetaserver-side
Copied!Confused about "Stop campaign,[object Object]"?
Let us know how we can improve our documentation:
PATCH /campaigns/{id}/stopRead more: Campaigns (beta)
Parameters
Copied!Responses
Copied!Test campaignbetaserver-side
Copied!Confused about "Test campaign,[object Object]"?
Let us know how we can improve our documentation:
POST /campaigns/{id}/testRead more: Campaigns (beta)
Parameters
Copied!Request Body Schema
Copied!>=1
<=10
Responses
Copied!Update campaignbetaserver-side
Copied!Confused about "Update campaign,[object Object]"?
Let us know how we can improve our documentation:
PUT /campaigns/{id}Read more: Campaigns (beta)
Parameters
Copied!Request Body Schema
Copied!Responses
Copied!Update segmentserver-side
Copied!Confused about "Update segment,[object Object]"?
Let us know how we can improve our documentation:
PUT /segments/{id}Read more: Campaigns (beta)
Parameters
Copied!Request Body Schema
Copied!Responses
Copied!Channel types
Copied!Create channel typeserver-side
Copied!Confused about "Create channel type,[object Object]"?
Let us know how we can improve our documentation:
POST /channeltypesRead more: Overview
Request Body Schema
Copied!Name
Channel type name
Typing events
Typing events support
Read events
Read events support
Connect events
Connect events support
Reactions
Enables message reactions
Replies
Enables message replies (threads)
Search
Enables message search
Mutes
Enables mutes
Uploads
Enables file uploads
URL enrichment
Enables URL enrichment
Custom events
Enables custom events
Push notifications
Enables push notifications
Message retention
Number of days to keep messages. 'infinite' disables retention
Maximum message length
Number of maximum message characters
Auto moderation
Enables automatic message moderation
allowed values:
- disabled
- simple
- AI
Auto moderation behavior
Sets behavior of automatic moderation
allowed values:
- flag
- block
Commands
List of commands that channel supports
Permissions
List of permissions for the channel type
Blocklist
Name of the blocklist to use
Blocklist behavior
Sets behavior of blocklist
allowed values:
- flag
- block
Responses
Copied!Delete channel typeserver-side
Copied!Confused about "Delete channel type,[object Object]"?
Let us know how we can improve our documentation:
DELETE /channeltypes/{name}Read more: Overview
Parameters
Copied!Name
Channel type name
Responses
Copied!Get channel typeserver-side
Copied!Confused about "Get channel type,[object Object]"?
Let us know how we can improve our documentation:
GET /channeltypes/{name}Read more: Overview
Parameters
Copied!Name
Channel type name
Responses
Copied!List channel typesserver-side
Copied!Confused about "List channel types,[object Object]"?
Let us know how we can improve our documentation:
GET /channeltypesRead more: Overview
Responses
Copied!Update channel typeserver-side
Copied!Confused about "Update channel type,[object Object]"?
Let us know how we can improve our documentation:
PUT /channeltypes/{name}Read more: Overview
Parameters
Copied!Request Body Schema
Copied!<=20000
allowed values:
- disabled
- simple
- AI
allowed values:
- flag
- block
allowed values:
- flag
- block
Auto moderation thresholds
Sets thresholds for AI moderation
Commands
List of commands that channel supports
Responses
Copied!Channels
Copied!Delete channel
Copied!Confused about "Delete channel,[object Object]"?
Let us know how we can improve our documentation:
DELETE /channels/{type}/{id}Read more: Deleting Channels
Parameters
Copied!Channel type
Channel type to interact with
Channel ID
Channel ID to interact with
Responses
Copied!Events
Copied!When channel is deleted
Permissions
Copied!To delete a channel
Deletes channels asynchronously
Copied!Confused about "Deletes channels asynchronously,[object Object]"?
Let us know how we can improve our documentation:
POST /channels/deleteRead more: GDPR Compliance
Request Body Schema
Copied!Channels CID
All channels that should be deleted
>=1
<=100
Hard delete
Specify if channels and all ressources should be hard deleted
Responses
Copied!Events
Copied!When a channel is deleted
Permissions
Copied!To delete a channel
Export channelsserver-side
Copied!Confused about "Export channels,[object Object]"?
Let us know how we can improve our documentation:
POST /export_channelsRead more: Exporting Data
Request Body Schema
Copied!Channels
Export options for channels
>=1
<=25
Clear deleted message text
Set if deleted message text should be cleared
Include truncated messages
Set if you want to include truncated messages
Responses
Copied!Export channels statusserver-side
Copied!Confused about "Export channels status,[object Object]"?
Let us know how we can improve our documentation:
GET /export_channels/{id}Read more: Exporting Data
Parameters
Copied!ID
Task ID
Responses
Copied!Get or create channel (type, id)
Copied!Confused about "Get or create channel (type, id),[object Object]"?
Let us know how we can improve our documentation:
POST /channels/{type}/{id}/queryRead more: Watching a Channel
Parameters
Copied!Type
Channel type
ID
Channel ID
Request Body Schema
Copied!Watch
Start watching the channel
State
Refresh channel state
Presence
Fetch user presence info
Hide for creator
Whether this channel will be hidden for the user who created the channel or not
Responses
Copied!Events
Copied!If channel is created
If member is added
If member is removed
If member is updated
If watch: true
Get or create channel (type)
Copied!Confused about "Get or create channel (type),[object Object]"?
Let us know how we can improve our documentation:
POST /channels/{type}/queryRead more: Watching a Channel
Parameters
Copied!Type
Channel type
Request Body Schema
Copied!Watch
Start watching the channel
State
Refresh channel state
Presence
Fetch user presence info
Hide for creator
Whether this channel will be hidden for the user who created the channel or not
Responses
Copied!Events
Copied!If channel is created
If member is added
If member is removed
If member is updated