Before createSession() can run in the browser, your backend must mint a credential. The credential is a short-lived LiveKit URL and token, scoped to a single session. No secrets reach the client.

Getting a Session Credential

How the Credential Flow Works

A session credential is produced in two hops:

  1. Your backend authenticates with Bourne, then calls POST /guide/session with your agentId and any session options. Bourne returns a SessionCredential object containing a LiveKit URL and a scoped token.
  2. Your frontend receives that credential from your own token endpoint, then calls createSession({ credential }). The SDK uses the credential to join the LiveKit room — your API key never leaves the server.

All session configuration (agent selection, interaction mode, language, credit cap) is baked into the credential at creation time. The browser cannot override these values after the fact.

Backend Step — Calling the Token Endpoint

Your backend calls:

POST /guide/session

The only required parameter is agentId. All others are optional and have sensible defaults.

ParameterTypeDefaultDescription
agentIdstringrequiredYour agent configuration ID
mode"voice" | "video""voice"Device mode
interactionMode"guided_steps" | "immediate_feedback""guided_steps"Session interaction mode
langstring"en-US"Language code
enableRagbooleantrueEnable retrieval from user-uploaded documents
activeAccesstagstring""Filter system knowledge docs by this tag
llmModelstring"gpt-4o-mini"LLM model for agent reasoning
videoFpsnumber3Video frame rate (1–10)
videoProcessorstring"none"Video processor (e.g. "yolo-pose")
feedbackTaskstring""Task description — required when using immediate_feedback mode
feedbackTipsPerCyclenumber1Tips per feedback cycle (1–5)
feedbackAutoIntervalSecondsnumber0Auto-feedback interval in seconds (0–600)
continueRunIdstringnullResume a previous session by run ID
endUserRefstringnullEnd-user identifier (A-Za-z0-9_-, up to 64 chars)
maxCreditsPerSessionnumbernullCredit cap for this session

The endpoint returns a SessionCredential object. Pass this object directly to createSession() — do not unpack or modify it.

Frontend Step — Calling createSession()

Once your backend exposes the credential at your own endpoint (e.g. /api/your-token-endpoint), your frontend fetches it and bootstraps the session:

import { createSession } from "@picoagent/embed-core";

const credential = await fetch("/api/your-token-endpoint").then(r => r.json());
const session = await createSession({ credential });

createSession() validates the credential's protocolVersion, connects to the LiveKit infrastructure, and returns a Session object. From here you attach transports (attachVoice, attachVideo) and subscribe to events.

Session Events

Once a session is created, subscribe to agent events with session.on():

EventPayloadDescription
plan{ plan }The agent's current plan — list of steps and metadata. Fires on session start and whenever the plan changes.
step_update{ stepIndex, totalSteps }The active step index changed. Use this to update your step indicator UI.
session_ended{ reason }The session has ended. reason may be "completed", "timeout", "credit_limit", or "error".
error{ code, message }A session-level error occurred. Handle and surface to the user as appropriate.

Session Resume

The SDK automatically persists the current runId in browser session storage. Use getResumeRunId() to retrieve it — do not read session storage directly, since the key name is an SDK implementation detail and may change. If the user refreshes the page mid-session, you can detect and resume the previous session:

import { createSession, getResumeRunId } from "@picoagent/embed-core";

// On page load — check for an in-progress session
const existingRunId = getResumeRunId();

// Pass it to your backend, which forwards it to the token endpoint
const credential = await fetch("/api/your-token-endpoint", {
  method: "POST",
  body: JSON.stringify({
    agentId: "your-agent-id",
    continueRunId: existingRunId ?? undefined,
  }),
}).then(r => r.json());

const session = await createSession({ credential });

When continueRunId is set, Bourne resumes the session from where it left off — the plan state, step index, and conversation history are all restored.

Next Steps