API (Python)
Use this page to look up the signature of every public name in cetra.__all__; each entry links to the guide section that explains it.
AddedQueueItems
Section titled “AddedQueueItems”class AddedQueueItems: added: int existing: int skipped: tuple[SkippedQueueItem, ...]What client.annotation_queues.add_items returns: the targets added, the ones already in the queue, and the ones skipped, each with its position in the call. See Annotation queues.
AnnotationQueue
Section titled “AnnotationQueue”class AnnotationQueue: id: str name: str description: str | None instructions: str | None target: QueueTarget definition_ids: tuple[str, ...] version: int created_by: str | None created_at: str updated_at: str counts: QueueCountsAn annotation queue with its item counts, as the server returns it. See Annotation queues.
AnnotationQueueItem
Section titled “AnnotationQueueItem”class AnnotationQueueItem: id: str queue_id: str trace_id: str | None span_id: str | None session_id: str | None target_time: str status: QueueItemStatus skip_reason: str | None leased_by_user_id: str | None lease_expires_at: str | None done_by_user_id: str | None done_at: str | None added_by: Literal["user", "pat", "key"] added_by_id: str created_at: strOne target of a queue, as client.annotation_queues.items returns it. The reviewer fields are set by the web UI. See Annotation queues.
ApiError
Section titled “ApiError”class ApiError(Exception): status: int code: str | None detail: str | None errors: Sequence[Mapping[str, object]]Raised by Client, evaluate and aevaluate when the API answers with an error. status, code and detail come from the server’s problem document, and errors holds the field errors of a refused dataset item. See Errors.
Client
Section titled “Client”class Client: def __init__(self, *, api_key: str | None = None, base_url: str | None = None) -> None: ... datasets: Datasets annotation_queues: AnnotationQueues prompts: PromptsThe REST client for datasets, experiments, annotation queues and prompts. It reads the key and the base URL the way init() does and raises ConfigError without a key. See Datasets and experiments, Annotation queues and Prompts.
ConfigError
Section titled “ConfigError”class ConfigError(ValueError): ...Raised for a missing or invalid configuration value. The message names the option or environment variable, never its value. See Configuration.
Dataset
Section titled “Dataset”class Dataset: id: str name: str description: str | None version: int items: tuple[DatasetItem, ...]
def add_items(self, items: Iterable[Mapping[str, Any]]) -> Dataset: ...A dataset at one version, with its items. add_items sends the items in batches of 1,000 and returns the dataset at its latest version. See Datasets.
DatasetInfo
Section titled “DatasetInfo”class DatasetInfo: id: str name: str description: str | None current_version: int item_count: intOne entry of client.datasets.list(): a dataset without its items. See Datasets.
DatasetItem
Section titled “DatasetItem”class DatasetItem: id: str input: Any expected_output: Any metadata: Mapping[str, Any] version: int source_trace_id: str | None source_span_id: str | NoneOne item of a dataset version, as the server returns it. See Datasets.
ExperimentResult
Section titled “ExperimentResult”class ExperimentResult: experiment_id: str experiment_name: str dataset_id: str dataset_version: int runs: tuple[Run, ...] scorer_errors: Mapping[str, int] error_count: int # property
def summary(self) -> str: ... def assert_min(self, name: str, threshold: float) -> None: ...What evaluate returns: one Run per item and repetition, in item order. summary() prints the means and counts; assert_min raises AssertionError when a scorer’s mean is below the threshold, which gates CI. See Experiments.
LlmSpan
Section titled “LlmSpan”class LlmSpan(Span): def set_input_messages(self, messages: Sequence[object]) -> None: ... def set_output_messages(self, messages: Sequence[object]) -> None: ... def set_response_model(self, model: str) -> None: ... def set_usage(self, *, input_tokens: int | None = None, output_tokens: int | None = None, cache_read_tokens: int | None = None, cache_write_tokens: int | None = None, reasoning_tokens: int | None = None) -> None: ... def set_cost(self, total_usd: float) -> None: ... def record_first_token(self) -> None: ...The handle llm_span yields. It writes the GenAI attributes of a chat call. See Manual spans and llm_span.
Prompt
Section titled “Prompt”class Prompt: name: str type: Literal["text", "chat"] template: str | tuple[Mapping[str, str], ...] version: int | None # None for a fallback config: Mapping[str, Any] labels: tuple[str, ...] variables: tuple[str, ...] placeholders: tuple[str, ...] is_fallback: bool
def compile(self, **values: object) -> str | list[dict[str, str]]: ...A prompt version from the registry, or the fallback that get_prompt built from a string or message list. compile fills the variables and placeholders and links the current span to the prompt. See Prompts.
PromptCompileError
Section titled “PromptCompileError”class PromptCompileError(ValueError): kind: str # invalid, missing_variable or missing_placeholder name: str | None reason: str | None line: int | None column: int | None prompt: str | NoneRaised by compile when a variable or placeholder has no value, or when a template is invalid, including an invalid fallback. The message names the prompt and never quotes the template. See Prompts.
PromptNotAvailable
Section titled “PromptNotAvailable”class PromptNotAvailable(Exception): name: str reason: str # not found, status <code>, network, invalid response or sdk disabledRaised by get_prompt when no prompt can be fetched, no stale copy is cached and no fallback was given. See Prompts.
QueueCounts
Section titled “QueueCounts”class QueueCounts: pending: int completed: int skipped: intThe item counts of an annotation queue, by status. See Annotation queues.
QueueItemStatus
Section titled “QueueItemStatus”QueueItemStatus = Literal["pending", "completed", "skipped"]The status of a queue item, the filter of client.annotation_queues.items. See Annotation queues.
QueueTarget
Section titled “QueueTarget”QueueTarget = Literal["trace", "span", "session"]What the items of a queue are. It is fixed when the queue is created. See Annotation queues.
class Run: dataset_item_id: str repetition: int input: Any expected_output: Any output: Any error: str | None trace_id: str | None latency_ns: int scores: Mapping[str, Score]The outcome of the task on one item and one repetition, with the scores it received. See Experiments.
class Score: def __init__(self, *, value: bool | int | float | str, reason: str | None = None, data_type: Literal["numeric", "boolean", "categorical", "text"] | None = None, metadata: Mapping[str, object] | None = None) -> None: ...What a scorer returns when it has a reason or metadata to add to the value. See Experiments.
SkippedQueueItem
Section titled “SkippedQueueItem”class SkippedQueueItem: index: int message: strA target that add_items did not add. index is its position in the list the call received, and message says why without repeating the value. See Annotation queues.
class Span: trace_id: str | None # property span_id: str | None # property
def set_input(self, value: object) -> None: ... def set_output(self, value: object) -> None: ... def set_metadata(self, **values: object) -> None: ...The handle span yields. Every method is a no-op after the span ended and never raises. See Manual spans and llm_span.
__version__
Section titled “__version__”__version__: strThe installed version of the SDK. See Install.
aevaluate
Section titled “aevaluate”async def aevaluate(*, dataset: str | Dataset, task: Callable[..., Any], scorers: Sequence[Callable[..., Any]] = (), experiment_name: str | None = None, description: str | None = None, metadata: Mapping[str, object] | None = None, dataset_version: int | None = None, concurrency: int = 8, repetitions: int = 1, client: Client | None = None) -> ExperimentResult: ...The async form of evaluate, for async tasks. See Experiments.
context
Section titled “context”def context(*, session_id: str | None = None, user_id: str | None = None, tags: Sequence[str] | None = None, metadata: Mapping[str, object] | None = None, propagate: bool = False, prompt: Prompt | None = None) -> ContextManager: ...A sync and async context manager that stamps the session, user, tags and metadata on every span started inside it. propagate=True also writes the ids to W3C baggage. prompt stamps the prompt’s name and version on those spans, as compile does for the current span. See Context and baggage.
current_span_id
Section titled “current_span_id”def current_span_id() -> str | None: ...The id of the running span as 16 lowercase hex characters, or None outside a span. See Scores.
current_trace_id
Section titled “current_trace_id”def current_trace_id() -> str | None: ...The id of the running trace as 32 lowercase hex characters, or None outside a span. See Scores.
evaluate
Section titled “evaluate”def evaluate(*, dataset: str | Dataset, task: Callable[..., Any], scorers: Sequence[Callable[..., Any]] = (), experiment_name: str | None = None, description: str | None = None, metadata: Mapping[str, object] | None = None, dataset_version: int | None = None, concurrency: int = 8, repetitions: int = 1, client: Client | None = None) -> 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.
def flush() -> None: ...Blocks until the pending spans and scores are exported. Call it at the end of every serverless invocation. See Serverless.
get_prompt
Section titled “get_prompt”def get_prompt(name: str, *, label: str | None = None, version: int | None = None, fallback: str | Sequence[Mapping[str, str]] | None = None, cache_ttl_s: float = 60.0) -> Prompt: ...Fetches a prompt by label (default production) or version. Labels are cached for 60 seconds and then served stale while one refresh runs; a version never expires. See Prompts.
def init(*, api_key: str | None = None, base_url: str | None = None, environment: str | None = None, release: str | None = None, capture_content: bool | None = None, sample_rate: float | None = None, instrument: Sequence[str] | None = None, mask: Callable[[Any], Any] | None = None, use_global_provider: bool | None = None, export_filter: Callable[[ReadableSpan], bool] | None = None, enabled: bool | None = None) -> None: ...Starts the SDK. It is called once per process; later calls are ignored. See Configuration.
llm_span
Section titled “llm_span”def llm_span(name: str, *, provider: str, model: str, input_messages: Sequence[object] | None = None, system_instructions: str | Sequence[object] | None = None, params: Mapping[str, object] | None = None, metadata: Mapping[str, object] | None = None) -> ContextManager[LlmSpan]: ...A sync and async context manager that writes the GenAI attributes of a chat call, for providers without an instrumentor. See Manual spans and llm_span.
observe
Section titled “observe”def observe(func=None, /, *, name: str | None = None, kind: str = "chain", capture_input: bool = True, capture_output: bool = True, reduce_output: Callable[[list[object]], object] | None = None): ...Traces a function, coroutine function, generator function or async generator function as one span. It works with and without arguments. See Decorator rules.
def score(*, name: str, value: bool | int | float | str, trace_id: str | None = None, span_id: str | None = None, session_id: str | None = None, reason: str | None = None, data_type: Literal["numeric", "boolean", "categorical", "text"] | None = None, metadata: Mapping[str, object] | None = None, user_id: str | None = None, score_id: str | None = None) -> str | None: ...Attaches a score to a trace, a span or a session. It returns the score id, or None when nothing was queued. See Scores.
shutdown
Section titled “shutdown”def shutdown() -> None: ...Flushes, then stops the SDK and uninstruments what it enabled. init() registers it with atexit. See Initialize.
def span(name: str, *, kind: str = "chain", input: object = ..., metadata: Mapping[str, object] | None = None) -> ContextManager[Span]: ...A sync and async context manager that runs its body inside one span. The handle’s setters record the input, the output and the metadata. See Manual spans and llm_span.
span_processor
Section titled “span_processor”def span_processor() -> SpanProcessor | None: ...Returns the span processor of the SDK, for apps that build their own OpenTelemetry pipeline. See Existing OpenTelemetry setups.
tracer_provider
Section titled “tracer_provider”def tracer_provider() -> TracerProvider: ...Returns the tracer provider in use: a no-op provider before init(), when disabled or after shutdown(). See Existing OpenTelemetry setups.
def uuid7() -> str: ...Returns a new UUIDv7, the kind of id score() mints. Use it when you need your own idempotent score ids. See Scores.