🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
Extend public API: GET (#59)
Marc Klingene85fc41855b2
diff --git a/fern/fern.config.json b/fern/fern.config.jsonindex 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 filediff --git a/fern/server/definition/api.yml b/fern/server/definition/api.ymlindex 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.NotFoundErrorheaders: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.ymlindex 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: 403type: string+ NotFoundError:+ status-code: 404+ type: stringMethodNotAllowedError:status-code: 405type: stringdiff --git a/fern/server/definition/event.yml b/fern/server/definition/event.ymlindex 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.ymlservice:auth: truebase-path: /api/public@@ -8,43 +9,5 @@ service:docs: Add an event to the databasemethod: POSTpath: /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.Observationdiff --git a/fern/server/definition/generations.yml b/fern/server/definition/generations.ymlindex 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.ymlservice:auth: truebase-path: /api/public@@ -7,34 +8,15 @@ service:log:method: POSTpath: /generations- request: CreateLog- response: Log+ request: commons.CreateGenerationRequest+ response: commons.Observationupdate:method: PATCHpath: /generationsrequest: UpdateGenerationRequest- response: Log+ response: commons.Observationtypes:- 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- - EXTERNALdiff --git a/fern/server/definition/observations.yml b/fern/server/definition/observations.ymlnew file mode 100644index 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.Observationdiff --git a/fern/server/definition/score.yml b/fern/server/definition/score.ymlindex 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.ymlservice:auth: truebase-path: /api/public@@ -9,28 +11,30 @@ service:method: POSTpath: /scoresrequest: 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: Scorestypes:CreateScoreRequest:properties:id: optional<string>traceId: string- traceIdType: optional<TraceIdType>+ traceIdType: optional<commons.TraceIdTypeEnum>name: stringvalue: integerobservationId: 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.MetaResponsediff --git a/fern/server/definition/span.yml b/fern/server/definition/span.ymlindex 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.ymlservice:auth: truebase-path: /api/public@@ -8,31 +9,16 @@ service:docs: Add a span to the databasemethod: POSTpath: /spans- request: CreateSpanRequest- response: Span+ request: commons.CreateSpanRequest+ response: commons.Observationupdate:docs: Update a span to the databasemethod: PATCHpath: /spansrequest: UpdateSpanRequest- response: Span+ response: commons.Observationtypes:- 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- - EXTERNALdiff --git a/fern/server/definition/trace.yml b/fern/server/definition/trace.ymlindex 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.ymlservice:auth: truebase-path: /api/public@@ -9,7 +10,16 @@ service:method: POSTpath: /tracesrequest: 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.TraceWithDetailstypes: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.ymlnew file mode 100644index 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: integerdiff --git a/fern/server/generators.yml b/fern/server/generators.ymlindex c0c339356c..5ae76e188c 100644--- a/fern/server/generators.yml+++ b/fern/server/generators.yml@@ -2,45 +2,47 @@ default-group: localgroups:local:generators:- - name: fernapi/fern-typescript-node-sdk- version: 0.7.1+ - name: fernapi/fern-openapi+ version: 0.0.28output:- location: npm- url: npm.buildwithfern.com- package-name: "@finto-fern/langfuse-node"+ location: local-file-system+ path: ../../generated/openapi-serverconfig:namespaceExport: LangfuseallowCustomFetcher: true- name: fernapi/fern-python-sdkversion: 0.3.7output:- location: pypi- url: pypi.buildwithfern.com- package-name: finto-fern-langfuse+ location: local-file-system+ path: ../../generated/pythonconfig:namespaceExport: LangfuseallowCustomFetcher: true- - name: fernapi/fern-openapi- version: 0.0.28+ - name: fernapi/fern-typescript-node-sdk+ version: 0.7.1output:location: local-file-system- path: ../../generated/openapi-server+ path: ../../generated/typescript-serverconfig:namespaceExport: LangfuseallowCustomFetcher: true+ published:+ generators:- name: fernapi/fern-python-sdkversion: 0.3.7output:- location: local-file-system- path: ../../generated/python+ location: pypi+ url: pypi.buildwithfern.com+ package-name: finto-fern-langfuseconfig:namespaceExport: LangfuseallowCustomFetcher: true- name: fernapi/fern-typescript-node-sdkversion: 0.7.1output:- location: local-file-system- path: ../../generated/typescript-server+ location: npm+ url: npm.buildwithfern.com+ package-name: "@finto-fern/langfuse-node"config:namespaceExport: LangfuseallowCustomFetcher: truediff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.ymlindex 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_updatetags:@@ -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_0components:schemas:CreateEventRequest:@@ -328,7 +542,7 @@ components:type: stringnullable: truetraceIdType:- $ref: '#/components/schemas/TraceIdTypeEvent'+ $ref: '#/components/schemas/TraceIdTypeEnum'nullable: truename:type: string@@ -344,7 +558,7 @@ components:output:nullable: truelevel:- $ref: '#/components/schemas/ObservationLevelEvent'+ $ref: '#/components/schemas/ObservationLevel'nullable: truestatusMessage:type: string@@ -352,80 +566,20 @@ components:parentObservationId:type: stringnullable: true- Event:- title: Event+ CreateSpanRequest:+ title: CreateSpanRequesttype: objectproperties:- id:- type: string- traceId:- type: string- type:- type: string- name:- type: string- nullable: true- startTime:+ endTime:type: stringformat: date-time- metadata:- nullable: true- input:- nullable: true- output:- nullable: true- level:- $ref: '#/components/schemas/ObservationLevelEvent'- statusMessage:- type: stringnullable: 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: CreateGenerationRequesttype: objectproperties:- 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: truecompletionStartTime:type: stringformat: date-time@@ -440,68 +594,57 @@ components:nullable: trueprompt:nullable: true- metadata:- nullable: truecompletion:type: stringnullable: trueusage:$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: Tracetype: objectproperties:- generationId:- type: string- name:+ id:type: string- nullable: true- endTime:+ description: The unique identifier of a trace+ timestamp:type: stringformat: date-time- nullable: true- completionStartTime:+ externalId:type: string- format: date-timenullable: true- model:+ name:type: stringnullable: true- modelParameters:- type: object- additionalProperties:- $ref: '#/components/schemas/MapValue'- nullable: true- prompt:- nullable: true- metadata:- nullable: true- completion:+ userId:type: stringnullable: true- usage:- $ref: '#/components/schemas/LLMUsage'- nullable: true- level:- $ref: '#/components/schemas/ObservationLevelGeneration'- nullable: true- statusMessage:- type: string+ metadata:nullable: truerequired:- - 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: Observationtype: objectproperties:id:@@ -546,7 +689,7 @@ components:totalTokens:type: integerlevel:- $ref: '#/components/schemas/ObservationLevelGeneration'+ $ref: '#/components/schemas/ObservationLevel'statusMessage:type: stringnullable: 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- - valueScore:title: Scoretype: 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: TraceIdTypeEnumtype: stringenum:- LANGFUSE- EXTERNAL- CreateSpanRequest:- title: CreateSpanRequest+ LLMUsage:+ title: LLMUsagetype: objectproperties:- id:- type: string+ promptTokens:+ type: integernullable: true- traceId:- type: string+ completionTokens:+ type: integernullable: true- traceIdType:- $ref: '#/components/schemas/TraceIdTypeSpan'+ totalTokens:+ type: integernullable: true+ UpdateGenerationRequest:+ title: UpdateGenerationRequest+ type: object+ properties:+ generationId:+ type: stringname:type: stringnullable: true- startTime:+ endTime:type: stringformat: date-timenullable: true- endTime:+ completionStartTime:type: stringformat: date-timenullable: true- metadata:- nullable: true- input:- nullable: true- output:- nullable: true- level:- $ref: '#/components/schemas/ObservationLevelSpan'- nullable: true- statusMessage:+ model:type: stringnullable: 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: truemetadata:nullable: true- input:+ completion:+ type: stringnullable: true- output:+ usage:+ $ref: '#/components/schemas/LLMUsage'nullable: truelevel:- $ref: '#/components/schemas/ObservationLevelSpan'+ $ref: '#/components/schemas/ObservationLevel'nullable: truestatusMessage:type: stringnullable: truerequired:- - spanId- Span:- title: Span+ - generationId+ CreateScoreRequest:+ title: CreateScoreRequesttype: objectproperties:id:type: string+ nullable: truetraceId:type: string- type:- type: string+ traceIdType:+ $ref: '#/components/schemas/TraceIdTypeEnum'+ nullable: truename:type: string+ value:+ type: integer+ observationId:+ type: stringnullable: 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-timeendTime:type: stringformat: date-time@@ -747,33 +867,13 @@ components:output:nullable: truelevel:- $ref: '#/components/schemas/ObservationLevelSpan'- statusMessage:- type: string+ $ref: '#/components/schemas/ObservationLevel'nullable: true- parentObservationId:+ statusMessage:type: stringnullable: truerequired:- - id- - traceId- - type- - startTime- - level- ObservationLevelSpan:- title: ObservationLevelSpan- type: string- enum:- - DEBUG- - DEFAULT- - WARNING- - ERROR- TraceIdTypeSpan:- title: TraceIdTypeSpan- type: string- enum:- - LANGFUSE- - EXTERNAL+ - spanIdCreateTraceRequest:title: CreateTraceRequesttype: object@@ -789,29 +889,23 @@ components:nullable: truemetadata:nullable: true- Trace:- title: Trace+ utilsMetaResponse:+ title: utilsMetaResponsetype: objectproperties:- 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: integerrequired:- - id- - timestamp+ - page+ - limit+ - totalItems+ - totalPagessecuritySchemes:BasicAuth:type: httpdiff --git a/src/pages/api/public/cors.ts b/src/features/publicApi/server/cors.tssimilarity index 100%rename from src/pages/api/public/cors.tsrename to src/features/publicApi/server/cors.tsdiff --git a/src/pages/api/public/events.ts b/src/pages/api/public/events.tsindex 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.tsindex 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.tsnew file mode 100644index 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].tsnew file mode 100644index 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.tsindex 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 AUTHconst 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.tsindex 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.tsindex 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].tsnew file mode 100644index 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,+ });+ }+}