Setup
Install the Braintrust andvoyageai packages, then set your API keys. Requires voyageai v0.2.0 or later.1
Install packages
2
Set environment variables
.env
Auto-instrumentation
To trace Voyage AI SDK calls without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch the Voyage AI SDK at runtime.1
Initialize Braintrust and call Voyage AI
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 Voyage AI clients manually, wrap them yourself withwrapVoyageAI(). Use this when you want to instrument specific clients individually rather than all of them globally.What Braintrust traces
Braintrust patches thevoyageai SDK and creates an LLM-typed span per call:- Embedding spans (
voyageai.embed): input texts and the model as metadata, output summarized as the number of returned embeddings, and token usage (prompt_tokens,tokens). - Multimodal embedding spans (
voyageai.multimodalEmbed): multimodal content (text, images, video) as input, output summarized as the number of returned embeddings, and token usage. - Rerank spans (
voyageai.rerank): query and documents as input, results as a list of{index, relevance_score}items (capped at 100), and request parameters (model,returnDocuments,topK,truncation) as metadata. - Contextualized embedding spans (
voyageai.contextualizedEmbed): inputs and model as metadata, output summarized as the total number of returned embeddings, and token usage. - Response metadata (model name when returned by the API).
- Errors captured on every call.