Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(api): GET /scores support for filtering by traceId, datasetRunId (#10478)

marliessophiee1f390d66688
diff --git a/fern/apis/server/definition/score-v2.yml b/fern/apis/server/definition/score-v2.yml
index d40e86907e..06f896b99f 100644
--- a/fern/apis/server/definition/score-v2.yml
+++ b/fern/apis/server/definition/score-v2.yml
@@ -53,6 +53,12 @@ service:
sessionId:
type: optional<string>
docs: Retrieve only scores with a specific sessionId.
+ datasetRunId:
+ type: optional<string>
+ docs: Retrieve only scores with a specific datasetRunId.
+ traceId:
+ type: optional<string>
+ docs: Retrieve only scores with a specific traceId.
queueId:
type: optional<string>
docs: Retrieve only scores with a specific annotation queueId.
diff --git a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts
index c740cf0e42..96c9c2fe5c 100644
--- a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts
+++ b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts
@@ -10,6 +10,8 @@ export const GetScoreResponseV2 = APIScoreSchemaV2;
// GET /scores v2
export const GetScoresQueryV2 = GetScoresQuery.extend({
sessionId: z.string().nullish(),
+ traceId: z.string().nullish(),
+ datasetRunId: z.string().nullish(),
});
export const GetScoreResponseDataV2 = z.intersection(
APIScoreSchemaV2,
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index 3d8597cb01..f8ab14f6f1 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -4412,6 +4412,20 @@ paths:
schema:
type: string
nullable: true
+ - name: datasetRunId
+ in: query
+ description: Retrieve only scores with a specific datasetRunId.
+ required: false
+ schema:
+ type: string
+ nullable: true
+ - name: traceId
+ in: query
+ description: Retrieve only scores with a specific traceId.
+ required: false
+ schema:
+ type: string
+ nullable: true
- name: queueId
in: query
description: Retrieve only scores with a specific annotation queueId.
@@ -7763,6 +7777,8 @@ components:
- image/svg+xml
- image/tiff
- image/bmp
+ - image/avif
+ - image/heic
- audio/mpeg
- audio/mp3
- audio/wav
@@ -7771,19 +7787,42 @@ components:
- audio/aac
- audio/mp4
- audio/flac
+ - audio/opus
+ - audio/webm
- video/mp4
- video/webm
+ - video/ogg
+ - video/mpeg
+ - video/quicktime
+ - video/x-msvideo
+ - video/x-matroska
- text/plain
- text/html
- text/css
- text/csv
+ - text/markdown
+ - text/x-python
+ - application/javascript
+ - text/x-typescript
+ - application/x-yaml
- application/pdf
- application/msword
- application/vnd.ms-excel
+ - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- application/zip
- application/json
- application/xml
- application/octet-stream
+ - >-
+ application/vnd.openxmlformats-officedocument.wordprocessingml.document
+ - >-
+ application/vnd.openxmlformats-officedocument.presentationml.presentation
+ - application/rtf
+ - application/x-ndjson
+ - application/vnd.apache.parquet
+ - application/gzip
+ - application/x-tar
+ - application/x-7z-compressed
description: The MIME type of the media record
MetricsResponse:
title: MetricsResponse
diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.json
index 4c2c5986ca..37b4824bf3 100644
--- a/web/public/generated/postman/collection.json
+++ b/web/public/generated/postman/collection.json
@@ -3039,7 +3039,7 @@
"request": {
"description": "Get a list of scores (supports both trace and session scores)",
"url": {
- "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&sessionId=&queueId=&dataType=&traceTags=",
+ "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&sessionId=&datasetRunId=&traceId=&queueId=&dataType=&traceTags=",
"host": [
"{{baseUrl}}"
],
@@ -3115,6 +3115,16 @@
"value": "",
"description": "Retrieve only scores with a specific sessionId."
},
+ {
+ "key": "datasetRunId",
+ "value": "",
+ "description": "Retrieve only scores with a specific datasetRunId."
+ },
+ {
+ "key": "traceId",
+ "value": "",
+ "description": "Retrieve only scores with a specific traceId."
+ },
{
"key": "queueId",
"value": "",
diff --git a/web/src/__tests__/async/scores-api-v1.servertest.ts b/web/src/__tests__/async/scores-api-v1.servertest.ts
index 2fd486e517..639406345e 100644
--- a/web/src/__tests__/async/scores-api-v1.servertest.ts
+++ b/web/src/__tests__/async/scores-api-v1.servertest.ts
@@ -414,6 +414,7 @@ describe("/api/public/scores API Endpoint", () => {
const traceId_3 = v4();
const generationId = v4();
const sessionId = v4();
+ const datasetRunId = v4();
const scoreId_1 = v4();
const scoreId_2 = v4();
const scoreId_3 = v4();
@@ -1052,6 +1053,36 @@ describe("/api/public/scores API Endpoint", () => {
);
}
});
+
+ it("should reject dataset run ID filtering", async () => {
+ try {
+ await makeAPICall(
+ "GET",
+ `/api/public/scores?datasetRunId=${datasetRunId}`,
+ undefined,
+ authentication,
+ );
+ } catch (error) {
+ expect((error as Error).message).toContain(
+ "API call did not return 200, returned status 400",
+ );
+ }
+ });
+
+ it("should reject trace ID filtering", async () => {
+ try {
+ await makeAPICall(
+ "GET",
+ `/api/public/scores?traceId=${traceId}`,
+ undefined,
+ authentication,
+ );
+ } catch (error) {
+ expect((error as Error).message).toContain(
+ "API call did not return 200, returned status 400",
+ );
+ }
+ });
});
});
});
diff --git a/web/src/__tests__/async/scores-api-v2.servertest.ts b/web/src/__tests__/async/scores-api-v2.servertest.ts
index 1fddaeb441..1c6589bdaa 100644
--- a/web/src/__tests__/async/scores-api-v2.servertest.ts
+++ b/web/src/__tests__/async/scores-api-v2.servertest.ts
@@ -898,6 +898,78 @@ describe("/api/public/v2/scores API Endpoint", () => {
]),
);
});
+
+ it("should filter scores by dataset run ID", async () => {
+ const getScore = await makeZodVerifiedAPICall(
+ GetScoresResponseV2,
+ "GET",
+ `/api/public/v2/scores?datasetRunId=${runId}`,
+ undefined,
+ authentication,
+ );
+ expect(getScore.status).toBe(200);
+ expect(getScore.body.meta).toMatchObject({
+ page: 1,
+ limit: 50,
+ totalItems: 2,
+ totalPages: 1,
+ });
+ expect(getScore.body.data).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ id: scoreId_8,
+ datasetRunId: runId,
+ name: scoreName,
+ value: 100.5,
+ }),
+ expect.objectContaining({
+ id: scoreId_9,
+ datasetRunId: runId,
+ name: scoreName,
+ value: 100.5,
+ }),
+ ]),
+ );
+ });
+
+ it("should filter scores by trace ID", async () => {
+ const getScore = await makeZodVerifiedAPICall(
+ GetScoresResponseV2,
+ "GET",
+ `/api/public/v2/scores?traceId=${traceId}`,
+ undefined,
+ authentication,
+ );
+ expect(getScore.status).toBe(200);
+ expect(getScore.body.meta).toMatchObject({
+ page: 1,
+ limit: 50,
+ totalItems: 3,
+ totalPages: 1,
+ });
+ expect(getScore.body.data).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ id: scoreId_1,
+ traceId: traceId,
+ name: scoreName,
+ value: 10.5,
+ }),
+ expect.objectContaining({
+ id: scoreId_2,
+ traceId: traceId,
+ name: scoreName,
+ value: 50.5,
+ }),
+ expect.objectContaining({
+ id: scoreId_3,
+ traceId: traceId,
+ name: scoreName,
+ value: 100.8,
+ }),
+ ]),
+ );
+ });
});
});
});
diff --git a/web/src/features/public-api/server/scores.ts b/web/src/features/public-api/server/scores.ts
index 911e8626d6..3cdc54c48f 100644
--- a/web/src/features/public-api/server/scores.ts
+++ b/web/src/features/public-api/server/scores.ts
@@ -21,6 +21,7 @@ export type ScoreQueryType = {
scoreId?: string;
configId?: string;
sessionId?: string;
+ datasetRunId?: string;
queueId?: string;
traceTags?: string | string[];
operator?: string;
@@ -296,6 +297,13 @@ const secureScoreFilterOptions = [
filterType: "StringFilter",
clickhousePrefix: "s",
},
+ {
+ id: "datasetRunId",
+ clickhouseSelect: "dataset_run_id",
+ clickhouseTable: "scores",
+ filterType: "StringFilter",
+ clickhousePrefix: "s",
+ },
{
id: "queueId",
clickhouseSelect: "queue_id",
diff --git a/web/src/pages/api/public/v2/scores/index.ts b/web/src/pages/api/public/v2/scores/index.ts
index be3a373866..8d9167f781 100644
--- a/web/src/pages/api/public/v2/scores/index.ts
+++ b/web/src/pages/api/public/v2/scores/index.ts
@@ -21,6 +21,8 @@ export default withMiddlewares({
name: query.name ?? undefined,
configId: query.configId ?? undefined,
sessionId: query.sessionId ?? undefined,
+ traceId: query.traceId ?? undefined,
+ datasetRunId: query.datasetRunId ?? undefined,
queueId: query.queueId ?? undefined,
traceTags: query.traceTags ?? undefined,
dataType: query.dataType ?? undefined,