# AUTO-GENERATED tier-A mirror spec — do not edit.
# Source: openapi/runtime/traces.yaml (runtime 0.124.0)
#  + policy: openapi/mirror-policies/traces.json
# Regenerate: node scripts/generate-mirror-specs.mjs
openapi: 3.0.3
info:
  title: naturali.ai — Traces API
  version: 1.0.0
  description: >-
    Traces: the execution record of a run — its tree of child traces, the generations underneath
    them, and the content-purge control that erases a tenant's data while leaving the audit skeleton
    behind. A fully runtime-backed module — this spec is generated verbatim from the runtime's own,
    re-rooted under /v1/projects/{project_id}. The project in the path is authorized by naturali and
    enforced upstream by the project's scoped credential.


    This module mirrors the upstream runtime verbatim (tier A): paths are the runtime's own
    re-rooted under /v1/projects/{project_id}, and every field, method, status code and error shape
    passes through unchanged. Errors raised by the runtime arrive in its envelope; errors raised by
    naturali itself (authentication, project resolution, an unreachable runtime) use naturali's.
  contact:
    name: naturali.ai
    url: https://naturali.ai
servers:
  - url: "{baseUrl}"
    description: Host of your naturali.ai deployment; every path carries the /v1 prefix.
    variables:
      baseUrl:
        description: Base host URL.
        default: https://api.naturali.ai
tags:
  - name: Traces
    description: Inspect execution traces and trace trees
security:
  - bearerAuth: []
  - oauth2:
      - mcp:access
paths:
  /v1/projects/{project_id}/traces:
    get:
      tags:
        - Traces
      summary: List traces
      description: Returns a paginated list of execution traces for the project.
      operationId: listTraces
      parameters:
        - name: parent_trace_id
          in: query
          required: false
          schema:
            type: string
            example: trace_V1StGXR8Z5jdHi6B
          description: Only the direct children of this trace. A trace naming nothing the caller can read
            matches nothing rather than widening the listing.
        - $ref: "#/components/parameters/Limit"
        - $ref: "#/components/parameters/Cursor"
      responses:
        "200":
          description: List of traces
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Page"
                  - properties:
                      data:
                        type: array
                        items:
                          $ref: "#/components/schemas/Trace"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          $ref: "#/components/responses/ProjectNotFound"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/traces/{trace_id}:
    get:
      tags:
        - Traces
      summary: Get a trace
      description: Returns a single trace by ID.
      operationId: getTrace
      parameters:
        - name: trace_id
          in: path
          required: true
          schema:
            type: string
          description: Public ID of the trace
      responses:
        "200":
          description: Trace details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Trace"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trace not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/traces/{trace_id}/tree:
    get:
      tags:
        - Traces
      summary: Get trace tree
      description: >
        Returns the full execution tree rooted at the given trace (or its root if the given trace is
        a child). Each node represents one agent's execution session. The `children` array contains
        traces triggered by sub-agent tool calls from that trace. A node's generations are listed by
        `GET /v1/projects/{project_id}/generations?trace_id=`, and a node's direct children page by
        `GET /v1/projects/{project_id}/traces?parent_trace_id=`.
      operationId: getTraceTree
      parameters:
        - name: trace_id
          in: path
          required: true
          schema:
            type: string
          description: Public ID of any trace in the tree (root or child)
      responses:
        "200":
          description: Trace tree rooted at the resolved root trace
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TraceTreeNode"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trace not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
  /v1/projects/{project_id}/traces/{trace_id}/content:
    delete:
      tags:
        - Traces
      summary: Purge trace content
      description: >
        Deletes the trace's steps object from storage and clears its content columns (`file_id`,
        `error`), cascading to every descendant trace and to all of their generations. A descendant
        holds its own steps object covering the same run, so the cascade is what makes the erasure
        complete rather than merely partial.


        The rows survive as auditable skeletons with `content_redacted_at` set — ids, timestamps,
        step counts, and the generations' usage-attribution fields are preserved, because the
        billing and audit ledger must outlive a tenant's erasure of the content. A purged trace
        therefore reads back as a skeleton, not a 404: a 404 would prove nothing.


        Idempotent — purging an already-purged trace succeeds and leaves the original
        `content_redacted_at` in place.
      operationId: purgeTraceContent
      parameters:
        - name: trace_id
          in: path
          required: true
          schema:
            type: string
          description: Public ID of the trace
      responses:
        "200":
          description: The purged trace skeleton
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Trace"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Trace not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/AdmissionUnavailable"
        4XX:
          $ref: "#/components/responses/AdmissionRefused"
    parameters:
      - $ref: "#/components/parameters/ProjectId"
