@eka-care/ekascribe-ts-sdk handles microphone capture, voice-activity detection, chunked upload and session lifecycle for you. It also ships a prebuilt recording Widget, session/document utilities (history, details, documents), and Eka env / clientId handling.
Prerequisites
- Node 14+
npmoryarn- Microphone access via browser permissions
- Stable network connectivity
- An access token from Eka Care
Installation
Integration Guide (Step-by-Step)
Step 1: Initialize the SDK
The SDK uses a singleton pattern —getEkaScribeInstance() always returns the same instance for a given env + clientId combination.
flavour and allianceConfig.baseUrl are both required. flavour identifies your app variant on every request — Eka Care issues the value to use. Omitting baseUrl throws [EkaScribe] allianceConfig.baseUrl is required at runtime.
To use Eka Care’s hosted scribe service, set baseUrl to:
- Calling
getEkaScribeInstance()again with the same config returns the same instance. - If
envorclientIdchanges, the old instance is automatically reset. - If only
access_tokenchanges, the token is updated without resetting. - One active recording at a time. Call
endRecording()orcancelSession()before starting a new one.
Step 2: Register Callbacks
Register callbacks before starting a recording — events fire immediately once recording starts.onTokenRequired must return the new token as a string. The handler has a 10 second timeout.Step 3: Start Recording
startRecordingV2() creates the session, starts the microphone, and begins chunked upload in one call. It returns TStartRecordingResponse — check error_code, then read the session id from txn_id.
Use
clinical_notes_template for testing, or contact Eka Care to create a custom template for your use case. Call ekascribe.sessions.getConfig() to list the templates enabled for your account.Step 4: Pause / Resume
Optional, during recording. Pausing stops VAD processing — the mic stays open and no new chunks are created.Step 5: End Recording
Stops the microphone, flushes the last audio chunk, waits for uploads, and tells the server the session has ended — which triggers server-side processing. Onaudio_upload_failed, retry the failed chunks with retryUploadRecording().
Step 6: Poll for Results
getSessionStatus() returns an SDKResult — check success before reading data.
Step 7: Cancel Instead of End (optional)
Stops recording without triggering processing.Step 8: Clean Up
resetInstance() tears down the singleton — clears state, destroys the widget, removes callbacks. Call getEkaScribeInstance() again afterwards to get a fresh instance.
Flow Diagram
Full Example
Important Notes
flavouris required. It identifies your app variant on every request. Eka Care issues the value to use.allianceConfig.baseUrlis the root for all API calls. Session creation, audio upload, status polling — everything uses this URL. It is required; omitting it throws at runtime.access_tokenmust be a valid Bearer token. All API requests includeAuthorization: Bearer <token>. If it expires, registeronTokenRequiredto auto-refresh.- Register callbacks before
startRecordingV2(). Events fire immediately once recording starts — if callbacks aren’t registered, you’ll miss upload progress and errors. endRecording()triggers server processing. UsecancelSession()instead if you don’t want processing to happen.- Recording methods and status methods report errors differently.
startRecordingV2()/endRecording()return anerror_codefield;getSessionStatus()returns anSDKResultyou check withresult.success. - One active recording at a time. Call
endRecording()orcancelSession()before starting a new one. - Microphone permission is requested on
startRecordingV2(). If denied, you get themicrophoneerror code. resetInstance()is a full teardown. It clears state, destroys the widget and removes callbacks. CallgetEkaScribeInstance()again afterwards.
Bundler Setup (Vite / Webpack / Next.js)
The SDK uses a SharedWorker for background audio uploads. Modern bundlers handle this automatically. Vite — works out of the box. Webpack 5 — works out of the box (new URL(..., import.meta.url) is natively supported).
Next.js — ensure the SDK is used only on the client:
sharedWorkerUrl in config. Resolve it with the built-in helper:
Prebuilt Widget (zero-UI recording)
The SDK provides an optional pre-built recording UI injected via Shadow DOM — you write zero UI code. Step 1: Enable the widget in config with session defaults and callbacks:startForPatient() per patient — the widget appears and the user drives it (pause, resume, stop). Results arrive via callbacks.
startRecordingV2(), pauseRecording(), resumeRecording(), endRecording(), and getSessionStatus() internally.
Widget state flow:
Session & Document Utilities
Helpers for fetching session history, details, and documents.getSessionHistory(request)
Fetch previous sessions.
getSessionDetails(request)
Detailed info including documents, context, and presigned URLs.
Presigned URLs are temporary — checkpresigned_url_expires_at(epoch) before using. CallgetDocument(documentId)for a fresh URL if expired.
getDocument(documentId)
Fetch a single document by ID (and a fresh presigned URL).
patchSessionStatus(request, sessionId?)
Update session properties.
Account config (getConfig)
Call ekascribe.sessions.getConfig() to fetch your account config: supported languages, output formats, consultation modes, and my_templates (the valid template_id values to pass when starting a recording). clinical_notes_template is a ready-to-use testing template; contact Eka Care for a custom one.
TGetConfigV2Response
Discovery
ekascribe.sessions.getDiscoveryDocument() returns what the server supports — models, languages, upload methods and audio formats.
Pre-recorded Audio Upload
Upload a pre-recorded audio file instead of live recording, for non-real-time flows.- Create session via
ekascribe.sessions.createSession() - Upload audio via
processPreRecordedAudio() - End session via
ekascribe.sessions.endSession()
Authentication
The token you pass at init is used for every request. Two ways to keep it fresh: Automatic (recommended) — registeronTokenRequired; the SDK calls it on a 401 and retries the failed request:
updateAuthTokens() propagates a new token to all internal transports and the worker:
If you haveonTokenRequiredregistered, the SDK handles 401s automatically. You only needupdateAuthTokens()for proactive token rotation (e.g. before expiry).
Configuration
Recording Options
Passed tostartRecordingV2():
API Reference
Instance lifecycle
Recording
Session
Documents
Widget
Auth
Callbacks
Register withekascribe.registerCallback(name, handler).
Payload shapes
Request / Response Types
Recording responses
Session
Error Handling
The SDK reports errors two ways, depending on the method. Recording methods (startRecordingV2, endRecording) return an error_code field:
getSessionStatus) return an SDKResult<T> — errors are returned, not thrown:
Error Codes
Deprecated Methods
These methods are from older SDK versions. They still work but are not recommended for new integrations.Source and specification
- EkaScribe TS SDK — source for
@eka-care/ekascribe-ts-sdk

