Skip to main content

Introduction

The Alcamine JavaScript SDK provides a type-safe, promise-based interface for connecting your web application to Alcamine voice agents in just a few lines of code. All networking and media handling is taken care of behind the scenes so you can focus on building great experiences.

When should I use it?

  1. Spin up a new realtime voice session with an Alcamine agent.
  2. Resume an existing conversation.
  3. Interact with the underlying room object (subscribe to tracks, mute/unmute, etc.).
  4. Capture analytics events inside your product.
If you only need to call the REST API (for example from your backend) take a look at our HTTP reference.

Installation

Quick start

…and that’s it! Your browser’s microphone is automatically enabled and audio is sent to the agent as soon as the room connects.

API reference

alcamine.init(publicKey: string, config?: AlcamineConfig)

Initializes the SDK. Must be called before any other method. Calling init() more than once is a no-op and will log a warning in development.

alcamine.connect(options): Promise<{ session: Session }>

Starts or resumes a voice session. When resolved you receive session – an object containing id, timestamps and other metadata. A room is created in the background and microphone input is buffered until the connection is fully established.

alcamine.disconnect(sessionId?: string): Promise<void>

Gracefully ends the audio call and marks the session as completed in Alcamine.
  • If sessionId is provided, only that room is disconnected.
  • If omitted, all active rooms are disconnected – handy for global clean-up, for example in a window.beforeunload handler.

alcamine.getRoom(sessionId: string): Room | undefined

Returns the underlying room instance so you can:
  • Listen to room-level events (participantJoined, trackSubscribed, …).
  • Toggle microphone or speaker state.
  • Access statistics such as RTT and packet loss.

alcamine.captureEvent(name: string, properties: Record<string, any>): Promise<void>

Optional helper that sends a custom analytics event to Alcamine. Events show up in your analytics dashboard in real-time and can be used to build funnels or triggers.

Type definitions

The SDK ships with full TypeScript typings. Key interfaces:
Hover over methods in your editor to see the complete types.

Error handling

All methods throw standard JavaScript errors for fatal conditions, so wrap async calls in try/catch or use .catch() to handle them gracefully.

Troubleshooting

  • You have already initialized Alcamine!init() was called more than once. This is safe to ignore, but you probably want to remove the duplicate call.
  • Room not found – you called getRoom() with a wrong or expired sessionId.
  • Continuous reconnections – check that your firewall allows WebRTC traffic.

Next steps

  • Read the HTTP API reference for low-level control.
  • Explore our React hooks package for rapid UI integration.
  • Join the community on Discord to share what you build and get help!
Happy coding! 👋