Client Setup
How to create and configure the Base44 client.Contents
- In Base44-Generated Apps
- In External Apps
- In Backend Functions
- Authentication Modes (Anonymous, User, Service Role)
- Available Modules
- Client Methods
- Client Configuration Options
In Base44-Generated Apps
Inside a Base44 app, the client is automatically created and configured. Import it from@/api/base44Client and use it as base44:
In External Apps
When using Base44 as a backend from an external app, install the SDK and create a client by callingcreateClient() directly:
- ❌
createClient({ clientId: "..." })- WRONG parameter name - ❌
createClient({ id: "..." })- WRONG parameter name - ❌
createClient({ appId: "...", onError: ... })- WRONG: onError must be in options - ✅
createClient({ appId: "..." })- CORRECT parameter name - ✅
createClient({ appId: "...", options: { onError: ... } })- CORRECT: onError in options
In Backend Functions
createClientFromRequest() is designed for Base44-hosted backend functions. It extracts auth from request headers that Base44 injects and returns a client that includes service role access (base44.asServiceRole). For frontends and external backends, use createClient() instead.
Authentication Modes
Anonymous Mode
No authentication. Can only access public resources.User Mode
After user logs in, the client automatically includes their token.Service Role Mode
Admin-level access. Backend only.Available Modules
The client exposes these modules:base44.app and base44.actors are available at the top level only (no separate service-role variant); base44.asServiceRole.browser and base44.asServiceRole.voice are service-role only (no frontend variant). See app.md, actors.md, browser.md, voice.md, payments.md, and ai-gateway.md.
Client Methods
The client provides these methods:setToken
Updates the authentication token for all subsequent API requests and WebSocket connections.cleanup
Disconnects WebSocket connections. Call when you’re done with the client or when the component unmounts.fetchWithAuth
Calls one of your app’s own server routes with this client’s credentials attached. A plainfetch() from the browser carries no Base44 auth, and a plain fetch() between your own server routes carries none of the headers the callee’s createClientFromRequest() needs — fetchWithAuth() is the same fetch() with whatever this client holds added (the signed-in user’s bearer token in the browser; the full set of propagated Base44 headers, service role included, when called from a client made with createClientFromRequest()).
Only relative paths on your app’s own origin are allowed (e.g. /api/orders); an absolute URL or another origin throws. To call a Base44 backend function, use functions.fetch() instead; for another origin, use plain fetch().
fetchWithAuth(path: string, init?: RequestInit & { fetch?: typeof fetch }): Promise<Response>
Client Configuration Options
- The parameter name is
appId, notclientIdorid. Using the wrong parameter name will cause errors. - The
onErrorhandler must be nested inside theoptionsobject, not at the top level.