components:
  schemas:
    Trace:
      type: object
      properties:
        id:
          type: string
          description: Public ID of the trace
          example: trace_V1StGXR8Z5jdHi6B
        project_id:
          x-naturali-ref: projects
          type: string
          description: Public ID of the project
        agent_id:
          x-naturali-ref: agents
          type: string
          description: Public ID of the agent that produced this trace
        file_id:
          x-naturali-ref: files
          type: string
          nullable: true
          description: >
            Public ID of the File containing the full serialized steps JSON. Null if the trace has
            not been saved yet (save is fire-and-forget).
          example: file_xyz789
        step_count:
          type: integer
          description: Number of steps recorded in this trace
          example: 2
        parent_trace_id:
          x-naturali-ref: traces
          type: string
          nullable: true
          description: >
            Public ID of the parent trace. Null if this trace is the root (i.e., it was not
            triggered by a sub-agent call from another trace).
        root_trace_id:
          x-naturali-ref: traces
          type: string
          nullable: true
          description: >
            Public ID of the root trace for the entire execution tree. Null if this trace is itself
            the root.
        error:
          allOf:
            - $ref: "#/components/schemas/StoredError"
          nullable: true
          description: Why a generation in this trace failed (e.g. an upstream AI provider error). Null if no
            failure has been recorded.
        content_redacted_at:
          type: string
          format: date-time
          nullable: true
          description: >
            When the trace's content was purged. Non-null means the steps object has been deleted
            from storage and the content columns cleared, while this row survives as an auditable
            skeleton (ids, timestamps, step count). A purged trace still reads back as a skeleton
            with this marker set rather than as a 404, so the erasure is provable.
        content_redacted_by_principal_type:
          nullable: true
          allOf:
            - $ref: "#/components/schemas/PrincipalType"
          description: "Who purged the content: `user` or `api_key` for a purge request, `system` for the
            retention sweep and for content never stored under zero retention."
        content_redacted_by_principal_id:
          type: string
          nullable: true
          description: Public id of that principal — the API key's own id for key auth, so the record names
            which key acted. `retention_sweep` or `zero_retention` for `system`.
          example: user_V1StGXR8Z5jdHi6B
        created_at:
          type: string
          format: date-time
    TraceTreeNode:
      type: object
      description: A trace node in the execution tree, with nested children.
      properties:
        id:
          type: string
          description: Public ID of the trace
        project_id:
          x-naturali-ref: projects
          type: string
        agent_id:
          x-naturali-ref: agents
          type: string
        file_id:
          x-naturali-ref: files
          type: string
          nullable: true
        step_count:
          type: integer
        parent_trace_id:
          x-naturali-ref: traces
          type: string
          nullable: true
        root_trace_id:
          x-naturali-ref: traces
          type: string
          nullable: true
        error:
          allOf:
            - $ref: "#/components/schemas/StoredError"
          nullable: true
          description: Why a generation in this trace failed
        created_at:
          type: string
          format: date-time
        content_redacted_at:
          type: string
          format: date-time
          nullable: true
          description: >
            When the trace's content was purged. Non-null means the steps object has been deleted
            from storage and the content columns cleared, while this row survives as an auditable
            skeleton (ids, timestamps, step count). A purged trace still reads back as a skeleton
            with this marker set rather than as a 404, so the erasure is provable.
        content_redacted_by_principal_type:
          nullable: true
          allOf:
            - $ref: "#/components/schemas/PrincipalType"
          description: "Who purged the content: `user` or `api_key` for a purge request, `system` for the
            retention sweep and for content never stored under zero retention."
        content_redacted_by_principal_id:
          type: string
          nullable: true
          description: Public id of that principal — the API key's own id for key auth, so the record names
            which key acted. `retention_sweep` or `zero_retention` for `system`.
          example: user_V1StGXR8Z5jdHi6B
        children:
          type: array
          description: Child traces triggered by sub-agent calls from this trace
          items:
            $ref: "#/components/schemas/TraceTreeNode"
    Page:
      type: object
      description: One page of a list. Rows inserted or removed between two calls neither repeat nor skip
        a row on the next page.
      required:
        - data
        - next_cursor
      properties:
        data:
          type: array
          description: This page's items, in the list's order.
          items: {}
        next_cursor:
          type: string
          nullable: true
          description: Pass as `cursor` to fetch the next page; `null` on the last page.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          description: Structured error. Every error response uses this shape, so `code` can be read without
            first checking the type of `error`.
          required:
            - code
            - message
            - hint
          properties:
            code:
              type: string
              pattern: ^[A-Z][A-Z0-9_]*$
              description: Machine-readable error code, UPPER_SNAKE whether naturali or the runtime raises it.
              example: FORBIDDEN
            message:
              type: string
              description: Human-readable explanation.
              example: Your role in this project does not carry this action.
            hint:
              type: string
              description: What to do about it, naming the routes of this API to call. For people and agents; it
                may change, so branch on `code`.
              example: Use a credential whose scope includes this action, or ask a project `admin` or `owner` to
                act; the caller's role or key excludes it.
            meta:
              type: object
              additionalProperties: true
              description: Structured context, such as the `resource` and `limit` of a `PLAN_LIMIT_REACHED`.
    StoredError:
      type: object
      description: Why a resource's work failed, in the shape of an error response's `error` without
        `hint`. Every `error` field a resource records carries it, so `code` can be read without
        first checking the type of `error`.
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: A key from the server's ERROR_CODES registry, documented on the Error Codes page.
            `INTERNAL_ERROR`, with the message `Internal Server Error`, records an unexpected
            failure whose detail reaches the server log only.
          example: AI_PROVIDER_ERROR
        message:
          type: string
          example: "Provider returned 402: insufficient credits"
        meta:
          type: object
          additionalProperties: true
          description: The failure's own structured context, when it names any.
    PrincipalType:
      type: string
      enum:
        - user
        - api_key
        - agent
        - automation
        - approval
        - trigger
        - system
        - eval
        - decider
        - ingestion_rule
        - memory_rule
        - playbook_version
      description: What kind of principal acted. `user` and `api_key` are authenticated callers, and the
        id is the user's (`user_…`) or the key's own (`key_…`), so a record names which key acted
        rather than its owner. `agent` is an agent writing under its own identity (`agent_…`).
        `automation` is the task engine acting on a dispatch outcome and `approval` an approval
        resolution; neither carries an id. `trigger` is a trigger firing under its own `policy_ids`
        (`trg_…`). `system` is the platform itself, with an id naming the mechanism
        (`retention_sweep`, `zero_retention`). `eval`, `decider`, `ingestion_rule`, `memory_rule`
        and `playbook_version` are that resource's work running under its own `policy_ids` when
        nobody started it, the id its own.
      example: user
  parameters:
    ProjectId:
      name: project_id
      in: path
      required: true
      description: Project public ID (proj_ prefix).
      schema:
        type: string
        example: proj_V1StGXR8Z5jdHi6B
    Limit:
      name: limit
      in: query
      required: false
      description: Results per page, 1 to 100 (default 50). Above 100 it is clamped; below 1 or not an
        integer it is `400`.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
    Cursor:
      name: cursor
      in: query
      required: false
      description: The previous page's `next_cursor`; omit it for the first page. A cursor this list did
        not issue is `400`.
      schema:
        type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A naturali API key (nat_sk_…) or a session JWT.
    oauth2:
      type: oauth2
      description: "A connected app's OAuth access token, issued by this API's authorization server
        (discovery: /.well-known/oauth-authorization-server). Its one scope carries every operation,
        confined to the projects the user chose when approving the app."
      flows:
        authorizationCode:
          authorizationUrl: https://api.naturali.ai/authorize
          tokenUrl: https://api.naturali.ai/token
          refreshUrl: https://api.naturali.ai/token
          scopes:
            mcp:access: Every operation this API serves, on the projects the grant covers.
  responses:
    BadRequest:
      description: The request was malformed or failed validation.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    TooManyRequests:
      description: "`QUOTA_EXCEEDED` — a `requests` quota on the calling API key or its project is spent
        for the window; `Retry-After` says when it reopens"
      headers:
        Retry-After:
          description: Seconds until the quota window admits a request again
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    InternalError:
      description: Unexpected server error — `INTERNAL_ERROR`, with the raw message never forwarded
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    AdmissionUnavailable:
      description: The deployment's admission service is asked about this write and did not answer —
        `ADMISSION_UNAVAILABLE`; the write did not happen
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    AdmissionRefused:
      description: The deployment's admission service refused this write — answered under the service's
        own `4xx` status, with its `code` (matching `^[A-Za-z_][A-Za-z0-9_]{0,63}$`, not necessarily
        an `ERROR_CODES` key), `message` and `meta`; the write did not happen. A status this
        operation also declares on its own is documented there
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    ProjectNotFound:
      description: The project does not exist or the caller is not a member of it (`RESOURCE_NOT_FOUND`).
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
