@arizeai/phoenix-client 7.10.0 → 7.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +13 -5
  3. package/dist/esm/__generated__/api/v1.d.ts +112 -4
  4. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  5. package/dist/esm/constants/serverRequirements.d.ts +2 -0
  6. package/dist/esm/constants/serverRequirements.d.ts.map +1 -1
  7. package/dist/esm/constants/serverRequirements.js +16 -0
  8. package/dist/esm/constants/serverRequirements.js.map +1 -1
  9. package/dist/esm/prompts/createPrompt.d.ts +5 -0
  10. package/dist/esm/prompts/createPrompt.d.ts.map +1 -1
  11. package/dist/esm/prompts/createPrompt.js +27 -121
  12. package/dist/esm/prompts/createPrompt.js.map +1 -1
  13. package/dist/esm/schemas/llm/converters.d.ts +4 -4
  14. package/dist/esm/sessions/listSessions.d.ts +10 -1
  15. package/dist/esm/sessions/listSessions.d.ts.map +1 -1
  16. package/dist/esm/sessions/listSessions.js +10 -1
  17. package/dist/esm/sessions/listSessions.js.map +1 -1
  18. package/dist/esm/traces/getTraces.d.ts +10 -2
  19. package/dist/esm/traces/getTraces.d.ts.map +1 -1
  20. package/dist/esm/traces/getTraces.js +12 -4
  21. package/dist/esm/traces/getTraces.js.map +1 -1
  22. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  23. package/dist/esm/utils/getPromptBySelector.d.ts +3 -0
  24. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  25. package/dist/src/__generated__/api/v1.d.ts +112 -4
  26. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  27. package/dist/src/constants/serverRequirements.d.ts +2 -0
  28. package/dist/src/constants/serverRequirements.d.ts.map +1 -1
  29. package/dist/src/constants/serverRequirements.js +17 -1
  30. package/dist/src/constants/serverRequirements.js.map +1 -1
  31. package/dist/src/prompts/createPrompt.d.ts +5 -0
  32. package/dist/src/prompts/createPrompt.d.ts.map +1 -1
  33. package/dist/src/prompts/createPrompt.js +20 -121
  34. package/dist/src/prompts/createPrompt.js.map +1 -1
  35. package/dist/src/schemas/llm/converters.d.ts +4 -4
  36. package/dist/src/sessions/listSessions.d.ts +10 -1
  37. package/dist/src/sessions/listSessions.d.ts.map +1 -1
  38. package/dist/src/sessions/listSessions.js +9 -0
  39. package/dist/src/sessions/listSessions.js.map +1 -1
  40. package/dist/src/traces/getTraces.d.ts +10 -2
  41. package/dist/src/traces/getTraces.d.ts.map +1 -1
  42. package/dist/src/traces/getTraces.js +11 -3
  43. package/dist/src/traces/getTraces.js.map +1 -1
  44. package/dist/src/utils/getPromptBySelector.d.ts +3 -0
  45. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/docs/sessions.mdx +13 -0
  48. package/docs/traces.mdx +7 -6
  49. package/package.json +13 -13
  50. package/src/__generated__/api/v1.ts +112 -4
  51. package/src/constants/serverRequirements.ts +18 -0
  52. package/src/prompts/createPrompt.ts +35 -121
  53. package/src/sessions/listSessions.ts +22 -2
  54. package/src/traces/getTraces.ts +21 -2
package/docs/sessions.mdx CHANGED
@@ -42,6 +42,19 @@ Each session includes cumulative prompt, completion, and total token counts acro
42
42
  all of its spans. The fields may be `undefined` when using a Phoenix server that
43
43
  does not return session token usage.
44
44
 
45
+ Pass a `filter` expression to narrow the results. The language is documented on the
46
+ [Filter Expressions](/docs/phoenix/tracing/how-to-tracing/filter-expressions) page.
47
+
48
+ ```ts
49
+ const failedSessions = await listSessions({
50
+ project: "support-bot",
51
+ filter: "num_traces_with_error > 0 and duration_ms >= 60000",
52
+ });
53
+ ```
54
+
55
+ Empty expressions do not filter. Invalid expressions return HTTP 400; older
56
+ servers are rejected before sending an expression.
57
+
45
58
  ## Retrieve A Session And Its Turns
