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

# Ingest a trace

> Ingest a single trace from the SDK.

## Data Model

A trace contains two types of children:

- **`spans`** — represent operations (agent steps, tool calls, chains).
  Nest via `parent_span_id` to form a tree.
- **`llm_calls`** — represent individual LLM invocations with full fidelity
  (model, tokens, messages, response). Link to a parent span via `span_id`.

## Structuring Rules

**Spans** should be used for containers and non-LLM operations:

| `span_type` | Use for | Example |
|-------------|---------|---------|
| `agent`     | Top-level agent invocation (root span) | `finance-research-agent` |
| `tool`      | Tool/function execution | `get_stock_price` |
| `chain`     | Multi-step pipeline or sub-chain | `research-pipeline` |
| `retrieval` | RAG retrieval step | `vector-search` |
| `llm`       | Wrapper span for an LLM call (optional) | `LLM: plan step 1` |

**LLM calls** should be used for every LLM invocation:

- Always set `span_id` to the parent span that triggered this call
- Include `rendered_input` (list of messages), `output`, `model_name`, `provider`
- Include `started_at`/`ended_at` for timeline visualization
- Include token counts (`input_tokens`, `output_tokens`) for cost tracking

## Tree Rendering

The frontend builds a unified tree from both tables:

1. If an `llm_call` has `span_id` matching a span → it enriches that span
   (shown as one node with LLM details in a tab)
2. If an `llm_call` has no matching span → shown as a standalone 🧠 node
   under the root span
3. All children are sorted by `started_at` for chronological order

## Example Structure

```
agent-step (span, type=agent)
  ├── llm_call_1 (llm_call, span_id=agent-step)
  ├── tool-span  (span, type=tool, parent_span_id=agent-step)
  └── llm_call_2 (llm_call, span_id=agent-step)
```

Returns 409 if a trace with the same ID already exists.



## OpenAPI

````yaml /openapi.json post /api/v1/traces
openapi: 3.1.0
info:
  title: DecimalAI Platform
  description: Agent Dataset Lifecycle Platform — Backend API
  version: 0.1.0
servers: []
security:
  - BearerAuth: []
tags:
  - name: traces
    description: >-
      Ingest, search, and inspect agent execution traces. A trace is the atomic
      unit of the platform — every other feature (evaluation, compatibility
      scoring, dataset building) operates on traces. Each trace is auto-tagged
      with the manifest hash of the agent that produced it.
  - name: eval-scores
    description: >-
      Push, fetch, and aggregate per-trace evaluation scores. Scores carry
      source provenance (built-in, DeepEval, LangSmith, custom) and feed the
      unified decision engine, which produces a keep / repair / replay / drop
      verdict per trace.
  - name: skills
    description: >-
      Manage reusable instruction blocks (SKILL.md files) that modify agent
      behavior. Skills are first-class manifest components — changes to a skill
      appear in your regression-check impact reports. Use these endpoints to
      create, version, fork, and sync skills with your local SKILL.md files.
  - name: manifests
    description: >-
      Register and inspect manifest versions. A manifest is a snapshot of your
      agent's structural identity (tools, prompts, models, skills) at a point in
      time. The SDK registers manifests automatically; these endpoints expose
      the underlying records.
  - name: datasets
    description: >-
      Build versioned SFT/DPO training datasets from manifest-classified,
      eval-scored traces. Datasets are reproducible — each version locks the
      manifest and filter set used to build it. Export as JSONL, Parquet, or
      push to HuggingFace Hub.
  - name: replay
    description: >-
      Re-execute historical traces against a new manifest version. Replay is the
      deferred-future capability for behavioral verification of agent changes.
      The SDK creates a replay batch, your worker executes each task, then
      submits results back here for eval scoring.
  - name: registry
    description: >-
      Browse and install community skills from the public skills registry. Each
      registry skill carries a SkillScore — an evidence-tiered quality composite
      computed from real-world evals, benchmarks, and ratings across
      organizations. Installing creates a fork in your org — edits don't affect
      the public version.
  - name: agents
    description: >-
      List and inspect agents, plus their multi-agent topology (orchestrator →
      sub-agent edges discovered from traces). Agents are identified by a stable
      agent_name string set in your SDK init() call.
  - name: import
    description: >-
      Bulk-import historical traces from another observability platform or a
      JSONL backup. Useful for migrating from LangSmith / Braintrust / Langfuse.
      Duplicate trace IDs are silently skipped — re-running an import is safe.
paths:
  /api/v1/traces:
    post:
      tags:
        - traces
      summary: Ingest a trace
      description: >-
        Ingest a single trace from the SDK.


        ## Data Model


        A trace contains two types of children:


        - **`spans`** — represent operations (agent steps, tool calls, chains).
          Nest via `parent_span_id` to form a tree.
        - **`llm_calls`** — represent individual LLM invocations with full
        fidelity
          (model, tokens, messages, response). Link to a parent span via `span_id`.

        ## Structuring Rules


        **Spans** should be used for containers and non-LLM operations:


        | `span_type` | Use for | Example |

        |-------------|---------|---------|

        | `agent`     | Top-level agent invocation (root span) |
        `finance-research-agent` |

        | `tool`      | Tool/function execution | `get_stock_price` |

        | `chain`     | Multi-step pipeline or sub-chain | `research-pipeline` |

        | `retrieval` | RAG retrieval step | `vector-search` |

        | `llm`       | Wrapper span for an LLM call (optional) | `LLM: plan
        step 1` |


        **LLM calls** should be used for every LLM invocation:


        - Always set `span_id` to the parent span that triggered this call

        - Include `rendered_input` (list of messages), `output`, `model_name`,
        `provider`

        - Include `started_at`/`ended_at` for timeline visualization

        - Include token counts (`input_tokens`, `output_tokens`) for cost
        tracking


        ## Tree Rendering


        The frontend builds a unified tree from both tables:


        1. If an `llm_call` has `span_id` matching a span → it enriches that
        span
           (shown as one node with LLM details in a tab)
        2. If an `llm_call` has no matching span → shown as a standalone 🧠 node
           under the root span
        3. All children are sorted by `started_at` for chronological order


        ## Example Structure


        ```

        agent-step (span, type=agent)
          ├── llm_call_1 (llm_call, span_id=agent-step)
          ├── tool-span  (span, type=tool, parent_span_id=agent-step)
          └── llm_call_2 (llm_call, span_id=agent-step)
        ```


        Returns 409 if a trace with the same ID already exists.
      operationId: ingest_trace_api_v1_traces_post
      parameters:
        - name: Authorization
          in: header
          required: false
          schema:
            type: string
            title: Authorization
        - name: decimal_session
          in: cookie
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Decimal Session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
              title: Payload
      responses:
        '200':
          description: Ingestion result with counts
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                title: Response Ingest Trace Api V1 Traces Post
              example:
                status: ok
                id: trc_abc123
                trace_id: trc_abc123
                agent_name: my-agent
                spans: 5
                llm_calls: 3
        '400':
          description: Trace validation failed.
        '402':
          description: Plan trace-ingest quota exhausted.
        '409':
          description: A trace with this ID already exists.
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: Python
          label: Python SDK
          source: |-
            import decimalai

            # Auto-instrumentation (recommended)
            decimalai.init(api_key="dai_sk_...", openai_agents=True)

            # Or manual tracing with decorator
            @decimalai.trace(agent_name="my-agent")
            def run_agent(query: str) -> str:
                return llm.invoke(query)

            run_agent("What is the weather?")
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Enter your API key (e.g. dai_sk_test_key_001)

````