Installation
Core Functions
init()
Initializes the ZeroEval SDK. Must be called before using any other SDK features.
Parameters
opts
(optional):InitOptions
apiKey
(optional):string
- Your ZeroEval API key. If not provided, usesZEROEVAL_API_KEY
environment variableapiUrl
(optional):string
- Custom API URL. Defaults tohttps://api.zeroeval.com
flushInterval
(optional):number
- Interval in milliseconds to flush spansmaxSpans
(optional):number
- Maximum number of spans to buffer before flushingcollectCodeDetails
(optional):boolean
- Whether to collect code location detailsintegrations
(optional):Record<string, boolean>
- Enable/disable specific integrationsdebug
(optional):boolean
- Enable debug logging
Example
Wrapper Functions
wrap()
Wraps a supported AI client to automatically trace all API calls.
Supported Clients
- OpenAI SDK (
openai
package) - Vercel AI SDK (
ai
package)
Examples
Context Functions
getCurrentSpan()
Returns the currently active span, if any.
getCurrentTrace()
Returns the current trace ID.
getCurrentSession()
Returns the current session ID.
setTag()
Sets tags on a span, trace, or session.
Parameters
target
: The target to set tags onSpan
: Sets tags on the specific spanstring
: Sets tags on the trace (if valid trace ID) or session (if valid session ID)undefined
: Sets tags on the current span
tags
: Object containing key-value pairs of tags
Example
Spans API
There are two main ways to create spans in the TypeScript SDK:withSpan()
Wraps a function execution in a span, automatically capturing input/output and timing.
opts
(SpanOptions): Configuration for the spanname
(string): Name of the spansessionId
(string, optional): Session ID to associate with the spansessionName
(string, optional): Human-readable session nametags
(object, optional): Tags to attach to the spanattributes
(object, optional): Additional attributesinputData
(any, optional): Manual input data overrideoutputData
(any, optional): Manual output data override
fn
(Function): The function to execute within the span
@span
Decorator
Decorator for class methods to automatically create spans. Requires TypeScript with experimental decorators enabled.
opts
(SpanOptions): Same configuration options aswithSpan()
tsconfig.json
includes:
Signals API
sendSignal()
Send a signal to a specific entity.
Parameters
entityType
: Type of entity to attach the signal toentityId
: UUID of the entityname
: Name of the signalvalue
: Signal value (string, boolean, or number)signalType
(optional): Signal type, auto-detected if not provided
sendTraceSignal()
Send a signal to the current trace.
sendSessionSignal()
Send a signal to the current session.
sendSpanSignal()
Send a signal to the current span.
getEntitySignals()
Retrieve signals for a specific entity.
LangChain Integration
ZeroEvalCallbackHandler
A callback handler for integrating with LangChain.
Constructor
Options
debug
(optional):boolean
- Enable debug loggingexcludeMetadataProps
(optional):RegExp
- Pattern for metadata properties to excludemaxConcurrentSpans
(optional):number
- Maximum concurrent spans. Defaults to 1000spanCleanupIntervalMs
(optional):number
- Cleanup interval in milliseconds. Defaults to 60000
Example
setGlobalCallbackHandler()
Sets a global callback handler for LangChain.
getGlobalHandler()
Gets the current global callback handler.
clearGlobalHandler()
Clears the global callback handler.
Types
InitOptions
Configuration options for SDK initialization.
SignalCreate
Structure for creating a new signal.
Signal
Structure representing a signal.
ZeroEvalCallbackHandlerOptions
Options for the LangChain callback handler.
Environment Variables
The SDK uses the following environment variables:ZEROEVAL_API_KEY
: Your ZeroEval API keyZEROEVAL_API_URL
: API endpoint URL (defaults tohttps://api.zeroeval.com
)ZEROEVAL_DEBUG
: Set totrue
to enable debug logging