Skip to main content

Providing Feedback for Traces

You can create, modify, or delete feedback for trace spans. Feedback includes a rating from 1 (lowest) to 5 (highest) to evaluate the quality of a trace span.

Creating New Feedback

You can create new feedback for traces using the API. Specify the target trace span using either feedbackTargetId or a combination of traceId, spanId, and tracingProjectFQN.
  • Using Feedback Target ID
  • Using Trace ID, Span ID and Tracing Project FQN
The feedback target ID is returned in the headers of every AI Gateway response as x-tfy-feedback-target-id. Currently, the feedback target ID only represents the root span in the trace.
import requests

# Make API request
response = requests.post(
    "https://{control_plane_url}/api/svc/v1/gateway-feedback",
    headers={
        "Authorization": "Bearer YOUR_API_TOKEN",
        "Content-Type": "application/json"
    },
    json={
        "target": {
          "type": "target-id", # Type of the target
          "feedbackTargetId": "eyJzcGFuSWQiOiJhMmQ2Yjg4MmFhMTViZTU1IiwidHJhY2VJZCI6IjAxOWFiMmE5NmQ1MDcwN2ZhMzA5MGMxYjcyMDFkNWJkIn0="
        },
        "rating": 4,
        "comment": "Optional comment", # Optional
        "metadata": {"key": "value"} # Optional
    }
)

response.raise_for_status()
data = response.json()
The response contains the feedback ID, which can be used to modify or delete the feedback.
{
  "data": {
    "id": "019ab2a98fc6e80483eae496e2dd611d"
  }
}

Modifying Existing Feedback

Existing feedback can be modified using the following API request:
  • Using Feedback Target ID
  • Using Trace ID, Span ID and Tracing Project FQN
The feedback target ID is returned in the headers of every AI Gateway response as x-tfy-feedback-target-id. Currently, the feedback target ID only represents the root span in the trace.
import requests

# Make API request
response = requests.put(
    "https://{control_plane_url}/api/svc/v1/gateway-feedback/019ab2a98fc6e80483eae496e2dd611d",
    headers={
        "Authorization": "Bearer YOUR_API_TOKEN",
        "Content-Type": "application/json"
    },
    json={
        "target": {
          "type": "target-id", # Type of the target
          "feedbackTargetId": "eyJzcGFuSWQiOiJhMmQ2Yjg4MmFhMTViZTU1IiwidHJhY2VJZCI6IjAxOWFiMmE5NmQ1MDcwN2ZhMzA5MGMxYjcyMDFkNWJkIn0="
        },
        "rating": 4,
        "comment": "Optional comment", # Optional
        "metadata": {"key": "value"} # Optional
    }
)

response.raise_for_status()
data = response.json()

Deleting Existing Feedback

Existing feedback can be deleted using the following API request:
  • Using Feedback Target ID
  • Using Trace ID, Span ID and Tracing Project FQN
The feedback target ID is returned in the headers of every AI Gateway response as x-tfy-feedback-target-id. Currently, the feedback target ID only represents the root span in the trace.
import requests

# Make API request
response = requests.delete(
    "https://{control_plane_url}/api/svc/v1/gateway-feedback/019ab2a98fc6e80483eae496e2dd611d",
    headers={
        "Authorization": "Bearer YOUR_API_TOKEN",
        "Content-Type": "application/json"
    },
    json={
        "target": {
          "type": "target-id", # Type of the target
          "feedbackTargetId": "eyJzcGFuSWQiOiJhMmQ2Yjg4MmFhMTViZTU1IiwidHJhY2VJZCI6IjAxOWFiMmE5NmQ1MDcwN2ZhMzA5MGMxYjcyMDFkNWJkIn0="
        },
        "metadata": {"key": "value"} # Optional
    }
)

response.raise_for_status()
data = response.json()

Reading Feedback

Feedback for any given trace span is displayed alongside the span in the trace view.
Feedback for trace

AI Gateway - Feedback for trace span

You can also view the complete list of feedback for a trace span in the Raw Data section under the tfyGatewayFeedbacks field.