@arizeai/phoenix-client 6.5.1 → 6.5.3

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 (40) hide show
  1. package/README.md +194 -0
  2. package/dist/esm/__generated__/api/v1.d.ts +71 -0
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/constants/serverRequirements.d.ts +1 -0
  5. package/dist/esm/constants/serverRequirements.d.ts.map +1 -1
  6. package/dist/esm/constants/serverRequirements.js +7 -0
  7. package/dist/esm/constants/serverRequirements.js.map +1 -1
  8. package/dist/esm/traces/getTraces.d.ts +78 -0
  9. package/dist/esm/traces/getTraces.d.ts.map +1 -0
  10. package/dist/esm/traces/getTraces.js +96 -0
  11. package/dist/esm/traces/getTraces.js.map +1 -0
  12. package/dist/esm/traces/index.d.ts +2 -0
  13. package/dist/esm/traces/index.d.ts.map +1 -0
  14. package/dist/esm/traces/index.js +2 -0
  15. package/dist/esm/traces/index.js.map +1 -0
  16. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  17. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  18. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  19. package/dist/src/__generated__/api/v1.d.ts +71 -0
  20. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  21. package/dist/src/constants/serverRequirements.d.ts +1 -0
  22. package/dist/src/constants/serverRequirements.d.ts.map +1 -1
  23. package/dist/src/constants/serverRequirements.js +8 -1
  24. package/dist/src/constants/serverRequirements.js.map +1 -1
  25. package/dist/src/traces/getTraces.d.ts +78 -0
  26. package/dist/src/traces/getTraces.d.ts.map +1 -0
  27. package/dist/src/traces/getTraces.js +100 -0
  28. package/dist/src/traces/getTraces.js.map +1 -0
  29. package/dist/src/traces/index.d.ts +2 -0
  30. package/dist/src/traces/index.d.ts.map +1 -0
  31. package/dist/src/traces/index.js +18 -0
  32. package/dist/src/traces/index.js.map +1 -0
  33. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  34. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +7 -3
  37. package/src/__generated__/api/v1.ts +71 -0
  38. package/src/constants/serverRequirements.ts +8 -0
  39. package/src/traces/getTraces.ts +156 -0
  40. package/src/traces/index.ts +1 -0
