Skip to main content
This page is part of an AI coding agent skill and is written for agents, not humans. For the human-readable Base44 docs, see the developer documentation.

Client Setup

How to create and configure the Base44 client.

Contents

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 calling createClient() directly:
Common Mistakes:
  • ❌ 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 plain fetch() 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().
Signature: fetchWithAuth(path: string, init?: RequestInit & { fetch?: typeof fetch }): Promise<Response>

Client Configuration Options

⚠️ Critical:
  • The parameter name is appId, not clientId or id. Using the wrong parameter name will cause errors.
  • The onError handler must be nested inside the options object, not at the top level.

Type Definitions

CreateClientConfig

Base44Client