Skip to content

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

Extend public API: GET (#59)

Marc Klingene85fc41855b2
diff --git a/fern/fern.config.json b/fern/fern.config.json
index f4eba3f9ba..8f90f7fdb5 100644
--- a/fern/fern.config.json
+++ b/fern/fern.config.json
@@ -1,4 +1,4 @@
{
"organization": "finto",
- "version": "0.11.6"
+ "version": "0.11.9"
}
\ No newline at end of file
diff --git a/fern/server/definition/api.yml b/fern/server/definition/api.yml
index 31fe7c6ed9..d1a754b5c7 100644
--- a/fern/server/definition/api.yml
+++ b/fern/server/definition/api.yml
@@ -9,6 +9,7 @@ errors:
- commons.UnauthorizedError
- commons.AccessDeniedError
- commons.MethodNotAllowedError
+ - commons.NotFoundError
headers:
X-Langfuse-Sdk-Name: optional<string>
X-Langfuse-Sdk-Version: optional<string>
diff --git a/fern/server/definition/commons.yml b/fern/server/definition/commons.yml
index 98fc49843f..f0c66aef93 100644
--- a/fern/server/definition/commons.yml
+++ b/fern/server/definition/commons.yml
@@ -1,3 +1,101 @@
+types:
+ # Create Bodies
+ CreateEventRequest:
+ properties:
+ id: optional<string>
+ traceId: optional<string>
+ traceIdType: optional<TraceIdTypeEnum>
+ name: optional<string>
+ startTime: optional<datetime>
+ metadata: optional<unknown>
+ input: optional<unknown>
+ output: optional<unknown>
+ level: optional<ObservationLevel>
+ statusMessage: optional<string>
+ parentObservationId: optional<string>
+ CreateSpanRequest:
+ extends: CreateEventRequest
+ properties:
+ endTime: optional<datetime>
+ CreateGenerationRequest:
+ extends: CreateSpanRequest
+ properties:
+ completionStartTime: optional<datetime>
+ model: optional<string>
+ modelParameters: optional<map<string, MapValue>>
+ prompt: optional<unknown>
+ completion: optional<string>
+ usage: optional<LLMUsage>
+
+ # Objects
+ Trace:
+ properties:
+ id:
+ type: string
+ docs: The unique identifier of a trace
+ timestamp: datetime
+ externalId: optional<string>
+ name: optional<string>
+ userId: optional<string>
+ metadata: optional<unknown>
+ TraceWithDetails:
+ extends: Trace
+ properties:
+ observations: list<Observation>
+ scores: list<Score>
+ Observation:
+ properties:
+ id: string
+ traceId: string
+ type: string
+ name: optional<string>
+ startTime: datetime
+ endTime: optional<datetime>
+ completionStartTime: optional<datetime>
+ model: optional<string>
+ modelParameters: optional<map<string, MapValue>>
+ prompt: optional<unknown>
+ metadata: optional<unknown>
+ completion: optional<string>
+ promptTokens: integer
+ completionTokens: integer
+ totalTokens: integer
+ level: ObservationLevel
+ statusMessage: optional<string>
+ parentObservationId: optional<string>
+ Score:
+ properties:
+ id: string
+ traceId: string
+ name: string
+ value: integer
+ observationId: optional<string>
+ timestamp: datetime
+ comment: optional<string>
+
+ # Utilities
+ ObservationLevel:
+ enum:
+ - DEBUG
+ - DEFAULT
+ - WARNING
+ - ERROR
+ MapValue:
+ discriminated: false
+ union:
+ - optional<string>
+ - optional<integer>
+ - optional<boolean>
+ TraceIdTypeEnum:
+ enum:
+ - LANGFUSE
+ - EXTERNAL
+ LLMUsage:
+ properties:
+ promptTokens: optional<integer>
+ completionTokens: optional<integer>
+ totalTokens: optional<integer>
+
errors:
Error:
status-code: 400
@@ -8,6 +106,9 @@ errors:
AccessDeniedError:
status-code: 403
type: string
+ NotFoundError:
+ status-code: 404
+ type: string
MethodNotAllowedError:
status-code: 405
type: string
diff --git a/fern/server/definition/event.yml b/fern/server/definition/event.yml
index 42704ce16d..7ef16cefc0 100644
--- a/fern/server/definition/event.yml
+++ b/fern/server/definition/event.yml
@@ -1,5 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
-
+imports:
+ commons: ./commons.yml
service:
auth: true
base-path: /api/public
@@ -8,43 +9,5 @@ service:
docs: Add an event to the database
method: POST
path: /events
- request: CreateEventRequest
- response: Event
-
-types:
- CreateEventRequest:
- properties:
- id: optional<string>
- traceId: optional<string>
- traceIdType: optional<TraceIdTypeEvent>
- name: optional<string>
- startTime: optional<datetime>
- metadata: optional<unknown>
- input: optional<unknown>
- output: optional<unknown>
- level: optional<ObservationLevelEvent>
- statusMessage: optional<string>
- parentObservationId: optional<string>
- Event:
- properties:
- id: string
- traceId: string
- type: string
- name: optional<string>
- startTime: datetime
- metadata: optional<unknown>
- input: optional<unknown>
- output: optional<unknown>
- level: ObservationLevelEvent
- statusMessage: optional<string>
- parentObservationId: optional<string>
- ObservationLevelEvent:
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeEvent:
- enum:
- - LANGFUSE
- - EXTERNAL
+ request: commons.CreateEventRequest
+ response: commons.Observation
diff --git a/fern/server/definition/generations.yml b/fern/server/definition/generations.yml
index 46250a1b0f..323164bb57 100644
--- a/fern/server/definition/generations.yml
+++ b/fern/server/definition/generations.yml
@@ -1,5 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
-
+imports:
+ commons: ./commons.yml
service:
auth: true
base-path: /api/public
@@ -7,34 +8,15 @@ service:
log:
method: POST
path: /generations
- request: CreateLog
- response: Log
+ request: commons.CreateGenerationRequest
+ response: commons.Observation
update:
method: PATCH
path: /generations
request: UpdateGenerationRequest
- response: Log
+ response: commons.Observation
types:
- CreateLog:
- properties:
- id: optional<string>
- traceId: optional<string>
- traceIdType: optional<TraceIdTypeGenerations>
- name: optional<string>
- startTime: optional<datetime>
- endTime: optional<datetime>
- completionStartTime: optional<datetime>
- model: optional<string>
- modelParameters: optional<map<string, MapValue>>
- prompt: optional<unknown>
- metadata: optional<unknown>
- completion: optional<string>
- usage: optional<LLMUsage>
- level: optional<ObservationLevelGeneration>
- statusMessage: optional<string>
- parentObservationId: optional<string>
-
UpdateGenerationRequest:
properties:
generationId: string
@@ -42,54 +24,10 @@ types:
endTime: optional<datetime>
completionStartTime: optional<datetime>
model: optional<string>
- modelParameters: optional<map<string, MapValue>>
- prompt: optional<unknown>
- metadata: optional<unknown>
- completion: optional<string>
- usage: optional<LLMUsage>
- level: optional<ObservationLevelGeneration>
- statusMessage: optional<string>
-
- Log:
- properties:
- id: string
- traceId: string
- type: string
- name: optional<string>
- startTime: datetime
- endTime: optional<datetime>
- completionStartTime: optional<datetime>
- model: optional<string>
- modelParameters: optional<map<string, MapValue>>
+ modelParameters: optional<map<string, commons.MapValue>>
prompt: optional<unknown>
metadata: optional<unknown>
completion: optional<string>
- promptTokens: integer
- completionTokens: integer
- totalTokens: integer
- level: ObservationLevelGeneration
+ usage: optional<commons.LLMUsage>
+ level: optional<commons.ObservationLevel>
statusMessage: optional<string>
- parentObservationId: optional<string>
-
- LLMUsage:
- properties:
- promptTokens: optional<integer>
- completionTokens: optional<integer>
- totalTokens: optional<integer>
-
- MapValue:
- discriminated: false
- union:
- - optional<string>
- - optional<integer>
- - optional<boolean>
- ObservationLevelGeneration:
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeGenerations:
- enum:
- - LANGFUSE
- - EXTERNAL
diff --git a/fern/server/definition/observations.yml b/fern/server/definition/observations.yml
new file mode 100644
index 0000000000..5da7beef96
--- /dev/null
+++ b/fern/server/definition/observations.yml
@@ -0,0 +1,16 @@
+# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
+imports:
+ commons: ./commons.yml
+service:
+ auth: true
+ base-path: /api/public
+ endpoints:
+ get:
+ docs: Get a specific observation
+ method: GET
+ path: /observations/{observationId}
+ path-parameters:
+ observationId:
+ type: string
+ docs: The unique langfuse identifier of an observation, can be an event, span or generation
+ response: commons.Observation
diff --git a/fern/server/definition/score.yml b/fern/server/definition/score.yml
index 8dc6902f08..119c9377d4 100644
--- a/fern/server/definition/score.yml
+++ b/fern/server/definition/score.yml
@@ -1,5 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
-
+imports:
+ pagination: ./utils/pagination.yml
+ commons: ./commons.yml
service:
auth: true
base-path: /api/public
@@ -9,28 +11,30 @@ service:
method: POST
path: /scores
request: CreateScoreRequest
- response: Score
-
+ response: commons.Score
+ get:
+ docs: Get scores
+ method: GET
+ path: /scores
+ request:
+ name: GetScoresRequest
+ query-parameters:
+ page: optional<integer>
+ limit: optional<integer>
+ userId: optional<string>
+ name: optional<string>
+ response: Scores
types:
CreateScoreRequest:
properties:
id: optional<string>
traceId: string
- traceIdType: optional<TraceIdType>
+ traceIdType: optional<commons.TraceIdTypeEnum>
name: string
value: integer
observationId: optional<string>
comment: optional<string>
- Score:
+ Scores:
properties:
- id: string
- traceId: string
- name: string
- value: integer
- observationId: optional<string>
- timestamp: datetime
- comment: optional<string>
- TraceIdType:
- enum:
- - LANGFUSE
- - EXTERNAL
+ data: list<commons.Score>
+ meta: pagination.MetaResponse
diff --git a/fern/server/definition/span.yml b/fern/server/definition/span.yml
index 4cf42d7102..04d0ab63d2 100644
--- a/fern/server/definition/span.yml
+++ b/fern/server/definition/span.yml
@@ -1,5 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
-
+imports:
+ commons: ./commons.yml
service:
auth: true
base-path: /api/public
@@ -8,31 +9,16 @@ service:
docs: Add a span to the database
method: POST
path: /spans
- request: CreateSpanRequest
- response: Span
+ request: commons.CreateSpanRequest
+ response: commons.Observation
update:
docs: Update a span to the database
method: PATCH
path: /spans
request: UpdateSpanRequest
- response: Span
+ response: commons.Observation
types:
- CreateSpanRequest:
- properties:
- id: optional<string>
- traceId: optional<string>
- traceIdType: optional<TraceIdTypeSpan>
- name: optional<string>
- startTime: optional<datetime>
- endTime: optional<datetime>
- metadata: optional<unknown>
- input: optional<unknown>
- output: optional<unknown>
- level: optional<ObservationLevelSpan>
- statusMessage: optional<string>
- parentObservationId: optional<string>
-
UpdateSpanRequest:
properties:
spanId: string
@@ -40,30 +26,5 @@ types:
metadata: optional<unknown>
input: optional<unknown>
output: optional<unknown>
- level: optional<ObservationLevelSpan>
- statusMessage: optional<string>
-
- Span:
- properties:
- id: string
- traceId: string
- type: string
- name: optional<string>
- startTime: datetime
- endTime: optional<datetime>
- metadata: optional<unknown>
- input: optional<unknown>
- output: optional<unknown>
- level: ObservationLevelSpan
+ level: optional<commons.ObservationLevel>
statusMessage: optional<string>
- parentObservationId: optional<string>
- ObservationLevelSpan:
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeSpan:
- enum:
- - LANGFUSE
- - EXTERNAL
diff --git a/fern/server/definition/trace.yml b/fern/server/definition/trace.yml
index 4d849c2a3f..d50c3294d5 100644
--- a/fern/server/definition/trace.yml
+++ b/fern/server/definition/trace.yml
@@ -1,5 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
-
+imports:
+ commons: ./commons.yml
service:
auth: true
base-path: /api/public
@@ -9,7 +10,16 @@ service:
method: POST
path: /traces
request: CreateTraceRequest
- response: Trace
+ response: commons.Trace
+ get:
+ docs: Get a specific trace
+ method: GET
+ path: /traces/{traceId}
+ path-parameters:
+ traceId:
+ type: string
+ docs: The unique langfuse identifier of a trace
+ response: commons.TraceWithDetails
types:
CreateTraceRequest:
@@ -18,11 +28,3 @@ types:
userId: optional<string>
externalId: optional<string>
metadata: optional<unknown>
- Trace:
- properties:
- id: string
- timestamp: datetime
- externalId: optional<string>
- name: optional<string>
- userId: optional<string>
- metadata: optional<unknown>
diff --git a/fern/server/definition/utils/pagination.yml b/fern/server/definition/utils/pagination.yml
new file mode 100644
index 0000000000..e66b72b30f
--- /dev/null
+++ b/fern/server/definition/utils/pagination.yml
@@ -0,0 +1,7 @@
+types:
+ MetaResponse:
+ properties:
+ page: integer
+ limit: integer
+ totalItems: integer
+ totalPages: integer
diff --git a/fern/server/generators.yml b/fern/server/generators.yml
index c0c339356c..5ae76e188c 100644
--- a/fern/server/generators.yml
+++ b/fern/server/generators.yml
@@ -2,45 +2,47 @@ default-group: local
groups:
local:
generators:
- - name: fernapi/fern-typescript-node-sdk
- version: 0.7.1
+ - name: fernapi/fern-openapi
+ version: 0.0.28
output:
- location: npm
- url: npm.buildwithfern.com
- package-name: "@finto-fern/langfuse-node"
+ location: local-file-system
+ path: ../../generated/openapi-server
config:
namespaceExport: Langfuse
allowCustomFetcher: true
- name: fernapi/fern-python-sdk
version: 0.3.7
output:
- location: pypi
- url: pypi.buildwithfern.com
- package-name: finto-fern-langfuse
+ location: local-file-system
+ path: ../../generated/python
config:
namespaceExport: Langfuse
allowCustomFetcher: true
- - name: fernapi/fern-openapi
- version: 0.0.28
+ - name: fernapi/fern-typescript-node-sdk
+ version: 0.7.1
output:
location: local-file-system
- path: ../../generated/openapi-server
+ path: ../../generated/typescript-server
config:
namespaceExport: Langfuse
allowCustomFetcher: true
+ published:
+ generators:
- name: fernapi/fern-python-sdk
version: 0.3.7
output:
- location: local-file-system
- path: ../../generated/python
+ location: pypi
+ url: pypi.buildwithfern.com
+ package-name: finto-fern-langfuse
config:
namespaceExport: Langfuse
allowCustomFetcher: true
- name: fernapi/fern-typescript-node-sdk
version: 0.7.1
output:
- location: local-file-system
- path: ../../generated/typescript-server
+ location: npm
+ url: npm.buildwithfern.com
+ package-name: "@finto-fern/langfuse-node"
config:
namespaceExport: Langfuse
allowCustomFetcher: true
diff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.yml
index cd79bba2ec..7f4bcf42c4 100644
--- a/generated/openapi-server/openapi.yml
+++ b/generated/openapi-server/openapi.yml
@@ -16,7 +16,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/Event'
+ $ref: '#/components/schemas/Observation'
'400':
description: ''
content:
@@ -35,6 +35,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -61,7 +67,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/Log'
+ $ref: '#/components/schemas/Observation'
'400':
description: ''
content:
@@ -80,6 +86,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -92,7 +104,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/CreateLog'
+ $ref: '#/components/schemas/CreateGenerationRequest'
patch:
operationId: generations_update
tags:
@@ -104,7 +116,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/Log'
+ $ref: '#/components/schemas/Observation'
'400':
description: ''
content:
@@ -123,6 +135,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -136,6 +154,59 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/UpdateGenerationRequest'
+ /api/public/observations/{observationId}:
+ get:
+ description: Get a specific observation
+ operationId: observations_get
+ tags:
+ - Observations
+ parameters:
+ - name: observationId
+ in: path
+ description: >-
+ The unique langfuse identifier of an observation, can be an event,
+ span or generation
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Observation'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ security: *ref_0
/api/public/scores:
post:
description: Add a score to the database
@@ -168,6 +239,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -181,6 +258,74 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CreateScoreRequest'
+ get:
+ description: Get scores
+ operationId: score_get
+ tags:
+ - Score
+ parameters:
+ - name: page
+ in: query
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ - name: limit
+ in: query
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ - name: userId
+ in: query
+ required: false
+ schema:
+ type: string
+ nullable: true
+ - name: name
+ in: query
+ required: false
+ schema:
+ type: string
+ nullable: true
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Scores'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ security: *ref_0
/api/public/spans:
post:
description: Add a span to the database
@@ -194,7 +339,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/Span'
+ $ref: '#/components/schemas/Observation'
'400':
description: ''
content:
@@ -213,6 +358,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -238,7 +389,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/Span'
+ $ref: '#/components/schemas/Observation'
'400':
description: ''
content:
@@ -257,6 +408,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -302,6 +459,12 @@ paths:
application/json:
schema:
type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
'405':
description: ''
content:
@@ -315,6 +478,57 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CreateTraceRequest'
+ /api/public/traces/{traceId}:
+ get:
+ description: Get a specific trace
+ operationId: trace_get
+ tags:
+ - Trace
+ parameters:
+ - name: traceId
+ in: path
+ description: The unique langfuse identifier of a trace
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/TraceWithDetails'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema:
+ type: string
+ security: *ref_0
components:
schemas:
CreateEventRequest:
@@ -328,7 +542,7 @@ components:
type: string
nullable: true
traceIdType:
- $ref: '#/components/schemas/TraceIdTypeEvent'
+ $ref: '#/components/schemas/TraceIdTypeEnum'
nullable: true
name:
type: string
@@ -344,7 +558,7 @@ components:
output:
nullable: true
level:
- $ref: '#/components/schemas/ObservationLevelEvent'
+ $ref: '#/components/schemas/ObservationLevel'
nullable: true
statusMessage:
type: string
@@ -352,80 +566,20 @@ components:
parentObservationId:
type: string
nullable: true
- Event:
- title: Event
+ CreateSpanRequest:
+ title: CreateSpanRequest
type: object
properties:
- id:
- type: string
- traceId:
- type: string
- type:
- type: string
- name:
- type: string
- nullable: true
- startTime:
+ endTime:
type: string
format: date-time
- metadata:
- nullable: true
- input:
- nullable: true
- output:
- nullable: true
- level:
- $ref: '#/components/schemas/ObservationLevelEvent'
- statusMessage:
- type: string
nullable: true
- parentObservationId:
- type: string
- nullable: true
- required:
- - id
- - traceId
- - type
- - startTime
- - level
- ObservationLevelEvent:
- title: ObservationLevelEvent
- type: string
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeEvent:
- title: TraceIdTypeEvent
- type: string
- enum:
- - LANGFUSE
- - EXTERNAL
- CreateLog:
- title: CreateLog
+ allOf:
+ - $ref: '#/components/schemas/CreateEventRequest'
+ CreateGenerationRequest:
+ title: CreateGenerationRequest
type: object
properties:
- id:
- type: string
- nullable: true
- traceId:
- type: string
- nullable: true
- traceIdType:
- $ref: '#/components/schemas/TraceIdTypeGenerations'
- nullable: true
- name:
- type: string
- nullable: true
- startTime:
- type: string
- format: date-time
- nullable: true
- endTime:
- type: string
- format: date-time
- nullable: true
completionStartTime:
type: string
format: date-time
@@ -440,68 +594,57 @@ components:
nullable: true
prompt:
nullable: true
- metadata:
- nullable: true
completion:
type: string
nullable: true
usage:
$ref: '#/components/schemas/LLMUsage'
nullable: true
- level:
- $ref: '#/components/schemas/ObservationLevelGeneration'
- nullable: true
- statusMessage:
- type: string
- nullable: true
- parentObservationId:
- type: string
- nullable: true
- UpdateGenerationRequest:
- title: UpdateGenerationRequest
+ allOf:
+ - $ref: '#/components/schemas/CreateSpanRequest'
+ Trace:
+ title: Trace
type: object
properties:
- generationId:
- type: string
- name:
+ id:
type: string
- nullable: true
- endTime:
+ description: The unique identifier of a trace
+ timestamp:
type: string
format: date-time
- nullable: true
- completionStartTime:
+ externalId:
type: string
- format: date-time
nullable: true
- model:
+ name:
type: string
nullable: true
- modelParameters:
- type: object
- additionalProperties:
- $ref: '#/components/schemas/MapValue'
- nullable: true
- prompt:
- nullable: true
- metadata:
- nullable: true
- completion:
+ userId:
type: string
nullable: true
- usage:
- $ref: '#/components/schemas/LLMUsage'
- nullable: true
- level:
- $ref: '#/components/schemas/ObservationLevelGeneration'
- nullable: true
- statusMessage:
- type: string
+ metadata:
nullable: true
required:
- - generationId
- Log:
- title: Log
+ - id
+ - timestamp
+ TraceWithDetails:
+ title: TraceWithDetails
+ type: object
+ properties:
+ observations:
+ type: array
+ items:
+ $ref: '#/components/schemas/Observation'
+ scores:
+ type: array
+ items:
+ $ref: '#/components/schemas/Score'
+ required:
+ - observations
+ - scores
+ allOf:
+ - $ref: '#/components/schemas/Trace'
+ Observation:
+ title: Observation
type: object
properties:
id:
@@ -546,7 +689,7 @@ components:
totalTokens:
type: integer
level:
- $ref: '#/components/schemas/ObservationLevelGeneration'
+ $ref: '#/components/schemas/ObservationLevel'
statusMessage:
type: string
nullable: true
@@ -562,68 +705,6 @@ components:
- completionTokens
- totalTokens
- level
- LLMUsage:
- title: LLMUsage
- type: object
- properties:
- promptTokens:
- type: integer
- nullable: true
- completionTokens:
- type: integer
- nullable: true
- totalTokens:
- type: integer
- nullable: true
- MapValue:
- title: MapValue
- oneOf:
- - type: string
- nullable: true
- - type: integer
- nullable: true
- - type: boolean
- nullable: true
- ObservationLevelGeneration:
- title: ObservationLevelGeneration
- type: string
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeGenerations:
- title: TraceIdTypeGenerations
- type: string
- enum:
- - LANGFUSE
- - EXTERNAL
- CreateScoreRequest:
- title: CreateScoreRequest
- type: object
- properties:
- id:
- type: string
- nullable: true
- traceId:
- type: string
- traceIdType:
- $ref: '#/components/schemas/TraceIdType'
- nullable: true
- name:
- type: string
- value:
- type: integer
- observationId:
- type: string
- nullable: true
- comment:
- type: string
- nullable: true
- required:
- - traceId
- - name
- - value
Score:
title: Score
type: object
@@ -651,91 +732,130 @@ components:
- name
- value
- timestamp
- TraceIdType:
- title: TraceIdType
+ ObservationLevel:
+ title: ObservationLevel
+ type: string
+ enum:
+ - DEBUG
+ - DEFAULT
+ - WARNING
+ - ERROR
+ MapValue:
+ title: MapValue
+ oneOf:
+ - type: string
+ nullable: true
+ - type: integer
+ nullable: true
+ - type: boolean
+ nullable: true
+ TraceIdTypeEnum:
+ title: TraceIdTypeEnum
type: string
enum:
- LANGFUSE
- EXTERNAL
- CreateSpanRequest:
- title: CreateSpanRequest
+ LLMUsage:
+ title: LLMUsage
type: object
properties:
- id:
- type: string
+ promptTokens:
+ type: integer
nullable: true
- traceId:
- type: string
+ completionTokens:
+ type: integer
nullable: true
- traceIdType:
- $ref: '#/components/schemas/TraceIdTypeSpan'
+ totalTokens:
+ type: integer
nullable: true
+ UpdateGenerationRequest:
+ title: UpdateGenerationRequest
+ type: object
+ properties:
+ generationId:
+ type: string
name:
type: string
nullable: true
- startTime:
+ endTime:
type: string
format: date-time
nullable: true
- endTime:
+ completionStartTime:
type: string
format: date-time
nullable: true
- metadata:
- nullable: true
- input:
- nullable: true
- output:
- nullable: true
- level:
- $ref: '#/components/schemas/ObservationLevelSpan'
- nullable: true
- statusMessage:
+ model:
type: string
nullable: true
- parentObservationId:
- type: string
+ modelParameters:
+ type: object
+ additionalProperties:
+ $ref: '#/components/schemas/MapValue'
nullable: true
- UpdateSpanRequest:
- title: UpdateSpanRequest
- type: object
- properties:
- spanId:
- type: string
- endTime:
- type: string
- format: date-time
+ prompt:
nullable: true
metadata:
nullable: true
- input:
+ completion:
+ type: string
nullable: true
- output:
+ usage:
+ $ref: '#/components/schemas/LLMUsage'
nullable: true
level:
- $ref: '#/components/schemas/ObservationLevelSpan'
+ $ref: '#/components/schemas/ObservationLevel'
nullable: true
statusMessage:
type: string
nullable: true
required:
- - spanId
- Span:
- title: Span
+ - generationId
+ CreateScoreRequest:
+ title: CreateScoreRequest
type: object
properties:
id:
type: string
+ nullable: true
traceId:
type: string
- type:
- type: string
+ traceIdType:
+ $ref: '#/components/schemas/TraceIdTypeEnum'
+ nullable: true
name:
type: string
+ value:
+ type: integer
+ observationId:
+ type: string
nullable: true
- startTime:
+ comment:
+ type: string
+ nullable: true
+ required:
+ - traceId
+ - name
+ - value
+ Scores:
+ title: Scores
+ type: object
+ properties:
+ data:
+ type: array
+ items:
+ $ref: '#/components/schemas/Score'
+ meta:
+ $ref: '#/components/schemas/utilsMetaResponse'
+ required:
+ - data
+ - meta
+ UpdateSpanRequest:
+ title: UpdateSpanRequest
+ type: object
+ properties:
+ spanId:
type: string
- format: date-time
endTime:
type: string
format: date-time
@@ -747,33 +867,13 @@ components:
output:
nullable: true
level:
- $ref: '#/components/schemas/ObservationLevelSpan'
- statusMessage:
- type: string
+ $ref: '#/components/schemas/ObservationLevel'
nullable: true
- parentObservationId:
+ statusMessage:
type: string
nullable: true
required:
- - id
- - traceId
- - type
- - startTime
- - level
- ObservationLevelSpan:
- title: ObservationLevelSpan
- type: string
- enum:
- - DEBUG
- - DEFAULT
- - WARNING
- - ERROR
- TraceIdTypeSpan:
- title: TraceIdTypeSpan
- type: string
- enum:
- - LANGFUSE
- - EXTERNAL
+ - spanId
CreateTraceRequest:
title: CreateTraceRequest
type: object
@@ -789,29 +889,23 @@ components:
nullable: true
metadata:
nullable: true
- Trace:
- title: Trace
+ utilsMetaResponse:
+ title: utilsMetaResponse
type: object
properties:
- id:
- type: string
- timestamp:
- type: string
- format: date-time
- externalId:
- type: string
- nullable: true
- name:
- type: string
- nullable: true
- userId:
- type: string
- nullable: true
- metadata:
- nullable: true
+ page:
+ type: integer
+ limit:
+ type: integer
+ totalItems:
+ type: integer
+ totalPages:
+ type: integer
required:
- - id
- - timestamp
+ - page
+ - limit
+ - totalItems
+ - totalPages
securitySchemes:
BasicAuth:
type: http
diff --git a/src/pages/api/public/cors.ts b/src/features/publicApi/server/cors.ts
similarity index 100%
rename from src/pages/api/public/cors.ts
rename to src/features/publicApi/server/cors.ts
diff --git a/src/pages/api/public/events.ts b/src/pages/api/public/events.ts
index ca9c83c1f6..e8a3a102fe 100644
--- a/src/pages/api/public/events.ts
+++ b/src/pages/api/public/events.ts
@@ -2,7 +2,7 @@ import { prisma } from "@/src/server/db";
import { ObservationLevel, ObservationType } from "@prisma/client";
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
-import { cors, runMiddleware } from "./cors";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
import { checkApiAccessScope } from "@/src/features/publicApi/server/apiScope";
diff --git a/src/pages/api/public/generations.ts b/src/pages/api/public/generations.ts
index 0749dfa7d5..6e27f0d6a6 100644
--- a/src/pages/api/public/generations.ts
+++ b/src/pages/api/public/generations.ts
@@ -2,7 +2,7 @@ import { prisma } from "@/src/server/db";
import { ObservationLevel, ObservationType } from "@prisma/client";
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
-import { cors, runMiddleware } from "./cors";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
import { checkApiAccessScope } from "@/src/features/publicApi/server/apiScope";
import { tokenCount } from "@/src/features/ingest/lib/usage";
diff --git a/src/pages/api/public/health.ts b/src/pages/api/public/health.ts
new file mode 100644
index 0000000000..02dc64f503
--- /dev/null
+++ b/src/pages/api/public/health.ts
@@ -0,0 +1,10 @@
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
+import { type NextApiRequest, type NextApiResponse } from "next";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ await runMiddleware(req, res, cors);
+ return res.status(200).json({ status: "OK" });
+}
diff --git a/src/pages/api/public/observations/[observationId].ts b/src/pages/api/public/observations/[observationId].ts
new file mode 100644
index 0000000000..23819b6159
--- /dev/null
+++ b/src/pages/api/public/observations/[observationId].ts
@@ -0,0 +1,73 @@
+import { type NextApiRequest, type NextApiResponse } from "next";
+import { z } from "zod";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
+import { prisma } from "@/src/server/db";
+import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
+
+const GetObservationSchema = z.object({
+ observationId: z.string(),
+});
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ await runMiddleware(req, res, cors);
+
+ if (req.method !== "GET") {
+ console.error(req.method, req.body, req.query);
+ return res.status(405).json({ message: "Method not allowed" });
+ }
+
+ // CHECK AUTH
+ const authCheck = await verifyAuthHeaderAndReturnScope(
+ req.headers.authorization
+ );
+ if (!authCheck.validKey)
+ return res.status(401).json({
+ success: false,
+ message: authCheck.error,
+ });
+ // END CHECK AUTH
+
+ try {
+ console.log("Trying to get observation:", req.body, req.query);
+
+ const { observationId } = GetObservationSchema.parse(req.query);
+
+ // CHECK ACCESS SCOPE
+ if (authCheck.scope.accessLevel !== "all") {
+ return res.status(401).json({
+ success: false,
+ message:
+ "Access denied - need to use basic auth with secret key to GET traces",
+ });
+ }
+ // END CHECK ACCESS SCOPE
+
+ const observation = await prisma.observation.findFirst({
+ where: {
+ id: observationId,
+ trace: {
+ projectId: authCheck.scope.projectId,
+ },
+ },
+ });
+ if (!observation) {
+ return res.status(404).json({
+ success: false,
+ message: "Observation not found within authorized project",
+ });
+ }
+ return res.status(200).json(observation);
+ } catch (error: unknown) {
+ console.error(error);
+ const errorMessage =
+ error instanceof Error ? error.message : "An unknown error occurred";
+ res.status(400).json({
+ success: false,
+ message: "Invalid request data",
+ error: errorMessage,
+ });
+ }
+}
diff --git a/src/pages/api/public/scores.ts b/src/pages/api/public/scores.ts
index f9bd8f7c2a..dd4170273e 100644
--- a/src/pages/api/public/scores.ts
+++ b/src/pages/api/public/scores.ts
@@ -2,11 +2,11 @@ import { prisma } from "@/src/server/db";
import { type Prisma } from "@prisma/client";
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
-import { cors, runMiddleware } from "./cors";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
import { checkApiAccessScope } from "@/src/features/publicApi/server/apiScope";
-const ScoreSchema = z.object({
+const ScoreCreateSchema = z.object({
id: z.string().nullish(),
name: z.string(),
value: z.number().int(),
@@ -16,16 +16,19 @@ const ScoreSchema = z.object({
comment: z.string().nullish(),
});
+const ScoresGetSchema = z.object({
+ page: z.coerce.number().int().positive().default(1),
+ limit: z.coerce.number().int().positive().lte(100).default(50),
+ userId: z.string().nullish(),
+ name: z.string().nullish(),
+});
+
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
await runMiddleware(req, res, cors);
- if (req.method !== "POST") {
- return res.status(405).json({ message: "Method not allowed" });
- }
-
// CHECK AUTH
const authCheck = await verifyAuthHeaderAndReturnScope(
req.headers.authorization
@@ -37,68 +40,137 @@ export default async function handler(
});
// END CHECK AUTH
- try {
- console.log("trying to create score", req.body);
+ if (req.method === "POST") {
+ try {
+ console.log("trying to create score", req.body);
- const obj = ScoreSchema.parse(req.body);
+ const obj = ScoreCreateSchema.parse(req.body);
- // If externalTraceId is provided, find the traceId
- const traceId =
- obj.traceIdType === "EXTERNAL"
- ? (
- await prisma.trace.findUniqueOrThrow({
- where: {
- projectId_externalId: {
- projectId: authCheck.scope.projectId,
- externalId: obj.traceId,
+ // If externalTraceId is provided, find the traceId
+ const traceId =
+ obj.traceIdType === "EXTERNAL"
+ ? (
+ await prisma.trace.findUniqueOrThrow({
+ where: {
+ projectId_externalId: {
+ projectId: authCheck.scope.projectId,
+ externalId: obj.traceId,
+ },
},
- },
- })
- ).id
- : obj.traceId;
+ })
+ ).id
+ : obj.traceId;
+
+ // CHECK ACCESS SCOPE
+ const accessCheck = await checkApiAccessScope(
+ authCheck.scope,
+ [
+ { type: "trace", id: traceId },
+ ...(obj.observationId
+ ? [{ type: "observation" as const, id: obj.observationId }]
+ : []),
+ ],
+ "score"
+ );
+ if (!accessCheck)
+ return res.status(403).json({
+ success: false,
+ message: "Access denied",
+ });
+ // END CHECK ACCESS SCOPE
+
+ const data: Prisma.ScoreCreateInput = {
+ id: obj.id ?? undefined,
+ timestamp: new Date(),
+ value: obj.value,
+ name: obj.name,
+ comment: obj.comment,
+ trace: { connect: { id: traceId } },
+ ...(obj.observationId && {
+ observation: { connect: { id: obj.observationId } },
+ }),
+ };
- // CHECK ACCESS SCOPE
- const accessCheck = await checkApiAccessScope(
- authCheck.scope,
- [
- { type: "trace", id: traceId },
- ...(obj.observationId
- ? [{ type: "observation" as const, id: obj.observationId }]
- : []),
- ],
- "score"
- );
- if (!accessCheck)
- return res.status(403).json({
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const newScore = await prisma.score.create({ data });
+
+ res.status(200).json(newScore);
+ } catch (error: unknown) {
+ console.error(error);
+ const errorMessage =
+ error instanceof Error ? error.message : "An unknown error occurred";
+ res.status(400).json({
success: false,
- message: "Access denied",
+ message: "Invalid request data",
+ error: errorMessage,
});
- // END CHECK ACCESS SCOPE
+ }
+ } else if (req.method === "GET") {
+ try {
+ if (authCheck.scope.accessLevel !== "all") {
+ return res.status(401).json({
+ success: false,
+ message:
+ "Access denied - need to use basic auth with secret key to GET scores",
+ });
+ }
- const data: Prisma.ScoreCreateInput = {
- id: obj.id ?? undefined,
- timestamp: new Date(),
- value: obj.value,
- name: obj.name,
- comment: obj.comment,
- trace: { connect: { id: traceId } },
- ...(obj.observationId && {
- observation: { connect: { id: obj.observationId } },
- }),
- };
+ console.log(req.query);
+ const obj = ScoresGetSchema.parse(req.query); // uses query and not body
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const newScore = await prisma.score.create({ data });
+ const [scores, totalItems] = await Promise.all([
+ prisma.score.findMany({
+ where: {
+ name: obj.name ?? undefined, // optional filter
+ trace: {
+ projectId: authCheck.scope.projectId,
+ userId: obj.userId ?? undefined, // optional filter
+ },
+ },
+ include: {
+ trace: {
+ select: {
+ userId: true,
+ },
+ },
+ },
+ skip: (obj.page - 1) * obj.limit,
+ take: obj.limit,
+ orderBy: {
+ timestamp: "desc",
+ },
+ }),
+ prisma.score.count({
+ where: {
+ name: obj.name ?? undefined, // optional filter
+ trace: {
+ projectId: authCheck.scope.projectId,
+ userId: obj.userId ?? undefined, // optional filter
+ },
+ },
+ }),
+ ]);
- res.status(200).json(newScore);
- } catch (error: unknown) {
- console.error(error);
- const errorMessage =
- error instanceof Error ? error.message : "An unknown error occurred";
- res.status(400).json({
- success: false,
- message: "Invalid request data",
- error: errorMessage,
- });
+ return res.status(200).json({
+ data: scores,
+ meta: {
+ page: obj.page,
+ limit: obj.limit,
+ totalItems,
+ totalPages: Math.ceil(totalItems / obj.limit),
+ },
+ });
+ } catch (error: unknown) {
+ console.error(error);
+ const errorMessage =
+ error instanceof Error ? error.message : "An unknown error occurred";
+ res.status(400).json({
+ success: false,
+ message: "Invalid request data",
+ error: errorMessage,
+ });
+ }
+ } else {
+ return res.status(405).json({ message: "Method not allowed" });
}
}
diff --git a/src/pages/api/public/spans.ts b/src/pages/api/public/spans.ts
index 7813158d63..8d26a69315 100644
--- a/src/pages/api/public/spans.ts
+++ b/src/pages/api/public/spans.ts
@@ -2,7 +2,7 @@ import { prisma } from "@/src/server/db";
import { ObservationLevel, ObservationType } from "@prisma/client";
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
-import { cors, runMiddleware } from "./cors";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
import { checkApiAccessScope } from "@/src/features/publicApi/server/apiScope";
diff --git a/src/pages/api/public/traces.ts b/src/pages/api/public/traces.ts
index 84f88e29cf..78cbc434ed 100644
--- a/src/pages/api/public/traces.ts
+++ b/src/pages/api/public/traces.ts
@@ -1,6 +1,6 @@
import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
-import { cors, runMiddleware } from "./cors";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
import { prisma } from "@/src/server/db";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
diff --git a/src/pages/api/public/traces/[traceId].ts b/src/pages/api/public/traces/[traceId].ts
new file mode 100644
index 0000000000..fa10ac9693
--- /dev/null
+++ b/src/pages/api/public/traces/[traceId].ts
@@ -0,0 +1,75 @@
+import { type NextApiRequest, type NextApiResponse } from "next";
+import { z } from "zod";
+import { cors, runMiddleware } from "@/src/features/publicApi/server/cors";
+import { prisma } from "@/src/server/db";
+import { verifyAuthHeaderAndReturnScope } from "@/src/features/publicApi/server/apiAuth";
+
+const GetTraceSchema = z.object({
+ traceId: z.string(),
+});
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ await runMiddleware(req, res, cors);
+
+ if (req.method !== "GET") {
+ console.error(req.method, req.body, req.query);
+ return res.status(405).json({ message: "Method not allowed" });
+ }
+
+ // CHECK AUTH
+ const authCheck = await verifyAuthHeaderAndReturnScope(
+ req.headers.authorization
+ );
+ if (!authCheck.validKey)
+ return res.status(401).json({
+ success: false,
+ message: authCheck.error,
+ });
+ // END CHECK AUTH
+
+ try {
+ console.log("Trying to get trace:", req.body, req.query);
+
+ const { traceId } = GetTraceSchema.parse(req.query);
+
+ // CHECK ACCESS SCOPE
+ if (authCheck.scope.accessLevel !== "all") {
+ return res.status(401).json({
+ success: false,
+ message:
+ "Access denied - need to use basic auth with secret key to GET traces",
+ });
+ }
+ // END CHECK ACCESS SCOPE
+
+ const trace = await prisma.trace.findFirst({
+ where: {
+ id: traceId,
+ projectId: authCheck.scope.projectId,
+ },
+ include: {
+ observations: true,
+ scores: true,
+ },
+ });
+ if (!trace) {
+ return res.status(404).json({
+ success: false,
+ message: "Trace not found within authorized project",
+ });
+ }
+ return res.status(200).json(trace);
+ } catch (error: unknown) {
+ console.error(error);
+ const errorMessage =
+ error instanceof Error ? error.message : "An unknown error occurred";
+ res.status(400).json({
+ success: false,
+ message: "Invalid request data",
+ error: errorMessage,
+ });
+ }
+}