Subscribe to a thread's new messages in realtime (WebSocket)
Opens a WebSocket connection that streams a conversation’s new messages to you live, with
no polling. As soon as either side posts a message, every connected subscriber of that thread
receives it. A thread that belongs to another customer answers 404 not_found, exactly as a
thread that does not exist does.
This is a WebSocket upgrade, not a normal request — send the standard upgrade headers
(Upgrade: websocket). The connection is served on the API’s own domain; the server responds
101 Switching Protocols and then pushes JSON frames shaped { "type", "payload" }:
{ "type": "message.created", "payload": { "thread_id": "…", "message": { … }, "environment": "production" } }
message.createdcarries{ thread_id, message, environment }.presence.joinandpresence.leavecarry{ participant: { pid, role }, participants: [ … ] }.presence.typingcarries{ participant, is_typing }andpresence.readcarries{ participant, at }.- The text frame
pingis answered withpong. A client may send{ "type": "typing", "payload": { "is_typing": true } }and{ "type": "read", "payload": { "at": "…" } }, which are relayed to the other participants; other frame types are ignored. Clients should ignore a frametypethey do not recognise.
Authentication. Because a browser WebSocket cannot set request headers, supply the
credentials as query parameters on the connection URL (they may also be sent as headers
from non-browser clients):
api_key— your publishable key (a publishable key is fine; this is a browser-origin read). This handshake is the only request that reads a key from the query string: every other messaging route requires theAuthorizationheader and answers401without it, and a secret key in the query string is refused with400.- one customer credential, proving the caller owns the thread:
auth_token— the session token of a customer signed in through Galactic Core (equivalently thex-auth-tokenheader),external_auth— a signed identity assertion for a customer authenticated with your own identity provider (equivalently thex-external-authheader), oridp_token— a raw token from your own identity provider that Galactic Core forwards to the store’s Auth verifier to validate (equivalently thex-idp-tokenheader).
The server validates the credential and confirms the customer is the thread’s participant
before accepting the socket; a connection that fails the check is refused with 401, 403 or 404 before the upgrade. Use the
subscribeToThread helper in the SDK to manage the connection (it returns an unsubscribe
function), or open the WebSocket yourself.
Send the text frame ping at intervals to keep an idle connection alive; the server replies
pong.
curl --request GET \
--url https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyAuthorizations
API Key Authentication
Use your API key in the Authorization header:
Authorization: Bearer tybrite_sk_live_YOUR_KEY
Key Types:
Secret Keys (Server-Side Only):
- Format:
tybrite_sk_live_*(production) ortybrite_sk_test_*(sandbox) - Full read/write access to all endpoints
- ⚠️ NEVER expose in client-side code or public repositories
- Required for: every write a shopper does not make for themselves, authentication, payment verification, AI recommendations
Publishable Keys (Client-Safe):
- Format:
tybrite_pk_live_*(production) ortybrite_pk_test_*(sandbox) - Catalogue reads, plus the actions a shopper takes for themselves
- ✅ Safe for client-side JavaScript, mobile apps, and public code
- Allowed for: browsing products, search, CMS content, pricing queries, cart and wishlist, reviews, storefront events, and the Agent API's quotes, cart drafts and checkout intents
Endpoint-Specific Requirements:
- Authentication endpoints (
/v1/auth/*): state-changingPOSTcalls require a secret key, for store and marketplace keys alike;GET /v1/auth/meaccepts either key - Payment verification (
POST /v1/payments/verify): Secret key required - AI Recommendations (
POST /v1/recommendations): Secret key required - Semantic Search (
POST /v1/search): Both key types allowed (read-only operation) - Shopper actions (cart, wishlist, reviews, storefront events, Agent API quotes, cart drafts and checkout intents): Both key types allowed
- All other write operations: Secret key required
- All read operations: Both key types allowed
Using a publishable key for restricted operations returns 403 Forbidden.
Limited publishable keys:
A publishable key can be limited to the products that carry one tag (for example starter:jewellery), created from
the store's Developers page. The limit applies to the key, never to the shopper: shopper sign-up and sign-in stay store-wide.
- Reads return only the slice: products (with their facets, filters, search, brands and specifications), categories and
subcategories that hold in-slice products, collections, promotions, posts and lookbooks that carry the tag, reviews of
in-slice products, prices, discovery lists and the store information summary, with every count computed on the slice.
A product outside the slice answers
404, as if it did not exist. - A write that names a product or variant outside the slice (adding to the cart or wishlist, reserving stock, an order line,
a review, a promotion calculation, a storefront event) answers
403with the error codeout_of_scope, and nothing is written or reserved. An order is refused as a whole. - A route that carries no slice behaviour is not available to the key: it answers
403withendpoint_not_allowed. - Orders placed through such a key record the tag on the order's attribution as
key_scope. - Secret keys and connected-app keys cannot be limited.
- Responses are cached per key limit: a limited key never receives a response cached for the whole store, and the reverse.
Headers
Query Parameters
Your publishable key, supplied as a query parameter for the WebSocket handshake (browsers
cannot set the Authorization header on a WebSocket). Read only on a request carrying
Upgrade: websocket; a secret key here is refused with 400 invalid_request. May also be sent as the
Authorization: Bearer header from non-browser clients.
A raw token from your own identity provider (e.g. a Firebase ID token). Galactic Core
forwards it to the store's configured Auth verifier, which validates it and returns the
identity. Fail-closed: if the verifier rejects the token or is unreachable, the connection
is not authorized. Supply exactly one customer credential (auth_token, external_auth, or
idp_token). May also be sent as the x-idp-token header.
Response
Switching Protocols — the WebSocket is established. New-message frames follow on the socket.
curl --request GET \
--url https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tybritelabs.com/v1/messaging/threads/{id}/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body
