Installation
Core Functions
init()
Initializes the ZeroEval SDK. Must be called before using any other SDK features.
Parameters
Example
redaction uses camelCase keys in TypeScript. Redaction applies only to
ingested payload fields (input_data and output_data). Attributes, tags,
session metadata, and error messages are not redacted.
Wrapper Functions
wrap()
Wraps a supported AI client to automatically trace all API calls.
Supported Clients
- OpenAI SDK (
openaipackage) - Vercel AI SDK (
aipackage) - Claude Agent SDK (
@anthropic-ai/claude-agent-sdkpackage)
Examples
wrapClaudeAgentSdk()
Wraps the entire @anthropic-ai/claude-agent-sdk module so that query() and session helpers are automatically traced.
Example
wrapClaudeAgentQuery()
Wraps only the query function from the Claude Agent SDK.
Example
Spans API
withSpan()
Wraps a function execution in a span, automatically capturing timing and errors.
SpanOptions
Example
@span Decorator
Decorator for class methods to automatically create spans.
Example
Requires
experimentalDecorators: true in your tsconfig.json.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
Prompts API
prompt()
Creates or fetches versioned prompts from the Prompt Library. Returns decorated content for downstream LLM calls.
PromptOptions
Behavior
- Auto-optimization (default): If
contentis provided withoutfrom, tries to fetch the latest optimized version first, falls back to provided content - Explicit mode (
from: "explicit"): Always uses providedcontent, bypasses auto-optimization - Latest mode (
from: "latest"): Requires an optimized version to exist, fails if none found - Hash mode (
from: "<hash>"): Fetches a specific version by its 64-character SHA-256 content hash
Examples
Return Value
Returns a decorated prompt string with metadata header used by integrations:Errors
sendFeedback()
Sends feedback for a completion to enable prompt optimization.
SendFeedbackOptions
Example
Utility Functions
renderTemplate()
Render a template string with variable substitution.
extractVariables()
Extract variable names from a template string.
sha256Hex()
Compute SHA-256 hash of text.
normalizePromptText()
Normalize prompt text for consistent hashing.
Error Classes
PromptNotFoundError
Thrown when a specific prompt version (by hash) is not found.
PromptRequestError
Thrown when a prompt request fails (e.g., no versions exist for from: "latest").
Types
Prompt
PromptMetadata
Environment Variables
Set before importing ZeroEval to configure default behavior.Configuration Examples
Production
Development
Need help? Check out our GitHub
examples or
reach out on Discord.