46
59
 
47
60
  ```ts
package/docs/traces.mdx CHANGED
@@ -60,16 +60,16 @@ console.log(result.nextCursor);
60
60
  - `cursor`
61
61
  - `includeSpans`
62
62
  - `sessionId`
63
- - `error`
64
- - `minLatencyMs`
65
- - `maxLatencyMs`
63
+ - `filter` — a trace DSL expression, combined with other filters using AND
64
+ - `error` (deprecated; use `filter`)
65
+ - `minLatencyMs` (deprecated; use `filter`)
66
+ - `maxLatencyMs` (deprecated; use `filter`)
66
67
 
67
68
  ```ts
68
69
  // Slow traces that contain at least one errored span
69
70
  const slowFailures = await getTraces({
70
71
  project: { projectName: "support-bot" },
71
- error: true,
72
- minLatencyMs: 1000,
72
+ filter: "error_count > 0 and latency_ms >= 1000",
73
73
  });
74
74
  ```
75
75
 
@@ -79,7 +79,8 @@ const slowFailures = await getTraces({
79
79
  - Use the returned `nextCursor` to continue pagination
80
80
  - Set `includeSpans` when you need a trace-centric fetch that also contains span details
81
81
  - `project` accepts `{ project }`, `{ projectId }`, or `{ projectName }`
82
- - `error`, `minLatencyMs`, and `maxLatencyMs` require Phoenix server >= 20.8.0; `error: false` selects traces with no errored spans
82
+ - `filter` takes a trace filter expression; the language is documented on the [Filter Expressions](/docs/phoenix/tracing/how-to-tracing/filter-expressions) page, and its [Finding field names](/docs/phoenix/tracing/how-to-tracing/filter-expressions#finding-field-names) section covers discovering valid names for your project.
83
+ - `error`, `minLatencyMs`, and `maxLatencyMs` remain supported on Phoenix server >= 20.8.0. Replace them with `error_count > 0` / `error_count == 0`, `latency_ms >= N`, and `latency_ms <= N` respectively. Latency bounds are inclusive and errors include child spans.
83
84
 
84
85
  ## Move Traces To Another Project
85
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "7.10.0",
3
+ "version": "7.12.0",
4
4
  "description": "A client for the Phoenix API",
5
5
  "keywords": [
6
6
  "arize",
@@ -103,31 +103,31 @@
103
103
  }
104
104
  },
105
105
  "dependencies": {
106
- "@arizeai/openinference-semantic-conventions": "^2.7.0",
106
+ "@arizeai/openinference-semantic-conventions": "^2.12.0",
107
107
  "@arizeai/phoenix-config": "0.5.0",
108
108
  "@arizeai/phoenix-otel": "2.2.0",
109
109
  "async": "^3.2.6",
110
110
  "openapi-fetch": "^0.17.0",
111
111
  "tiny-invariant": "^1.3.3",
112
- "zod": "^4.4.3"
112
+ "zod": "^4.6.5"
113
113
  },
114
114
  "devDependencies": {
115
- "@ai-sdk/openai": "^4.0.46",
116
- "@ai-sdk/otel": "^1.0.77",
115
+ "@ai-sdk/openai": "^4.0.71",
116
+ "@ai-sdk/otel": "^1.0.107",
117
117
  "@anthropic-ai/sdk": "^0.111.0",
118
- "@arizeai/phoenix-evals": "2.4.0",
118
+ "@arizeai/phoenix-evals": "2.5.0",
119
119
  "@arizeai/phoenix-testing": "0.0.0",
120
120
  "@opentelemetry/api": "^1.9.1",
121
- "@opentelemetry/sdk-trace-node": "^2.10.0",
122
- "@types/async": "^3.2.25",
123
- "@types/node": "^26.2.0",
124
- "ai": "^7.0.77",
121
+ "@opentelemetry/sdk-trace-node": "^2.11.0",
122
+ "@types/async": "^3.2.26",
123
+ "@types/node": "^26.6.2",
124
+ "ai": "^7.0.107",
125
125
  "dotenv": "^17.4.2",
126
- "jest": "^30.4.2",
126
+ "jest": "^30.5.2",
127
127
  "openai": "^6.49.0",
128
128
  "openapi-typescript": "^7.13.0",
129
- "tsx": "^4.23.12",
130
- "vitest": "^5.0.0"
129
+ "tsx": "^4.23.13",
130
+ "vitest": "^5.0.1"
131
131
  },
132
132
  "peerDependencies": {
133
133
  "@anthropic-ai/sdk": "^0.35.0",
@@ -430,7 +430,8 @@ export interface paths {
430
430
  path?: never;
431
431
  cookie?: never;
432
432
  };
433
- get?: never;
433
+ /** List dataset splits */
434
+ get: operations["listDatasetSplits"];
434
435
  put?: never;
435
436
  /** Create a dataset split */
436
437
  post: operations["createDatasetSplit"];
@@ -3980,6 +3981,13 @@ export interface components {
3980
3981
  /** Data */
3981
3982
  data: components["schemas"]["DatasetLabel"][];
3982
3983
  };
3984
+ /** ListDatasetSplitsResponseBody */
3985
+ ListDatasetSplitsResponseBody: {
3986
+ /** Data */
3987
+ data: components["schemas"]["DatasetSplit"][];
3988
+ /** Next Cursor */
3989
+ next_cursor: string | null;
3990
+ };
3983
3991
  /** ListDatasetVersionsResponseBody */
3984
3992
  ListDatasetVersionsResponseBody: {
3985
3993
  /** Data */
@@ -5296,6 +5304,13 @@ export interface components {
5296
5304
  PromptVersion: {
5297
5305
  /** Description */
5298
5306
  description?: string | null;
5307
+ /**
5308
+ * Metadata
5309
+ * @description Arbitrary JSON metadata for the prompt version.
5310
+ */
5311
+ metadata?: {
5312
+ [key: string]: unknown;
5313
+ };
5299
5314
  model_provider: components["schemas"]["ModelProvider"];
5300
5315
  /** Model Name */
5301
5316
  model_name: string;
@@ -5315,6 +5330,13 @@ export interface components {
5315
5330
  PromptVersionData: {
5316
5331
  /** Description */
5317
5332
  description?: string | null;
5333
+ /**
5334
+ * Metadata
5335
+ * @description Arbitrary JSON metadata for the prompt version.
5336
+ */
5337
+ metadata?: {
5338
+ [key: string]: unknown;
5339
+ };
5318
5340
  model_provider: components["schemas"]["ModelProvider"];
5319
5341
  /** Model Name */
5320
5342
  model_name: string;
@@ -8945,6 +8967,61 @@ export interface operations {
8945
8967
  };
8946
8968
  };
8947
8969
  };
8970
+ listDatasetSplits: {
8971
+ parameters: {
8972
+ query?: {
8973
+ /** @description Cursor for pagination */
8974
+ cursor?: string | null;
8975
+ /** @description The max number of dataset splits to return at a time. */
8976
+ limit?: number;
8977
+ };
8978
+ header?: never;
8979
+ path: {
8980
+ /** @description The dataset identifier: either dataset ID or dataset name. */
8981
+ dataset_identifier: string;
8982
+ };
8983
+ cookie?: never;
8984
+ };
8985
+ requestBody?: never;
8986
+ responses: {
8987
+ /** @description Successful Response */
8988
+ 200: {
8989
+ headers: {
8990
+ [name: string]: unknown;
8991
+ };
8992
+ content: {
8993
+ "application/json": components["schemas"]["ListDatasetSplitsResponseBody"];
8994
+ };
8995
+ };
8996
+ /** @description Forbidden */
8997
+ 403: {
8998
+ headers: {
8999
+ [name: string]: unknown;
9000
+ };
9001
+ content: {
9002
+ "text/plain": string;
9003
+ };
9004
+ };
9005
+ /** @description Dataset not found */
9006
+ 404: {
9007
+ headers: {
9008
+ [name: string]: unknown;
9009
+ };
9010
+ content: {
9011
+ "text/plain": string;
9012
+ };
9013
+ };
9014
+ /** @description Invalid request */
9015
+ 422: {
9016
+ headers: {
9017
+ [name: string]: unknown;
9018
+ };
9019
+ content: {
9020
+ "text/plain": string;
9021
+ };
9022
+ };
9023
+ };
9024
+ };
8948
9025
  createDatasetSplit: {
8949
9026
  parameters: {
8950
9027
  query?: never;
@@ -10098,12 +10175,23 @@ export interface operations {
10098
10175
  include_spans?: boolean;
10099
10176
  /** @description List of session identifiers to filter traces by. Each value can be either a session_id string or a session GlobalID. Only traces belonging to the specified sessions will be returned. */
10100
10177
  session_identifier?: string[] | null;
10101
- /** @description Filter by trace error status. If true, only return traces that contain at least one span with `status_code == ERROR`. If false, only return traces with no errored spans. If omitted, traces are not filtered by error status. Matches the error indicator shown in the UI. */
10178
+ /**
10179
+ * @deprecated
10180
+ * @description Deprecated: use `filter=error_count > 0` or `filter=error_count == 0`. Filter by trace error status. If true, only return traces that contain at least one span with `status_code == ERROR`. If false, only return traces with no errored spans. If omitted, traces are not filtered by error status.
10181
+ */
10102
10182
  error?: boolean | null;
10103
- /** @description Inclusive lower bound on trace latency in milliseconds. */
10183
+ /**
10184
+ * @deprecated
10185
+ * @description Inclusive lower bound on trace latency in milliseconds. Deprecated: use `filter=latency_ms >= N`.
10186
+ */
10104
10187
  min_latency_ms?: number | null;
10105
- /** @description Inclusive upper bound on trace latency in milliseconds. */
10188
+ /**
10189
+ * @deprecated
10190
+ * @description Inclusive upper bound on trace latency in milliseconds. Deprecated: use `filter=latency_ms <= N`.
10191
+ */
10106
10192
  max_latency_ms?: number | null;
10193
+ /** @description Trace filter expression, as documented at https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions. Combined with other filters using AND. Empty expressions do not filter. Invalid expressions return 400. */
10194
+ filter?: string | null;
10107
10195
  };
10108
10196
  header?: never;
10109
10197
  path: {
@@ -10123,6 +10211,15 @@ export interface operations {
10123
10211
  "application/json": components["schemas"]["GetTracesResponseBody"];
10124
10212
  };
10125
10213
  };
10214
+ /** @description Bad Request */
10215
+ 400: {
10216
+ headers: {
10217
+ [name: string]: unknown;
10218
+ };
10219
+ content: {
10220
+ "text/plain": string;
10221
+ };
10222
+ };
10126
10223
  /** @description Forbidden */
10127
10224
  403: {
10128
10225
  headers: {
@@ -11890,6 +11987,8 @@ export interface operations {
11890
11987
  limit?: number;
11891
11988
  /** @description Sort order by ID: 'asc' (ascending) or 'desc' (descending). */
11892
11989
  order?: "asc" | "desc";
11990
+ /** @description Session filter expression, as documented at https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions. Empty expressions do not filter. Invalid expressions return 400. */
11991
+ filter?: string | null;
11893
11992
  };
11894
11993
  header?: never;
11895
11994
  path: {
@@ -11909,6 +12008,15 @@ export interface operations {
11909
12008
  "application/json": components["schemas"]["GetSessionsResponseBody"];
11910
12009
  };
11911
12010
  };
12011
+ /** @description Bad Request */
12012
+ 400: {
12013
+ headers: {
12014
+ [name: string]: unknown;
12015
+ };
12016
+ content: {
12017
+ "text/plain": string;
12018
+ };
12019
+ };
11912
12020
  /** @description Forbidden */
11913
12021
  403: {
11914
12022
  headers: {
@@ -108,6 +108,22 @@ export const GET_TRACES_FILTERS: ParameterRequirement = {
108
108
  "The 'error', 'min_latency_ms', and 'max_latency_ms' query parameters on GET /v1/projects/{id}/traces",
109
109
  };
110
110
 
111
+ export const GET_TRACES_FILTER_EXPRESSION: ParameterRequirement = {
112
+ kind: "parameter",
113
+ parameterName: "filter",
114
+ parameterLocation: "query",
115
+ route: "GET /v1/projects/{id}/traces",
116
+ minServerVersion: [20, 12, 0],
117
+ };
118
+
119
+ export const LIST_SESSIONS_FILTER_EXPRESSION: ParameterRequirement = {
120
+ kind: "parameter",
121
+ parameterName: "filter",
122
+ parameterLocation: "query",
123
+ route: "GET /v1/projects/{id}/sessions",
124
+ minServerVersion: [20, 12, 0],
125
+ };
126
+
111
127
  export const TRANSFER_TRACES: RouteRequirement = {
112
128
  kind: "route",
113
129
  method: "POST",
@@ -245,6 +261,8 @@ export const ALL_REQUIREMENTS: readonly CapabilityRequirement[] = [
245
261
  GET_SPANS_BY_ATTRIBUTE,
246
262
  LIST_PROJECT_TRACES,
247
263
  GET_TRACES_FILTERS,
264
+ GET_TRACES_FILTER_EXPRESSION,
265
+ LIST_SESSIONS_FILTER_EXPRESSION,
248
266
  TRANSFER_TRACES,
249
267
  DATASET_UPLOAD_EXAMPLE_IDS,
250
268
  ADD_TRACE_NOTE_IDENTIFIER,
@@ -84,6 +84,11 @@ interface PromptVersionInputBase {
84
84
  * The description of the prompt version.
85
85
  */
86
86
  description?: string;
87
+ /**
88
+ * Optional metadata for the prompt version as a JSON object.
89
+ * @example { "agent": "support", "dependencies": ["retriever"] }
90
+ */
91
+ metadata?: PromptVersionData["metadata"];
87
92
  /**
88
93
  * The name of the model to use for the prompt version.
89
94
  */
@@ -165,142 +170,51 @@ export type PromptVersionInput =
165
170
  export function promptVersion(params: PromptVersionInput): PromptVersionData {
166
171
  const {
167
172
  description = "",
173
+ metadata,
168
174
  modelProvider: model_provider,
169
175
  modelName: model_name,
170
176
  template: templateMessages,
171
177
  templateFormat: template_format = "MUSTACHE",
172
- invocationParameters: invocation_parameters,
173
178
  } = params;
174
- switch (model_provider) {
179
+ return {
180
+ description,
181
+ ...(metadata ? { metadata } : {}),
182
+ model_provider,
183
+ model_name,
184
+ template_type: "CHAT",
185
+ template_format,
186
+ template: {
187
+ type: "chat",
188
+ messages: templateMessages,
189
+ },
190
+ invocation_parameters: toInvocationParameters(params),
191
+ };
192
+ }
193
+
194
+ function toInvocationParameters(
195
+ params: PromptVersionInput
196
+ ): PromptVersionData["invocation_parameters"] {
197
+ switch (params.modelProvider) {
175
198
  case "OPENAI":
176
- return {
177
- description,
178
- model_provider,
179
- model_name,
180
- template_type: "CHAT",
181
- template_format,
182
- template: {
183
- type: "chat",
184
- messages: templateMessages,
185
- },
186
- invocation_parameters: {
187
- type: "openai",
188
- openai: invocation_parameters ?? {},
189
- },
190
- };
199
+ return { type: "openai", openai: params.invocationParameters ?? {} };
191
200
  case "AZURE_OPENAI":
192
201
  return {
193
- description,
194
- model_provider,
195
- model_name,
196
- template_type: "CHAT",
197
- template_format,
198
- template: {
199
- type: "chat",
200
- messages: templateMessages,
201
- },
202
- invocation_parameters: {
203
- type: "azure_openai",
204
- azure_openai: invocation_parameters ?? {},
205
- },
202
+ type: "azure_openai",
203
+ azure_openai: params.invocationParameters ?? {},
206
204
  };
207
205
  case "ANTHROPIC":
208
- return {
209
- description,
210
- model_provider,
211
- model_name,
212
- template_type: "CHAT",
213
- template_format,
214
- template: {
215
- type: "chat",
216
- messages: templateMessages,
217
- },
218
- invocation_parameters: {
219
- type: "anthropic",
220
- anthropic: invocation_parameters,
221
- },
222
- };
206
+ return { type: "anthropic", anthropic: params.invocationParameters };
223
207
  case "GOOGLE":
224
- return {
225
- description,
226
- model_provider,
227
- model_name,
228
- template_type: "CHAT",
229
- template_format,
230
- template: {
231
- type: "chat",
232
- messages: templateMessages,
233
- },
234
- invocation_parameters: {
235
- type: "google",
236
- google: invocation_parameters ?? {},
237
- },
238
- };
208
+ return { type: "google", google: params.invocationParameters ?? {} };
239
209
  case "DEEPSEEK":
240
- return {
241
- description,
242
- model_provider,
243
- model_name,
244
- template_type: "CHAT",
245
- template_format,
246
- template: {
247
- type: "chat",
248
- messages: templateMessages,
249
- },
250
- invocation_parameters: {
251
- type: "deepseek",
252
- deepseek: invocation_parameters ?? {},
253
- },
254
- };
210
+ return { type: "deepseek", deepseek: params.invocationParameters ?? {} };
255
211
  case "XAI":
256
- return {
257
- description,
258
- model_provider,
259
- model_name,
260
- template_type: "CHAT",
261
- template_format,
262
- template: {
263
- type: "chat",
264
- messages: templateMessages,
265
- },
266
- invocation_parameters: {
267
- type: "xai",
268
- xai: invocation_parameters ?? {},
269
- },
270
- };
212
+ return { type: "xai", xai: params.invocationParameters ?? {} };
271
213
  case "OLLAMA":
272
- return {
273
- description,
274
- model_provider,
275
- model_name,
276
- template_type: "CHAT",
277
- template_format,
278
- template: {
279
- type: "chat",
280
- messages: templateMessages,
281
- },
282
- invocation_parameters: {
283
- type: "ollama",
284
- ollama: invocation_parameters ?? {},
285
- },
286
- };
214
+ return { type: "ollama", ollama: params.invocationParameters ?? {} };
287
215
  case "AWS":
288
- return {
289
- description,
290
- model_provider,
291
- model_name,
292
- template_type: "CHAT",
293
- template_format,
294
- template: {
295
- type: "chat",
296
- messages: templateMessages,
297
- },
298
- invocation_parameters: {
299
- type: "aws",
300
- aws: invocation_parameters ?? {},
301
- },
302
- };
216
+ return { type: "aws", aws: params.invocationParameters ?? {} };
303
217
  default:
304
- return assertUnreachable(model_provider);
218
+ return assertUnreachable(params);
305
219
  }
306
220
  }
@@ -2,7 +2,10 @@ import invariant from "tiny-invariant";
2
2
 
3
3
  import type { components } from "../__generated__/api/v1";
4
4
  import { createClient } from "../client";
5
- import { LIST_PROJECT_SESSIONS } from "../constants/serverRequirements";
5
+ import {
6
+ LIST_PROJECT_SESSIONS,
7
+ LIST_SESSIONS_FILTER_EXPRESSION,
8
+ } from "../constants/serverRequirements";
6
9
  import type { ClientFn } from "../types/core";
7
10
  import type { ProjectIdentifier } from "../types/projects";
8
11
  import { resolveProjectIdentifier } from "../types/projects";
@@ -10,7 +13,15 @@ import type { Session } from "../types/sessions";
10
13
  import { ensureServerCapability } from "../utils/serverVersionUtils";
11
14
  import { toSession } from "./sessionUtils";
12
15
 
13
- export type ListSessionsParams = ClientFn & ProjectIdentifier;
16
+ export type ListSessionsParams = ClientFn &
17
+ ProjectIdentifier & {
18
+ /**
19
+ * Session filter expression.
20
+ * @see https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions
21
+ * @requires Phoenix server >= 20.12.0
22
+ */
23
+ filter?: string | null;
24
+ };
14
25
 
15
26
  type SessionsResponse = components["schemas"]["GetSessionsResponseBody"];
16
27
 
@@ -20,6 +31,8 @@ const DEFAULT_PAGE_SIZE = 100;
20
31
  * List all sessions for a project with automatic pagination handling.
21
32
  *
22
33
  * @requires Phoenix server >= 13.5.0
34
+ * @param params - Project and filtering options.
35
+ * @param params.filter - Session filter expression, passed unchanged on every page.
23
36
  *
24
37
  * @example
25
38
  * ```ts
