Skip to main content
Complete reference for lumina-sdk.

init_lumina(config)

Initialize the Lumina client and return a Lumina instance. Also stores the instance as a module-level singleton accessible via get_lumina(). Parameters: Returns: Lumina Example:

get_lumina()

Retrieve the current module-level singleton (set by the last init_lumina() call). Returns: Lumina | None Example:

lumina.trace_llm(fn, *, name, system, prompt, metadata, tags)

Trace an LLM call with automatic attribute extraction. Handles both OpenAI and Anthropic response shapes. Works with both sync and async callables — pass either a regular function or a coroutine function. Parameters: Returns: T (sync) or Coroutine[T] (async) Automatically extracted from response:
  • Model name (gen_ai.response.model)
  • Prompt and completion tokens (gen_ai.usage.*)
  • Response text (gen_ai.completion)
  • Cost in USD (lumina.cost_usd)
Example:

lumina.trace(name, fn, *, metadata, tags)

Create a span for any block of code. Use this to create parent spans for hierarchical (multi-span) traces. Works with both sync and async callables. Parameters: Returns: T (sync) or Coroutine[T] (async) Example:

lumina.flush()

Flush all buffered spans to the collector immediately. Returns: Coroutine[None] (must be awaited)

lumina.shutdown()

Flush all buffered spans and shut down the SDK. Returns: Coroutine[None] (must be awaited)

Span API

The span object passed to trace() callbacks is a standard OpenTelemetry Span. span.set_attribute(key, value) Add an attribute to the span.
span.add_event(name, attributes?) Record a timestamped event on the span.
span.set_status(status_code, description?) Set the span status.
span.record_exception(exception) Record an exception on the span.