Eka Care Ekascribe Typescript SDK Integration
This guide explains how to integrate the Eka Care Ekascribe Typescript SDK into your application.Overview
The Eka Care Ekascribe SDK allows you to capture and process audio, generating structured medical documentation using Eka Care’s voice transcription API.Prerequisites
- Node 14+
npmoryarn- Microphone access via browser permissions
- Stable network connectivity
- Access token from Eka Care
Installation
Install the SDK usingnpm or yarn:
Bundler Setup
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. Thenew URL(..., import.meta.url) pattern is natively supported.
Next.js
Ensure the SDK is only used on the client side:Browser (Script Tag)
Instance Management
The SDK uses a singleton pattern.getEkaScribeInstance() always returns the same instance for a given env + clientId combination.
- Calling
getEkaScribeInstance()multiple times with the same config returns the same instance. - If
envorclientIdchanges, the old instance is automatically reset. - If only
access_tokenchanges, the token is updated on the existing instance without resetting. - The SDK supports one active recording at a time. Always call
endRecording()orcancelSession()before starting a new recording. If you callstartRecordingV2()while a recording is active, the SDK cleans up the old recording locally but does not end the session on the server — the old session will be left abandoned until it expires.
Integration Guide
Step 1: Initialize the SDK
EkaScribeConfig
Step 2: Register Callbacks
Register callbacks before starting a recording. Events fire immediately once recording starts.Step 3: Start Recording
Creates a session and starts the microphone in one call.RecordingOptions
Response: TStartRecordingResponse
Step 4: Pause / Resume
Response: TPauseRecordingResponse
Step 5: End Recording
Stops the microphone, flushes pending audio, waits for all uploads, and ends the session on the server (triggers processing).Response: TEndRecordingResponse
Step 6: Get Output
UsegetSessionStatus() to poll for results after ending the recording.
Response: SDKResult<GetSessionStatusResponse>
Step 7: Clean Up
resetInstance(), you must call getEkaScribeInstance() again to get a new instance.
Flow Diagram
Callbacks Reference
Register withregisterCallback(name, handler). Remove with removeCallback(name, handler).
onTokenRequired
Called automatically when the SDK receives a 401 from any API call. Your handler must return a fresh access token. The SDK will update its internal token and retry the failed request.
- The handler must return
Promise<string>orstring - The SDK times out after 10 seconds — if your refresh takes longer, the request fails
- Once the token is returned, the SDK calls
updateAuthTokens()internally — you don’t need to call it yourself - This replaces the old pattern of manually checking
status_code: 401in every response
Type
onRecordingStateChange
Fired when recording state transitions.
Type
onAudioEvent
Fired for speech detection, silence warnings, chunk creation, and frame processing.
Type
onUploadEvent
Fired for upload progress, failures, and retries.
Type
onSessionEvent
Fired on session lifecycle events.
Type
onError
Fired on SDK errors — VAD failures, worker errors, network issues, validation errors.
Type
Removing Callbacks
Retry Failed Uploads
IfendRecording() returns audio_upload_failed, retry the failed uploads:
Response: TEndRecordingResponse
Cancel a Session
Cancel a session without triggering server-side processing.Response: SDKResult<PatchSessionResponse>
Pre-Recorded Audio Upload
Upload a pre-recorded audio file instead of live recording. Use this for non-real-time flows. Flow:- Create session via
ekascribe.sessions.createSession() - Upload audio via
processPreRecordedAudio() - End session via
ekascribe.sessions.endSession()
Request
Response: TStartRecordingResponse
Session Utils
getSessionHistory(request)
Fetch previous sessions.
Response: TGetTransactionHistoryResponse
getSessionDetails(request)
Get detailed information about a specific session, including documents, context, and presigned URLs.
presigned_url. To get the actual document content (notes, transcript, etc.), you need to fetch it from this URL:
Presigned URLs are temporary — checkpresigned_url_expires_at(epoch timestamp) before using. CallgetDocument(documentId)to get a fresh presigned URL if expired.
Request
Response: TGetV1SessionDetailsResponse
getDocument(documentId)
Fetch a single document by ID. Use this to get a fresh presigned URL if the previous one has expired.
Response: TPostV1DocumentResponse
patchSessionStatus(request, sessionId?)
Update session properties (patient details, status, templates).
Discovery
getDiscoveryDocument()
Get the raw discovery document fetched during initialization. Contains server capabilities (supported models, languages, upload methods, audio formats).
DiscoveryDocument | null.
getDiscoveryConfig()
Get the resolved configuration derived from the discovery document.
SDKResult<ResolvedConfig>.
Widget
The SDK provides an optional pre-built recording UI. When enabled, the SDK injects a floating widget into your page via Shadow DOM — you write zero UI code.Integration
Step 1: Enable the widget in SDK config with session defaults and callbacks:startForPatient() for each patient — the widget appears and the user interacts with it directly (pause, resume, stop). You receive results via callbacks.
startRecordingV2(), pauseRecording(), resumeRecording(), endRecording(), and getSessionStatus() internally.
Widget State Flow
Types
Authentication
updateAuthTokens(token)
Manually update the access token. This propagates the 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).
SharedWorker Configuration
The SDK offloads audio compression and upload to a SharedWorker for better main-thread performance. If SharedWorker is unavailable or fails, the SDK silently falls back to main-thread processing.Setup
- The worker URL must be accessible from the same origin or have proper CORS headers
- Remember to revoke blob URLs when done:
URL.revokeObjectURL(workerUrl) - If
sharedWorkerUrlis not provided, the SDK uses the main thread (no SharedWorker)
Error Codes
Deprecated Methods
These methods are from the older SDK version. They still work but are not recommended for new integrations.initTransaction(request)
Creates a session on the server. Must be followed by startRecording().
startRecording(microphoneID?)
Starts recording for an already initialized session.
getTemplateOutput(request)
Fetches processed template output for a session.
getOutputTranscription(request)
Fetches the transcription output for a session.
commitTransactionCall()
Commits the current transaction on the server.
stopTransactionCall()
Stops the current transaction on the server.
Full Example
Refer EkaScribe TS SDK for SDK implementation.

