---
title: "Add Trace to Draft Dataset"
method: POST
path: "/api/public/v2/dataset-versions/add-trace"
tags: ["datasets"]
---

# Add Trace to Draft Dataset

`POST /api/public/v2/dataset-versions/add-trace`

## Request body

- AddTraceToDatasetRequest
  - `dataset_group_id` integer, required — ID of the dataset group to add the trace row to.
  - `trace_id` string, required — ID of the trace to add as a dataset row.
  - `span_id` string, nullable — Optional span ID. When omitted the row anchors on the trace's earliest root span (Trace export). When provided the row anchors on that span and its direct children become the columns (Span export).

## Response `201`

Trace added to draft dataset.

- AddTraceToDatasetResponse
  - `success` true
  - `draft_dataset_id` integer — ID of the draft dataset the trace row was added to.
  - `mode` 'trace' | 'span' — Indicates whether the row was created from a full trace root (`trace`) or a specific span subtree (`span`).

## Other responses

- `400` — Invalid request (e.g. dataset not found, wrong workspace, or schema error).
- `401` — Unauthorized - missing or invalid API key.
- `403` — Forbidden - API key does not have access to the requested resource.
- `404` — Trace not found in the workspace.
- `422` — Validation error - request parameters or body are invalid.

---

[API](https://skmtc.dev/promptlayer/apis/promptlayer-api.md) · [All operations](https://skmtc.dev/promptlayer/apis/promptlayer-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/promptlayer/promptlayer-api/revisions/a23093a0a506/schema)