@@ -39,6 +52,12 @@ export async function listSessions(
39
52
  ): Promise<Session[]> {
40
53
  const client = params.client || createClient();
41
54
  await ensureServerCapability({ client, requirement: LIST_PROJECT_SESSIONS });
55
+ if (params.filter) {
56
+ await ensureServerCapability({
57
+ client,
58
+ requirement: LIST_SESSIONS_FILTER_EXPRESSION,
59
+ });
60
+ }
42
61
  const projectIdentifier = resolveProjectIdentifier(params);
43
62
 
44
63
  const sessions: Session[] = [];
@@ -54,6 +73,7 @@ export async function listSessions(
54
73
  query: {
55
74
  cursor,
56
75
  limit: DEFAULT_PAGE_SIZE,
76
+ filter: params.filter || undefined,
57
77
  },
58
78
  },
59
79
  });
@@ -1,6 +1,7 @@
1
1
  import type { operations } from "../__generated__/api/v1";
2
2
  import { createClient } from "../client";
3
3
  import {
4
+ GET_TRACES_FILTER_EXPRESSION,
4
5
  GET_TRACES_FILTERS,
5
6
  LIST_PROJECT_TRACES,
6
7
  } from "../constants/serverRequirements";
@@ -31,22 +32,31 @@ export interface GetTracesParams extends ClientFn {
31
32
  includeSpans?: boolean;
32
33
  /** Filter traces by session identifier(s) (session_id strings or GlobalIDs) */
33
34
  sessionId?: string | string[] | null;
35
+ /**
36
+ * Trace filter expression, combined with other filters using AND.
37
+ * @see https://arize.com/docs/phoenix/tracing/how-to-tracing/filter-expressions
38
+ * @requires Phoenix server >= 20.12.0
39
+ */
40
+ filter?: string | null;
34
41
  /**
35
42
  * Filter by trace error status. `true` returns only traces containing at
36
43
  * least one errored span, `false` only traces with no errored spans.
37
44
  * Omit to leave traces unfiltered by error status.
45
+ * @deprecated Use `filter: "error_count > 0"` or `filter: "error_count == 0"`.
38
46
  *
39
47
  * @requires Phoenix server >= 20.8.0
40
48
  */
41
49
  error?: boolean | null;
42
50
  /**
43
51
  * Inclusive lower bound on trace latency in milliseconds.
52
+ * @deprecated Use `filter: "latency_ms >= N"`.
44
53
  *
45
54
  * @requires Phoenix server >= 20.8.0
46
55
  */
47
56
  minLatencyMs?: number | null;
48
57
  /**
49
58
  * Inclusive upper bound on trace latency in milliseconds.
59
+ * @deprecated Use `filter: "latency_ms <= N"`.
50
60
  *
51
61
  * @requires Phoenix server >= 20.8.0
52
62
  */
@@ -96,11 +106,15 @@ function buildQuery({
96
106
  order,
97
107
  includeSpans,
98
108
  sessionId,
109
+ filter,
99
110
  error,
100
111
  minLatencyMs,
101
112
  maxLatencyMs,
102
113
  }: Omit<GetTracesParams, "client" | "project">): ListProjectTracesQuery {
103
114
  const query: ListProjectTracesQuery = { limit };
115
+ if (filter) {
116
+ query.filter = filter;
117
+ }
104
118
  if (cursor) {
105
119
  query.cursor = cursor;
106
120
  }
@@ -195,8 +209,7 @@ export type GetTracesResult = {
195
209
  * const slowFailures = await getTraces({
196
210
  * client,
197
211
  * project: { projectName: "my-project" },
198
- * error: true,
199
- * minLatencyMs: 1000,
212
+ * filter: "error_count > 0 and latency_ms >= 1000",
200
213
  * });
201
214
  * ```
202
215
  */
@@ -209,6 +222,12 @@ export async function getTraces({
209
222
  const client = _client ?? createClient();
210
223
  validateLatencyBounds({ minLatencyMs, maxLatencyMs });
211
224
  await ensureServerCapability({ client, requirement: LIST_PROJECT_TRACES });
225
+ if (params.filter) {
226
+ await ensureServerCapability({
227
+ client,
228
+ requirement: GET_TRACES_FILTER_EXPRESSION,
229
+ });
230
+ }
212
231
  if (errorFilter != null || minLatencyMs != null || maxLatencyMs != null) {
213
232
  await ensureServerCapability({ client, requirement: GET_TRACES_FILTERS });
214
233
  }