package/README.md CHANGED
@@ -298,6 +298,200 @@ const experiment = await runExperiment({
298
298
 
299
299
  > **Hint:** Tasks and evaluators are instrumented using [OpenTelemetry](https://opentelemetry.io/). You can view detailed traces of experiment runs and evaluations directly in the Phoenix UI for debugging and performance analysis.
300
300
 
301
+ ## Traces
302
+
303
+ The `@arizeai/phoenix-client` package provides a `traces` export for retrieving trace data from Phoenix projects.
304
+
305
+ ### Fetching Traces
306
+
307
+ Use `getTraces` to retrieve traces with optional filtering, sorting, and pagination.
308
+
309
+ ```ts
310
+ import { getTraces } from "@arizeai/phoenix-client/traces";
311
+
312
+ // Get the latest 10 traces
313
+ const result = await getTraces({
314
+ project: { projectName: "my-project" },
315
+ limit: 10,
316
+ });
317
+ console.log(result.data); // array of trace objects
318
+
319
+ // Filter by time range and include full span details
320
+ const detailed = await getTraces({
321
+ project: { projectName: "my-project" },
322
+ startTime: "2026-03-01T00:00:00Z",
323
+ endTime: new Date(),
324
+ includeSpans: true,
325
+ sort: "latency_ms",
326
+ order: "desc",
327
+ });
328
+
329
+ // Filter by session
330
+ const sessionTraces = await getTraces({
331
+ project: { projectName: "my-project" },
332
+ sessionId: "my-session-id",
333
+ });
334
+ ```
335
+
336
+ | Parameter | Type | Description |
337
+ | -------------- | ------------------------------ | ------------------------------------------ |
338
+ | `project` | `ProjectIdentifier` | The project (by name or ID) — **required** |
339
+ | `startTime` | `Date \| string \| null` | Inclusive lower bound on trace start time |
340
+ | `endTime` | `Date \| string \| null` | Exclusive upper bound on trace start time |
341
+ | `sort` | `"start_time" \| "latency_ms"` | Sort field |
342
+ | `order` | `"asc" \| "desc"` | Sort direction |
343
+ | `limit` | `number` | Maximum number of traces to return |
344
+ | `cursor` | `string \| null` | Pagination cursor (Trace GlobalID) |
345
+ | `includeSpans` | `boolean` | Include full span details for each trace |
346
+ | `sessionId` | `string \| string[] \| null` | Filter traces by session identifier(s) |
347
+
348
+ ### Pagination
349
+
350
+ Use the `cursor` from a previous result to fetch the next page:
351
+
352
+ ```ts
353
+ import { getTraces } from "@arizeai/phoenix-client/traces";
354
+
355
+ let cursor: string | null = null;
356
+ const allTraces = [];
357
+
358
+ do {
359
+ const result = await getTraces({
360
+ project: { projectName: "my-project" },
361
+ limit: 50,
362
+ cursor,
363
+ });
364
+ allTraces.push(...result.data);
365
+ cursor = result.nextCursor ?? null;
366
+ } while (cursor);
367
+ ```
368
+
369
+ > **Note:** Requires Phoenix server >= 13.15.0.
370
+
371
+ ## Spans
372
+
373
+ The `@arizeai/phoenix-client` package provides a `spans` export for querying spans with powerful filtering.
374
+
375
+ ### Fetching Spans
376
+
377
+ Use `getSpans` to retrieve spans with filtering by kind, status, name, trace, and more.
378
+
379
+ ```ts
380
+ import { getSpans } from "@arizeai/phoenix-client/spans";
381
+
382
+ // Get recent spans
383
+ const result = await getSpans({
384
+ project: { projectName: "my-project" },
385
+ limit: 100,
386
+ });
387
+
388
+ // Filter by span kind and status
389
+ const errorLLMSpans = await getSpans({
390
+ project: { projectName: "my-project" },
391
+ spanKind: "LLM",
392
+ statusCode: "ERROR",
393
+ });
394
+
395
+ // Filter by name and trace
396
+ const spans = await getSpans({
397
+ project: { projectName: "my-project" },
398
+ name: "chat_completion",
399
+ traceIds: ["trace-abc", "trace-def"],
400
+ });
401
+
402
+ // Root spans only
403
+ const rootSpans = await getSpans({
404
+ project: { projectName: "my-project" },
405
+ parentId: null,
406
+ });
407
+ ```
408
+
409
+ | Parameter | Type | Description |
410
+ | ------------ | ------------------------------------ | --------------------------------------------------------------- |
411
+ | `project` | `ProjectIdentifier` | The project (by name or ID) — **required** |
412
+ | `startTime` | `Date \| string \| null` | Inclusive lower bound time |
413
+ | `endTime` | `Date \| string \| null` | Exclusive upper bound time |
414
+ | `limit` | `number` | Maximum number of spans to return |
415
+ | `cursor` | `string \| null` | Pagination cursor (Span GlobalID) |
416
+ | `traceIds` | `string[] \| null` | Filter by trace ID(s) |
417
+ | `parentId` | `string \| null` | Filter by parent span ID (`null` for root spans only) |
418
+ | `name` | `string \| string[] \| null` | Filter by span name(s) |
419
+ | `spanKind` | `SpanKindFilter \| SpanKindFilter[]` | Filter by span kind (`LLM`, `CHAIN`, `TOOL`, `RETRIEVER`, etc.) |
420
+ | `statusCode` | `SpanStatusCode \| SpanStatusCode[]` | Filter by status code (`OK`, `ERROR`, `UNSET`) |
421
+
422
+ ## Span Annotations
423
+
424
+ The `spans` export also provides functions for managing span annotations — adding evaluations, feedback, and labels to spans.
425
+
426
+ ### Adding a Single Annotation
427
+
428
+ ```ts
429
+ import { addSpanAnnotation } from "@arizeai/phoenix-client/spans";
430
+
431
+ const result = await addSpanAnnotation({
432
+ spanAnnotation: {
433
+ spanId: "f8b1c3a2d4e5f678",
434
+ name: "correctness",
435
+ label: "correct",
436
+ score: 1.0,
437
+ explanation: "The response accurately answered the question",
438
+ annotatorKind: "HUMAN",
439
+ },
440
+ sync: true, // wait for the annotation ID to be returned
441
+ });
442
+ // result: { id: "annotation-id" } when sync: true, null when sync: false
443
+ ```
444
+
445
+ ### Logging Multiple Annotations
446
+
447
+ ```ts
448
+ import { logSpanAnnotations } from "@arizeai/phoenix-client/spans";
449
+
450
+ const results = await logSpanAnnotations({
451
+ spanAnnotations: [
452
+ {
453
+ spanId: "f8b1c3a2d4e5f678",
454
+ name: "relevance",
455
+ label: "relevant",
456
+ score: 0.95,
457
+ annotatorKind: "LLM",
458
+ },
459
+ {
460
+ spanId: "a1b2c3d4e5f67890",
461
+ name: "relevance",
462
+ label: "irrelevant",
463
+ score: 0.2,
464
+ annotatorKind: "LLM",
465
+ },
466
+ ],
467
+ sync: true,
468
+ });
469
+ // results: [{ id: "..." }, { id: "..." }]
470
+ ```
471
+
472
+ ### Fetching Span Annotations
473
+
474
+ ```ts
475
+ import { getSpanAnnotations } from "@arizeai/phoenix-client/spans";
476
+
477
+ const result = await getSpanAnnotations({
478
+ project: { projectName: "my-project" },
479
+ spanIds: ["f8b1c3a2d4e5f678", "a1b2c3d4e5f67890"],
480
+ includeAnnotationNames: ["relevance", "correctness"],
481
+ limit: 100,
482
+ });
483
+ console.log(result.data); // array of span annotation objects
484
+ ```
485
+
486
+ | Parameter | Type | Description |
487
+ | ------------------------ | ------------------- | ------------------------------------------------ |
488
+ | `project` | `ProjectIdentifier` | The project (by name or ID) — **required** |
489
+ | `spanIds` | `string[]` | Span IDs to fetch annotations for — **required** |
490
+ | `includeAnnotationNames` | `string[]` | Only return annotations with these names |
491
+ | `excludeAnnotationNames` | `string[]` | Exclude annotations with these names |
492
+ | `cursor` | `string \| null` | Pagination cursor |
493
+ | `limit` | `number` | Maximum annotations to return |
494
+
301
495
  ## Examples
302
496
 
303
497
  To run examples, install dependencies using `pnpm` and run:
@@ -888,6 +888,26 @@ export interface paths {
888
888
  patch?: never;
889
889
  trace?: never;
890
890
  };
891
+ "/v1/user": {
892
+ parameters: {
893
+ query?: never;
894
+ header?: never;
895
+ path?: never;
896
+ cookie?: never;
897
+ };
898
+ /**
899
+ * Get the authenticated user
900
+ * @description Returns the profile of the currently authenticated user. When authentication is disabled, returns an anonymous user representation.
901
+ */
902
+ get: operations["getViewer"];
903
+ put?: never;
904
+ post?: never;
905
+ delete?: never;
906
+ options?: never;
907
+ head?: never;
908
+ patch?: never;
909
+ trace?: never;
910
+ };
891
911
  "/v1/users": {
892
912
  parameters: {
893
913
  query?: never;
@@ -997,6 +1017,14 @@ export interface components {
997
1017
  */
998
1018
  explanation?: string | null;
999
1019
  };
1020
+ /** AnonymousUser */
1021
+ AnonymousUser: {
1022
+ /**
1023
+ * @description discriminator enum property added by openapi-typescript
1024
+ * @enum {string}
1025
+ */
1026
+ auth_method: "ANONYMOUS";
1027
+ };
1000
1028
  /** CategoricalAnnotationConfig */
1001
1029
  CategoricalAnnotationConfig: {
1002
1030
  /** Name */
@@ -1592,6 +1620,11 @@ export interface components {
1592
1620
  /** Next Cursor */
1593
1621
  next_cursor: string | null;
1594
1622
  };
1623
+ /** GetViewerResponseBody */
1624
+ GetViewerResponseBody: {
1625
+ /** Data */
1626
+ data: components["schemas"]["LocalUser"] | components["schemas"]["OAuth2User"] | components["schemas"]["LDAPUser"] | components["schemas"]["AnonymousUser"];
1627
+ };
1595
1628
  /** HTTPValidationError */
1596
1629
  HTTPValidationError: {
1597
1630
  /** Detail */
@@ -6382,6 +6415,44 @@ export interface operations {
6382
6415
  };
6383
6416
  };
6384
6417
  };
6418
+ getViewer: {
6419
+ parameters: {
6420
+ query?: never;
6421
+ header?: never;
6422
+ path?: never;
6423
+ cookie?: never;
6424
+ };
6425
+ requestBody?: never;
6426
+ responses: {
6427
+ /** @description The authenticated user's profile. */
6428
+ 200: {
6429
+ headers: {
6430
+ [name: string]: unknown;
6431
+ };
6432
+ content: {
6433
+ "application/json": components["schemas"]["GetViewerResponseBody"];
6434
+ };
6435
+ };
6436
+ /** @description User not found. */
6437
+ 401: {
6438
+ headers: {
6439
+ [name: string]: unknown;
6440
+ };
6441
+ content: {
6442
+ "text/plain": string;
6443
+ };
6444
+ };
6445
+ /** @description Forbidden */
6446
+ 403: {
6447
+ headers: {
6448
+ [name: string]: unknown;
6449
+ };
6450
+ content: {
6451
+ "text/plain": string;
6452
+ };
6453
+ };
6454
+ };
6455
+ };
6385
6456
  getUsers: {
6386
6457
  parameters: {
6387
6458
  query?: {