API (TypeScript)
Use this page to look up the signature of every export. There is one section per entry point, and each entry links to the guide section that explains it.
@cetra-ai/sdk
Section titled “@cetra-ai/sdk”AddedQueueItems
Section titled “AddedQueueItems”interface AddedQueueItems { readonly added: number; readonly existing: number; readonly skipped: readonly SkippedQueueItem[];}The answer of client.annotationQueues.addItems(). A target already in the queue counts as existing. See Annotation queues.
AiTelemetry
Section titled “AiTelemetry”interface AiTelemetry { isEnabled: boolean; tracer?: Tracer; functionId?: string; metadata?: Record<string, AttributeValue>;}What aiTelemetry() returns: the value to pass as experimental_telemetry. See Vercel AI SDK.
AiTelemetryOptions
Section titled “AiTelemetryOptions”interface AiTelemetryOptions { sessionId?: string; userId?: string; tags?: readonly string[]; metadata?: Readonly<Record<string, string | number | boolean>>; functionId?: string;}The options of aiTelemetry(). See Vercel AI SDK.
AnnotationQueue
Section titled “AnnotationQueue”interface AnnotationQueue { readonly id: string; readonly name: string; readonly description: string | undefined; readonly instructions: string | undefined; readonly target: QueueTarget; readonly definitionIds: readonly string[]; readonly version: number; readonly createdBy: string | undefined; readonly createdAt: string; readonly updatedAt: string; readonly counts: QueueCounts;}A queue as the server returns it, with its item counts by status. Pass its version to update(). See Annotation queues.
AnnotationQueueItem
Section titled “AnnotationQueueItem”interface AnnotationQueueItem { readonly id: string; readonly queueId: string; readonly traceId: string | undefined; readonly spanId: string | undefined; readonly sessionId: string | undefined; readonly targetTime: string; readonly status: QueueItemStatus; readonly skipReason: string | undefined; readonly leasedByUserId: string | undefined; readonly leaseExpiresAt: string | undefined; readonly doneByUserId: string | undefined; readonly doneAt: string | undefined; readonly addedBy: "user" | "pat" | "key"; readonly addedById: string; readonly createdAt: string;}One target of a queue, as client.annotationQueues.items() returns it. See Annotation queues.
AnnotationQueues
Section titled “AnnotationQueues”class AnnotationQueues { list(): Promise<AnnotationQueue[]>; get(queueId: string): Promise<AnnotationQueue>; create(name: string, options: { target: QueueTarget; definitionIds: readonly string[]; description?: string; instructions?: string }): Promise<AnnotationQueue>; update(queueId: string, options: { version: number; name?: string; description?: string; instructions?: string; definitionIds?: readonly string[] }): Promise<AnnotationQueue>; delete(queueId: string): Promise<void>; addItems(queueId: string, targets: QueueTargets): Promise<AddedQueueItems>; items(queueId: string, options?: { status?: QueueItemStatus }): Promise<AnnotationQueueItem[]>;}The annotation queue operations of client.annotationQueues. See Annotation queues.
ApiError
Section titled “ApiError”class ApiError extends Error { readonly status: number; readonly code: string | undefined; readonly detail: string | undefined; readonly errors: readonly { field: string; message: string }[];}Rejects the calls of Client and evaluate when the API answers with an error. errors holds the field errors of a refused dataset item. See Errors.
CetraOptions
Section titled “CetraOptions”interface CetraOptions { apiKey?: string; baseUrl?: string; environment?: string; release?: string; captureContent?: boolean; sampleRate?: number; mask?: (value: unknown) => unknown; useGlobalProvider?: boolean; exportFilter?: (span: ReadableSpan) => boolean; instrument?: readonly Instrumentation[]; enabled?: boolean;}The options of init(). See Configuration.
ChatEntry
Section titled “ChatEntry”type ChatEntry = ChatMessage | { type: "placeholder"; name: string };One entry of a chat template: a message whose text may hold {{ name }} variables, or a placeholder that compile() replaces with the messages it is given.
ChatMessage
Section titled “ChatMessage”interface ChatMessage { role: string; content: string;}A chat message: its role and its text. A placeholder is filled with a list of these, and compile() of a chat prompt returns a list of them.
Client
Section titled “Client”class Client { constructor(options?: ClientOptions); readonly datasets: Datasets; readonly annotationQueues: AnnotationQueues; readonly prompts: Prompts;}The REST client for datasets, prompts, experiments and annotation queues. It reads the key and the base URL the way init() does and throws ConfigError without a key. prompts holds the prompt operations: get, list, create, createVersion and setLabel. See Datasets and experiments.
ClientOptions
Section titled “ClientOptions”interface ClientOptions { apiKey?: string; baseUrl?: string; // plus the `fetch` and `sleep` injection points used by tests}The options of new Client(). See Datasets and experiments.
ConfigError
Section titled “ConfigError”class ConfigError extends Error { readonly option: string;}Thrown for a missing or invalid configuration value. The message names the option, never its value. See Configuration.
ContextOptions
Section titled “ContextOptions”interface ContextOptions { sessionId?: string; userId?: string; tags?: readonly string[]; metadata?: Readonly<Record<string, unknown>>; propagate?: boolean; prompt?: Prompt;}The options of withContext(). prompt stamps the prompt’s name and version on every span inside the block. See Context and baggage.
Dataset
Section titled “Dataset”class Dataset { readonly id: string; readonly name: string; readonly description: string | undefined; readonly version: number; readonly items: readonly DatasetItem[]; addItems(items: readonly NewDatasetItem[]): Promise<Dataset>;}A dataset at one version, with its items. addItems sends the items in batches of 1,000 and resolves to the dataset at its latest version. See Datasets.
DatasetInfo
Section titled “DatasetInfo”interface DatasetInfo { readonly id: string; readonly name: string; readonly description: string | undefined; readonly currentVersion: number; readonly itemCount: number;}One entry of client.datasets.list(): a dataset without its items. See Datasets.
DatasetItem
Section titled “DatasetItem”interface DatasetItem { readonly id: string; readonly input: unknown; readonly expectedOutput: unknown; readonly metadata: Readonly<Record<string, unknown>>; readonly version: number; readonly sourceTraceId: string | undefined; readonly sourceSpanId: string | undefined;}One item of a dataset version, as the server returns it. See Datasets.
Datasets
Section titled “Datasets”class Datasets { create(name: string, options?: { description?: string; inputSchema?: object; expectedSchema?: object }): Promise<Dataset>; get(nameOrId: string, options?: { version?: number }): Promise<Dataset>; list(): Promise<DatasetInfo[]>; delete(nameOrId: string): Promise<void>;}The dataset operations of client.datasets. See Datasets.
EvaluateOptions
Section titled “EvaluateOptions”interface EvaluateOptions { dataset: string | Dataset; task: (input: unknown, item: DatasetItem) => unknown; scorers?: readonly Scorer[]; experimentName?: string; description?: string; metadata?: Readonly<Record<string, unknown>>; datasetVersion?: number; concurrency?: number; repetitions?: number; client?: Client;}The options of evaluate(). See Experiments.
ExperimentResult
Section titled “ExperimentResult”class ExperimentResult { readonly experimentId: string; readonly experimentName: string; readonly datasetId: string; readonly datasetVersion: number; readonly runs: readonly Run[]; readonly scorerErrors: Readonly<Record<string, number>>; readonly errorCount: number; summary(): string; assertMin(name: string, threshold: number): void;}What evaluate() resolves to: one Run per item and repetition, in item order. assertMin throws when a scorer’s mean is below the threshold, which gates CI. See Experiments.
getPrompt
Section titled “getPrompt”function getPrompt(name: string, options?: GetPromptOptions): Promise<Prompt>;The prompt name at its label (default production) or at a version. It is cached in the process: a version never expires, and a label is fresh for cacheTtlS seconds (60 by default), then served stale while one refresh runs. A failed fetch falls back to the stale prompt, then to fallback, then rejects with PromptNotAvailable. Before init(), or with the SDK disabled, it behaves like a failed fetch. Bad arguments reject with TypeError.
GetPromptOptions
Section titled “GetPromptOptions”interface GetPromptOptions { label?: string; version?: number; fallback?: string | readonly ChatMessage[]; cacheTtlS?: number;}The options of getPrompt(). Pass a label or a version, not both. The fallback is a text template or a list of chat messages, used when no prompt can be fetched and no stale one is cached. cacheTtlS: 0 turns the label cache off.
Instrumentation
Section titled “Instrumentation”interface Instrumentation { setTracerProvider(provider: TracerProvider): void; enable(): void; disable(): void;}What init({ instrument }) accepts: the shape the OpenInference instrumentations have. See Instrumentation.
LlmSpanHandle
Section titled “LlmSpanHandle”interface LlmSpanHandle extends SpanHandle { setInputMessages(messages: readonly unknown[]): void; setOutputMessages(messages: readonly unknown[]): void; setResponseModel(model: string): void; setUsage(usage: Usage): void; setCost(totalUsd: number): void; recordFirstToken(): void;}The handle withLlmSpan passes to its body. See Manual spans and withLlmSpan.
LlmSpanOptions
Section titled “LlmSpanOptions”interface LlmSpanOptions { provider: string; model: string; inputMessages?: readonly unknown[]; systemInstructions?: string | readonly unknown[]; params?: Readonly<Record<string, unknown>>; metadata?: Readonly<Record<string, unknown>>;}The options of withLlmSpan(). provider and model are required non-empty strings. See Manual spans and withLlmSpan.
NewDatasetItem
Section titled “NewDatasetItem”interface NewDatasetItem { input: unknown; expectedOutput?: unknown; metadata?: Readonly<Record<string, unknown>>;}An item to add with addItems(). Any other key throws a TypeError. See Datasets.
ObserveOptions
Section titled “ObserveOptions”interface ObserveOptions { name?: string; kind?: SpanKind; captureInput?: boolean; captureOutput?: boolean; reduceOutput?: (items: unknown[]) => unknown;}The options of observe(). See Wrapper rules.
Prompt
Section titled “Prompt”class Prompt { readonly name: string; readonly type: "text" | "chat"; readonly template: string | readonly ChatEntry[]; readonly version: number | undefined; // undefined for a fallback readonly config: Readonly<Record<string, unknown>>; readonly labels: readonly string[]; readonly variables: readonly string[]; readonly placeholders: readonly string[]; readonly isFallback: boolean; compile(values?: PromptValues): string | readonly ChatMessage[];}A prompt returned by getPrompt(). compile() renders its template: a text prompt gives a string, a chat prompt a list of messages. It records cetra.prompt.name and cetra.prompt.version on the active span when that span records.
PromptCompileError
Section titled “PromptCompileError”class PromptCompileError extends Error { readonly kind: "invalid" | "missing_variable" | "missing_placeholder"; readonly variable: string | undefined; readonly reason: string | undefined; readonly line: number | undefined; readonly column: number | undefined; readonly prompt: string | undefined;}Thrown by compile() for a variable or placeholder that has no value, and by getPrompt() for an invalid fallback template. The message names the prompt and the variable, never the template or the values.
PromptNotAvailable
Section titled “PromptNotAvailable”class PromptNotAvailable extends Error { readonly prompt: string; readonly reason: string;}Thrown by getPrompt() when no prompt can be fetched and the call gave no fallback. reason is not found, status <n>, network, invalid response or sdk disabled.
Prompts
Section titled “Prompts”class Prompts { get(name: string, options?: { label?: string; version?: number }): Promise<Prompt>; list(): Promise<string[]>; create(input: { name: string; type: "text" | "chat"; template: string | readonly ChatEntry[]; config?: Record<string, unknown>; labels?: readonly string[]; commitMessage?: string; description?: string; tags?: readonly string[] }): Promise<Prompt>; createVersion(name: string, input: { template: string | readonly ChatEntry[]; config?: Record<string, unknown>; labels?: readonly string[]; commitMessage?: string }): Promise<Prompt>; setLabel(name: string, label: string, version: number): Promise<void>;}The prompt operations of client.prompts. They are not cached, and they reject with ApiError on failure.
PromptValues
Section titled “PromptValues”type PromptValues = Readonly<Record<string, string | number | boolean | readonly ChatMessage[]>>;The values of Prompt.compile(). A string, number or boolean fills {{ name }} (a boolean is true or false, and 1.0 is 1); a list of messages fills a placeholder. A value of any other type throws TypeError.
QueueCounts
Section titled “QueueCounts”interface QueueCounts { readonly pending: number; readonly completed: number; readonly skipped: number;}The item counts of an annotation queue, by status. See Annotation queues.
QueueItemStatus
Section titled “QueueItemStatus”type QueueItemStatus = "pending" | "completed" | "skipped";The status of a queue item, and the filter of items(). See Annotation queues.
QueueTarget
Section titled “QueueTarget”type QueueTarget = "trace" | "span" | "session";What the items of a queue are. It is fixed when the queue is created. See Annotation queues.
QueueTargets
Section titled “QueueTargets”type QueueTargets = | { readonly traceIds: readonly string[] } | { readonly spans: readonly (readonly [string, string])[] } | { readonly sessionIds: readonly string[] };What addItems() adds: exactly one of the three keys. A span is a [traceId, spanId] pair. See Annotation queues.
interface Run { readonly datasetItemId: string; readonly repetition: number; readonly input: unknown; readonly expectedOutput: unknown; readonly output: unknown; readonly error: string | undefined; readonly traceId: string | undefined; readonly latencyNs: number; readonly scores: Readonly<Record<string, Score>>;}The outcome of the task on one item and one repetition, with the scores it received. See Experiments.
interface Score { value: boolean | number | string; reason?: string; dataType?: "numeric" | "boolean" | "categorical" | "text"; metadata?: Readonly<Record<string, unknown>>;}What a scorer returns when it has a reason or metadata to add to the value. See Experiments.
ScoreOptions
Section titled “ScoreOptions”interface ScoreOptions { name: string; value: boolean | number | string; traceId?: string; spanId?: string; sessionId?: string; reason?: string; dataType?: "numeric" | "boolean" | "categorical" | "text"; metadata?: Readonly<Record<string, unknown>>; userId?: string; scoreId?: string;}The options of score(). See Scores.
Scorer
Section titled “Scorer”type Scorer = (args: ScorerArgs) => boolean | number | string | Score | undefined | null | Promise<boolean | number | string | Score | undefined | null>;A function that scores one run. Its name is the name of the score. See Experiments.
ScorerArgs
Section titled “ScorerArgs”interface ScorerArgs { input: unknown; output: unknown; expected: unknown; metadata: Readonly<Record<string, unknown>>; traceId: string | undefined; item: DatasetItem;}The one object a scorer receives. See Experiments.
SkippedQueueItem
Section titled “SkippedQueueItem”interface SkippedQueueItem { readonly index: number; readonly message: string;}A target that addItems() did not add. index is its position in the list you passed. See Annotation queues.
SpanHandle
Section titled “SpanHandle”interface SpanHandle { readonly traceId: string | undefined; readonly spanId: string | undefined; setInput(value: unknown): void; setOutput(value: unknown): void; setMetadata(values: Readonly<Record<string, unknown>>): void;}The handle withSpan passes to its body. Every method is a no-op after the span ended. See Manual spans and withLlmSpan.
SpanKind
Section titled “SpanKind”type SpanKind = | "llm" | "embedding" | "tool" | "agent" | "chain" | "retriever" | "reranker" | "guardrail" | "evaluator" | "span";The kinds a span can have. An invalid kind throws a TypeError. See Wrapper rules.
SpanOptions
Section titled “SpanOptions”interface SpanOptions { kind?: SpanKind; input?: unknown; metadata?: Readonly<Record<string, unknown>>;}The options of withSpan(). See Manual spans and withLlmSpan.
interface Usage { inputTokens?: number; outputTokens?: number; cacheReadTokens?: number; cacheWriteTokens?: number; reasoningTokens?: number;}The token counts setUsage records. Only safe integers are kept. See Manual spans and withLlmSpan.
VERSION
Section titled “VERSION”const VERSION: string;The version of the package. See Install.
aiTelemetry
Section titled “aiTelemetry”function aiTelemetry(options?: AiTelemetryOptions): AiTelemetry;Returns the telemetry settings for the Vercel AI SDK: a tracer from the cetra provider plus your context values as metadata. See Vercel AI SDK.
currentSpanId
Section titled “currentSpanId”function currentSpanId(): string | undefined;The id of the running span, or undefined outside a span. See Scores.
currentTraceId
Section titled “currentTraceId”function currentTraceId(): string | undefined;The id of the running trace, or undefined outside a span. See Scores.
evaluate
Section titled “evaluate”function evaluate(options: EvaluateOptions): Promise<ExperimentResult>;Runs your task on every item of a dataset version, scores each run and stores the results on the server. It needs init() first. See Experiments.
function flush(): Promise<void>;Resolves when the pending spans and scores are exported. Call it at the end of every serverless invocation. See Edge runtimes and serverless.
function init(options?: CetraOptions): void;Starts the SDK. It is called once per process; later calls are ignored. See Configuration.
observe
Section titled “observe”function observe<A extends unknown[], R>(fn: (...args: A) => R, options?: ObserveOptions): (...args: A) => R;Wraps a function so that each call is one span. See Wrapper rules.
function score(options: ScoreOptions): string | undefined;Queues a score for a trace, a span or a session and returns its id, or undefined when nothing was queued. See Scores.
shutdown
Section titled “shutdown”function shutdown(): Promise<void>;Flushes, then stops the SDK. See Edge runtimes and serverless.
spanProcessor
Section titled “spanProcessor”function spanProcessor(): SpanProcessor | undefined;Returns the span processor of the SDK, for apps that build their own OpenTelemetry pipeline. See Existing OpenTelemetry setups.
tracerProvider
Section titled “tracerProvider”function tracerProvider(): TracerProvider;Returns the tracer provider in use. See Existing OpenTelemetry setups.
function uuid7(): string;Returns a new UUIDv7, the kind of id score() mints. See Scores.
withContext
Section titled “withContext”function withContext<T>(options: ContextOptions, fn: () => T): T;Runs fn with a session, user, tags and metadata stamped on every span started inside it. See Context and baggage.
withLlmSpan
Section titled “withLlmSpan”function withLlmSpan<T>(name: string, options: LlmSpanOptions, fn: (span: LlmSpanHandle) => T): T;Runs fn inside a span that carries the GenAI attributes of a chat call. See Manual spans and withLlmSpan.
withSpan
Section titled “withSpan”function withSpan<T>(name: string, fn: (span: SpanHandle) => T): T;function withSpan<T>(name: string, options: SpanOptions, fn: (span: SpanHandle) => T): T;Runs fn inside a span. The return value of fn is never recorded; the handle’s setters write the span’s payloads. See Manual spans and withLlmSpan.
@cetra-ai/sdk/openai
Section titled “@cetra-ai/sdk/openai”openai
Section titled “openai”function openai(module: typeof OpenAI, options?: { captureContent?: boolean }): Instrumentation;Builds the OpenInference instrumentation for OpenAI and patches the module by hand. Pass the result to init({ instrument: [...] }). See Instrumentation.
@cetra-ai/sdk/anthropic
Section titled “@cetra-ai/sdk/anthropic”anthropic
Section titled “anthropic”function anthropic(module: typeof Anthropic, options?: { captureContent?: boolean }): Instrumentation;Builds the OpenInference instrumentation for Anthropic and patches the module by hand. Pass the result to init({ instrument: [...] }). See Instrumentation.
@cetra-ai/sdk/langchain
Section titled “@cetra-ai/sdk/langchain”langchain
Section titled “langchain”function langchain(module: typeof CallbackManagerModule, options?: { captureContent?: boolean }): Instrumentation;Builds the OpenInference instrumentation for LangChain and patches the module by hand. Pass the result to init({ instrument: [...] }). See Instrumentation.
@cetra-ai/sdk/browser
Section titled “@cetra-ai/sdk/browser”FeedbackOptions
Section titled “FeedbackOptions”interface FeedbackOptions { baseUrl: string; publicKey: string; traceId: string; spanId?: string; name?: string; value: number | boolean | string; comment?: string;}The options of feedback(). See Browser feedback.
feedback
Section titled “feedback”function feedback(options: FeedbackOptions): Promise<{ ok: boolean }>;Posts one end-user feedback score with a public key. It never throws and never retries: ok is false for invalid input or a failed request. See Browser feedback.