> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hipocap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scoring with SDK

## Create Evaluator Score

Create a score for a span using either a trace ID or span ID. When using a trace ID, the score will be attached to the root span of that trace.

### Code Examples

<CodeGroup>
  ```javascript TypeScript theme={null}
  import { LaminarClient, Laminar, observe } from "@lmnr-ai/lmnr";

  const laminarClient = new LaminarClient({
    projectApiKey: "your-project-api-key",
  });

  let traceId: string | null = null;
  let spanId: string | null = null;

  // First, capture your LLM calls
  await observe(
    {
      name: "chat_completion",
      input: { messages: [...] },
    },
    async () => {
      // Your LLM call here
      const output = { content: "AI response" };

      // Capture IDs while we're inside span context
      traceId = Laminar.getTraceId();
      spanId = Laminar.getLaminarSpanContext()?.spanId ?? null;

      return output;
    }
  );

  // IMPORTANT: Flush data to ensure it reaches the backend
  await Laminar.flush();

  if (!traceId || !spanId) {
    throw new Error("No recorded trace/span found");
  }

  // Score by trace ID (attaches to root span)
  await laminarClient.evaluators.score({
    name: "quality",
    traceId,
    score: 0.95,
    metadata: { model: "gpt-4" }
  });

  // Score by span ID (attaches to that span)
  await laminarClient.evaluators.score({
    name: "relevance", 
    spanId,
    score: 0.87
  });
  ```

  ```python Python theme={null}
  from lmnr import LaminarClient, Laminar
  import time

  laminar_client = LaminarClient(project_api_key="your-project-api-key")

  trace_id = None
  span_id = None

  # First, capture your LLM calls
  with Laminar.start_as_current_span(
      name = "chat_completion",
      input = {"messages": [
        # ...
      ]},
  ) as span:

      # Your LLM call here
      Laminar.set_span_output({"content": "AI response"})

      # Capture IDs while we're inside span context
      trace_id = Laminar.get_trace_id()
      span_context = Laminar.get_laminar_span_context()
      span_id = span_context.span_id if span_context else None

  # IMPORTANT: Flush data to ensure it reaches the backend
  Laminar.flush()

  if not trace_id or not span_id:
      raise ValueError("No recorded trace/span found")

  # Score by trace ID (attaches to root span)
  laminar_client.evaluators.score(
      name="quality",
      trace_id=trace_id, 
      score=0.95,
      metadata={"model": "gpt-4"}
  )

  # Score by span ID
  # In production, ensure this runs after the span is recorded/ingested.
  time.sleep(1)

  laminar_client.evaluators.score(
      name="relevance",
      span_id=span_id,
      score=0.87
  )
  ```
</CodeGroup>

## Viewing Scores in UI

When you create evaluator scores, they will appear in your Laminar dashboard attached to the corresponding spans:

<Frame>
  <img src="https://mintcdn.com/hipocap/jGau1UNMEqA4k6Af/images/evaluations/online-evaluators/score.png?fit=max&auto=format&n=jGau1UNMEqA4k6Af&q=85&s=4501f9f63efb0d98ed3788a57d9d9ae1" alt="Evaluator scores displayed in span details" width="3012" height="1522" data-path="images/evaluations/online-evaluators/score.png" />
</Frame>
