@sublay/js SDK gives you full access to the Sublay v7 API from any JavaScript environment, with no React, Redux, or state-management dependencies. Its only runtime dependency is axios. Use it in vanilla JS apps, Vue/Svelte/Solid apps, web workers, or anywhere you want the Sublay API without the React provider tree.
This SDK authenticates as an end user via a bearer token. The server derives
who is acting from that token, so — unlike the server-side
@sublay/node SDK — you never pass an actor userId.
For server-side, service-key access (acting on behalf of any user), use
@sublay/node instead.Installation
Initialization
SublayClient.init builds a client whose module namespaces are pre-bound to your project. It is async, so await it.
Configuration
Your Sublay project ID, found in the dashboard under Settings → General.
Tokens to hydrate the SDK on init (SDK-managed mode) — e.g. tokens your app
persisted from a previous session, so a reload restores the session.
An async hook returning the current access token. Providing it switches the
SDK to host-managed mode (see below): the SDK never stores or refreshes
tokens — it reads the current one from
getToken() on every request.Called whenever the SDK sets, rotates, or clears tokens (SDK-managed mode only).
Receives
null on sign-out. Use it to persist tokens so a session survives a
reload.Authentication
The SDK runs in one of two auth modes, chosen by whether you passgetToken.
SDK-managed (default)
The SDK keeps theaccessToken / refreshToken pair in memory, attaches
Authorization: Bearer <token> on every request, and auto-refreshes on a
403 (with a single-flight mutex so concurrent failures trigger only one
refresh). No storage is baked in — the SDK runs in any JS runtime — so persistence
is your job: listen to onAuthChange to save tokens, and pass them back via
initialTokens on the next load.
auth module’s signIn, signUp, and verifyExternalUser store the
returned tokens automatically; signOut clears them. You can also set or clear
them imperatively:
Host-managed
If your app already owns the access token and its refresh lifecycle, pass agetToken hook. The SDK then never stores or refreshes tokens — it reads the
current token from getToken() on each request, and on a 403 re-reads it once.
In this mode setTokens, clearTokens, and the onAuthChange callback are
no-ops.
Authorization header set on an individual request always wins over
both modes.
Modules
Once initialized, all functionality is accessed through module namespaces on the client:How this differs from @sublay/node
If you’re coming from the server SDK, three things are different here:
- No actor
userId. Functions act as the user behind the token. Params that named the acting user server-side are gone. AuserIdyou do see here is always a real target or filter — the user you’re following, a ban target, the author whose entities you’re listing — never “who is acting”. - Streaming AI Q&A.
search.askContentis an async generator over Server-Sent Events —for awaitover it to stream tokens — not a single awaited response. - Browser file uploads.
storage,chat.sendMessage, andusers.updateUseraccept browserFile/Blobobjects and sendmultipart/form-data— there’s noUint8Array+mimeTypepath.
Paginated responses
Most list functions return a sharedPaginatedResponse<T> shape:
page and limit to control pagination. A few endpoints use different
shapes — notably chat.listConversations / chat.listMessages use cursor
pagination, the search.search* functions return raw arrays, and a handful
of reaction-list endpoints return a { data, pagination: { page, limit, total, hasMore } } shape. Each is called out on its module page.
Auth
Sign up, sign in, token management, password reset, email verification
Users
Fetch and update profiles, and the per-user follow/connection graph
Entities
Create and manage content, reactions, drafts
Comments
Create and manage comments, reactions
Collections
Organize the user’s saved entities into collections
Follows
The logged-in user’s own follow graph and counts
Connections
Mutual connections, pending requests, accept/decline
Spaces
Space CRUD, navigation, slug management
Space Members
Membership, roles, approvals, bans
Space Moderation
Reports, content moderation, rules, digest
Chat
Conversations, messages, members, reactions, read state
Search
Semantic search and streaming AI Q&A
Reports
File content reports and read the moderation queue
App Notifications
Read and mark the user’s in-app notifications
Storage
Upload, fetch, and delete files and images
OAuth
OAuth sign-in/link redirect flows and linked identities

