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

# Stream the spans of a single trace as CSV or JSONL (sync export)

> Cursor-streamed synchronous export of every span belonging to the
trace identified by `trace_id`. `trace_id` is **required** — the
batch "all traces" export path was removed because it was too
expensive to support at hypertable scale. Callers needing trace-
level analytics should use `GET /v1/traces` for paginated listing
and call this endpoint per trace.

Rows are written directly to the response body — never buffered —
and capped per plan (Starter: 100, Pro/Team/Business: 5000,
Enterprise: unlimited). Hitting the cap sets
`X-TruLayer-Truncated: true`; the payload is complete up to that row.

CSV columns (in order): `trace_id, span_id, name, type, model,
created_at, duration_ms, prompt_tokens, completion_tokens, cost_usd,
trace_input, trace_output, span_input, span_output, error`.
`span_id` is the unique identifier for the span (renamed from `id`).
`trace_input` is the parent trace's input text joined onto every span
row. `span_input` is the span's own input text. `trace_output` and
`span_output` are the parent trace's and span's output payloads
respectively, so a single download carries the full input/output
context for both the trace and each span.

JSONL emits one JSON object per line with the same keys.

The Content-Disposition filename is
`spans-<trace-prefix>-YYYY-MM-DD.{csv,jsonl}`.




## OpenAPI

````yaml /api-reference/openapi.yaml get /v1/traces/export
openapi: 3.1.0
info:
  title: TruLayer API
  version: 0.1.0
  description: |
    Trace ingestion, evaluation, query, and feedback API for TruLayer AI.

    ### Authentication

    Two auth schemes coexist: SDK API keys (`Authorization: Bearer tl_...`)
    and Clerk session JWTs (dashboard). Routes marked "requires Clerk auth"
    in their summary are unreachable via API key.

    ### Roles (TRU-234)

    Dashboard requests carry one of three organization roles: `owner`,
    `member`, `viewer`. Endpoints enforce role allowlists, not rank
    comparisons. See `docs/security.md` for the full role-permission
    matrix.

    - **owner** — full control including billing, member management,
      destructive deletes on failure-rules/model-routes/webhooks/eval-rules,
      control-loop execution, and DLQ resolution.
    - **member** — read + write (ingest, feedback, evals, API keys,
      projects, failure-rules, model-routes, webhooks).
    - **viewer** — read-only dashboard access plus compliance read access
      to `/v1/audit-log` and `/v1/dlq`.
servers:
  - url: https://api.trulayer.ai
    description: Production
  - url: http://localhost:8080
    description: Local development
security:
  - BearerAuth: []
tags:
  - name: health
  - name: ingest
  - name: traces
  - name: metrics
  - name: feedback
  - name: evals
  - name: eval-rules
  - name: control
  - name: apikeys
  - name: model-routes
  - name: datasets
  - name: search
  - name: anomaly
  - name: webhooks
  - name: failure-rules
  - name: eval-runs
  - name: ci
  - name: otlp
  - name: billing
  - name: deprecations
  - name: audit
  - name: failures
  - name: projects
  - name: compliance
  - name: dsr
  - name: policies
  - name: members
paths:
  /v1/traces/export:
    get:
      tags:
        - traces
        - export
      summary: Stream the spans of a single trace as CSV or JSONL (sync export)
      description: |
        Cursor-streamed synchronous export of every span belonging to the
        trace identified by `trace_id`. `trace_id` is **required** — the
        batch "all traces" export path was removed because it was too
        expensive to support at hypertable scale. Callers needing trace-
        level analytics should use `GET /v1/traces` for paginated listing
        and call this endpoint per trace.

        Rows are written directly to the response body — never buffered —
        and capped per plan (Starter: 100, Pro/Team/Business: 5000,
        Enterprise: unlimited). Hitting the cap sets
        `X-TruLayer-Truncated: true`; the payload is complete up to that row.

        CSV columns (in order): `trace_id, span_id, name, type, model,
        created_at, duration_ms, prompt_tokens, completion_tokens, cost_usd,
        trace_input, trace_output, span_input, span_output, error`.
        `span_id` is the unique identifier for the span (renamed from `id`).
        `trace_input` is the parent trace's input text joined onto every span
        row. `span_input` is the span's own input text. `trace_output` and
        `span_output` are the parent trace's and span's output payloads
        respectively, so a single download carries the full input/output
        context for both the trace and each span.

        JSONL emits one JSON object per line with the same keys.

        The Content-Disposition filename is
        `spans-<trace-prefix>-YYYY-MM-DD.{csv,jsonl}`.
      operationId: exportTraces
      parameters:
        - name: trace_id
          in: query
          required: true
          description: >-
            Trace to export spans for. Required — the endpoint returns 400 if
            absent.
          schema:
            type: string
            format: uuid
        - name: format
          in: query
          schema:
            type: string
            enum:
              - csv
              - jsonl
            default: csv
        - name: project_id
          in: query
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Streamed CSV or JSONL payload.
          headers:
            X-TruLayer-Truncated:
              description: >-
                Present and `true` when the per-plan row cap was hit and more
                rows exist.
              schema:
                type: boolean
            Content-Disposition:
              description: >-
                Suggests a filename of
                `spans-<trace-prefix>-YYYY-MM-DD.{csv,jsonl}`.
              schema:
                type: string
          content:
            text/csv:
              schema:
                type: string
            application/x-ndjson:
              schema:
                type: string
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  schemas:
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: SDK API key (`tl_...`) or Clerk session JWT

````