Skip to main content
Last updated on

Browser client

Choose the browser entry point that fits your application; each exposes the same session-aware client.

ApplicationImport
Reactimport { useMythos } from '@mythos-work/sdk/react'
Any bundled pageimport { initMythos } from '@mythos-work/sdk/client'
No bundlerThe global <script> build

React​

tsx
const { status, session, error, fetch, confirmCharge, relaunch } = useMythos();

Any bundled page​

typescript
import { initMythos } from '@mythos-work/sdk/client';

const m = initMythos();
await m.ready;
const unsubscribe = m.subscribe(() => console.log(m.state.status));

No bundler​

html
<script src="https://cdn.jsdelivr.net/npm/@mythos-work/sdk@0.5.0/dist/mythos-client.global.js"></script>
<script>const m = Mythos.initMythos();</script>

Statuses​

StatusMeaningWhat your UI should do
loadingSession initialization is in progressShow a loading state
mythosA Mythos launch session is activeEnable Mythos billing
standaloneThe app was opened outside MythosUse your own auth or paywall
expiredThe launch session expiredEmbedded clients request a relaunch automatically; offer relaunch() as a manual fallback
errorInitialization failedShow error and a retry path

Automatic relaunch​

initMythos({ autoRelaunch: false }) disables the default one-time mythos:relaunch request to the embedding Mythos dashboard on expiry. For manual recovery, display a relaunch() button when status is expired. Standalone pages never post a relaunch. The client schedules a silent session refresh before identity expiry and checks again when a background tab becomes visible.

Transport​

The client uses an HTTP-only cookie first, so session credentials are normally unavailable to JavaScript. If the browser blocks cookies, the SDK falls back to its managed transport. Your code never reads, parses, or stores Mythos tokens in localStorage or sessionStorage. This keeps transport details inside the SDK while preserving the same API in embedded and standalone browsers.

Use m.fetch (or the fetch returned by useMythos) like native fetch; it automatically attaches the current session. Before a billable action, call confirmCharge({ credits, reason }) for a fixed price, or confirmCharge({ kind: 'llm', reason }) for LLM calls — those are usage-based (provider cost plus your margin, settled after the response), so they take no credits.