> ## 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.

# Get the per-trace remediation diff for a control action

> Returns a comparison of the original LLM span against the
remediated span produced by a `retry` control action — token
length delta, latency delta, Claude-rated similarity, and
per-rule eval score deltas. Lazy-computed on first GET and
cached for subsequent requests. TRU-363.

Status codes:
  * 200 — diff available (cached or just computed)
  * 202 — `evaluation_incomplete`: caller should poll
  * 404 — action not found / cross-tenant
  * 422 — `no_remediated_span`: action type cannot produce a diff
          (currently `fallback_model` and `prompt_modification`)




## OpenAPI

````yaml /api-reference/openapi.yaml get /v1/control/actions/{id}/diff
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/control/actions/{id}/diff:
    get:
      tags:
        - control
      summary: Get the per-trace remediation diff for a control action
      description: |
        Returns a comparison of the original LLM span against the
        remediated span produced by a `retry` control action — token
        length delta, latency delta, Claude-rated similarity, and
        per-rule eval score deltas. Lazy-computed on first GET and
        cached for subsequent requests. TRU-363.

        Status codes:
          * 200 — diff available (cached or just computed)
          * 202 — `evaluation_incomplete`: caller should poll
          * 404 — action not found / cross-tenant
          * 422 — `no_remediated_span`: action type cannot produce a diff
                  (currently `fallback_model` and `prompt_modification`)
      operationId: getRemediationDiff
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Remediation diff
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RemediationDiff'
        '202':
          description: Evaluation still running — caller should poll
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - pending
                  reason:
                    type: string
                    enum:
                      - evaluation_incomplete
                required:
                  - status
                  - reason
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          description: Action type cannot produce a remediation diff
          content:
            application/json:
              schema:
                type: object
                properties:
                  reason:
                    type: string
                    enum:
                      - no_remediated_span
                required:
                  - reason
components:
  schemas:
    RemediationDiff:
      type: object
      description: |
        Per-trace remediation diff for a `retry` control action. Lazy-
        computed on first GET and cached. `embedding_similarity` is a
        0..1 score from a Claude similarity rating, with the sentinel
        `-1.0` when the rater call failed. TRU-363.
      required:
        - action_id
        - original_span_id
        - remediated_span_id
        - token_length_delta
        - latency_delta_ms
        - embedding_similarity
        - score_deltas
        - summary
      properties:
        action_id:
          type: string
          format: uuid
        original_span_id:
          type: string
          format: uuid
        remediated_span_id:
          type: string
          format: uuid
        token_length_delta:
          type: integer
          description: remediated_tokens - original_tokens (sum of prompt + completion).
        latency_delta_ms:
          type: integer
          format: int64
          description: remediated_latency_ms - original_latency_ms.
        embedding_similarity:
          type: number
          format: double
          description: 0..1 similarity, or -1.0 when the rater call failed.
        score_deltas:
          type: array
          items:
            $ref: '#/components/schemas/ScoreDelta'
        summary:
          type: string
        citation_density_delta:
          type: number
          format: double
          nullable: true
          description: |
            citations_per_1k_chars(remediated) -
            citations_per_1k_chars(original). Null for diffs
            computed before TRU-373 (column nullable, no backfill)
            and when both outputs are empty. TRU-373.
    ScoreDelta:
      type: object
      required:
        - eval_rule_id
        - rule_name
        - original_score
        - remediated_score
        - delta
      properties:
        eval_rule_id:
          type: string
          format: uuid
        rule_name:
          type: string
        original_score:
          type: number
          format: double
        remediated_score:
          type: number
          format: double
        delta:
          type: number
          format: double
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
  responses:
    Unauthorized:
      description: Missing or invalid credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: SDK API key (`tl_...`) or Clerk session JWT

````