Setup
Install the Braintrust and@elevenlabs/elevenlabs-js packages, then set your API keys. Requires @elevenlabs/elevenlabs-js v2.67.0 or later.1
Install packages
2
Set environment variables
.env
Auto-instrumentation
To trace ElevenLabs SDK calls without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch the ElevenLabs SDK at runtime.1
Initialize Braintrust and call ElevenLabs
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.If you’re using a bundler, see Trace LLM calls for plugin and loader setup.
Manual instrumentation
To trace ElevenLabs clients manually, wrap them yourself withwrapElevenLabs(). Use this when you want to instrument specific clients individually rather than all of them globally.What Braintrust traces
Braintrust patches the@elevenlabs/elevenlabs-js SDK and creates an LLM-typed span per call:- Text-to-speech spans (
elevenlabs.textToSpeech.convert): input text, voice ID, and model as metadata. Generated audio is attached as a Braintrust attachment with content typeaudio/mpeg. - Streaming text-to-speech spans (
elevenlabs.textToSpeech.stream): same as above, withtime_to_first_tokencaptured for the first audio chunk. - Timestamped text-to-speech spans (
elevenlabs.textToSpeech.convertWithTimestamps,elevenlabs.textToSpeech.streamWithTimestamps): same fields as their non-timestamped counterparts, including word-level timing data. - Transcription spans (
elevenlabs.speechToText.convert): audio input and model as metadata. Transcript text is captured as output. - Errors captured on every call.
Webhook transcription and Speech Engine sessions are not instrumented.