From f2494f0f496b34fb349937066222caad619b0478 Mon Sep 17 00:00:00 2001 From: langfuse-bot Date: Thu, 26 Feb 2026 21:13:52 +0000 Subject: [PATCH] feat(api): update API spec from langfuse/langfuse a93f65a --- langfuse/api/__init__.py | 3 + langfuse/api/commons/__init__.py | 3 + langfuse/api/commons/types/__init__.py | 3 + langfuse/api/commons/types/observation_v2.py | 235 ++++++++++++++++++ .../types/observations_v2response.py | 3 +- 5 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 langfuse/api/commons/types/observation_v2.py diff --git a/langfuse/api/__init__.py b/langfuse/api/__init__.py index eddf81af0..8b70c0807 100644 --- a/langfuse/api/__init__.py +++ b/langfuse/api/__init__.py @@ -97,6 +97,7 @@ NumericScoreV1, Observation, ObservationLevel, + ObservationV2, ObservationsView, PricingTier, PricingTierCondition, @@ -423,6 +424,7 @@ "ObservationBody": ".ingestion", "ObservationLevel": ".commons", "ObservationType": ".ingestion", + "ObservationV2": ".commons", "Observations": ".observations", "ObservationsV2Meta": ".observations_v2", "ObservationsV2Response": ".observations_v2", @@ -714,6 +716,7 @@ def __dir__(): "ObservationBody", "ObservationLevel", "ObservationType", + "ObservationV2", "Observations", "ObservationsV2Meta", "ObservationsV2Response", diff --git a/langfuse/api/commons/__init__.py b/langfuse/api/commons/__init__.py index 43e4649d2..af79e3e25 100644 --- a/langfuse/api/commons/__init__.py +++ b/langfuse/api/commons/__init__.py @@ -32,6 +32,7 @@ NumericScoreV1, Observation, ObservationLevel, + ObservationV2, ObservationsView, PricingTier, PricingTierCondition, @@ -94,6 +95,7 @@ "NumericScoreV1": ".types", "Observation": ".types", "ObservationLevel": ".types", + "ObservationV2": ".types", "ObservationsView": ".types", "PricingTier": ".types", "PricingTierCondition": ".types", @@ -179,6 +181,7 @@ def __dir__(): "NumericScoreV1", "Observation", "ObservationLevel", + "ObservationV2", "ObservationsView", "PricingTier", "PricingTierCondition", diff --git a/langfuse/api/commons/types/__init__.py b/langfuse/api/commons/types/__init__.py index 97fc36d1d..b7834caf3 100644 --- a/langfuse/api/commons/types/__init__.py +++ b/langfuse/api/commons/types/__init__.py @@ -31,6 +31,7 @@ from .numeric_score_v1 import NumericScoreV1 from .observation import Observation from .observation_level import ObservationLevel + from .observation_v2 import ObservationV2 from .observations_view import ObservationsView from .pricing_tier import PricingTier from .pricing_tier_condition import PricingTierCondition @@ -80,6 +81,7 @@ "NumericScoreV1": ".numeric_score_v1", "Observation": ".observation", "ObservationLevel": ".observation_level", + "ObservationV2": ".observation_v2", "ObservationsView": ".observations_view", "PricingTier": ".pricing_tier", "PricingTierCondition": ".pricing_tier_condition", @@ -160,6 +162,7 @@ def __dir__(): "NumericScoreV1", "Observation", "ObservationLevel", + "ObservationV2", "ObservationsView", "PricingTier", "PricingTierCondition", diff --git a/langfuse/api/commons/types/observation_v2.py b/langfuse/api/commons/types/observation_v2.py new file mode 100644 index 000000000..149dfb422 --- /dev/null +++ b/langfuse/api/commons/types/observation_v2.py @@ -0,0 +1,235 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +import pydantic +import typing_extensions +from ...core.pydantic_utilities import UniversalBaseModel +from ...core.serialization import FieldMetadata +from .observation_level import ObservationLevel + + +class ObservationV2(UniversalBaseModel): + """ + An observation from the v2 API with field-group-based selection. + Core fields are always present. Other fields are included only when their field group is requested. + """ + + id: str = pydantic.Field() + """ + The unique identifier of the observation + """ + + trace_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="traceId") + ] = pydantic.Field(default=None) + """ + The trace ID associated with the observation + """ + + start_time: typing_extensions.Annotated[ + dt.datetime, FieldMetadata(alias="startTime") + ] = pydantic.Field() + """ + The start time of the observation + """ + + end_time: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="endTime") + ] = pydantic.Field(default=None) + """ + The end time of the observation + """ + + project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")] = ( + pydantic.Field() + ) + """ + The project ID this observation belongs to + """ + + parent_observation_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="parentObservationId") + ] = pydantic.Field(default=None) + """ + The parent observation ID + """ + + type: str = pydantic.Field() + """ + The type of the observation (e.g. GENERATION, SPAN, EVENT) + """ + + name: typing.Optional[str] = pydantic.Field(default=None) + """ + The name of the observation + """ + + level: typing.Optional[ObservationLevel] = pydantic.Field(default=None) + """ + The level of the observation + """ + + status_message: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="statusMessage") + ] = pydantic.Field(default=None) + """ + The status message of the observation + """ + + version: typing.Optional[str] = pydantic.Field(default=None) + """ + The version of the observation + """ + + environment: typing.Optional[str] = pydantic.Field(default=None) + """ + The environment from which this observation originated + """ + + bookmarked: typing.Optional[bool] = pydantic.Field(default=None) + """ + Whether the observation is bookmarked + """ + + public: typing.Optional[bool] = pydantic.Field(default=None) + """ + Whether the observation is public + """ + + user_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="userId") + ] = pydantic.Field(default=None) + """ + The user ID associated with the observation + """ + + session_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="sessionId") + ] = pydantic.Field(default=None) + """ + The session ID associated with the observation + """ + + completion_start_time: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="completionStartTime") + ] = pydantic.Field(default=None) + """ + The completion start time of the observation + """ + + created_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="createdAt") + ] = pydantic.Field(default=None) + """ + The creation timestamp of the observation + """ + + updated_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="updatedAt") + ] = pydantic.Field(default=None) + """ + The last update timestamp of the observation + """ + + input: typing.Optional[typing.Any] = pydantic.Field(default=None) + """ + The input data of the observation + """ + + output: typing.Optional[typing.Any] = pydantic.Field(default=None) + """ + The output data of the observation + """ + + metadata: typing.Optional[typing.Any] = pydantic.Field(default=None) + """ + Additional metadata of the observation + """ + + provided_model_name: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="providedModelName") + ] = pydantic.Field(default=None) + """ + The model name as provided by the user + """ + + internal_model_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="internalModelId") + ] = pydantic.Field(default=None) + """ + The internal model ID matched by Langfuse + """ + + model_parameters: typing_extensions.Annotated[ + typing.Optional[typing.Any], FieldMetadata(alias="modelParameters") + ] = pydantic.Field(default=None) + """ + The parameters of the model used for the observation + """ + + usage_details: typing_extensions.Annotated[ + typing.Optional[typing.Dict[str, int]], FieldMetadata(alias="usageDetails") + ] = pydantic.Field(default=None) + """ + The usage details of the observation. Key is the usage metric name, value is the number of units consumed. + """ + + cost_details: typing_extensions.Annotated[ + typing.Optional[typing.Dict[str, float]], FieldMetadata(alias="costDetails") + ] = pydantic.Field(default=None) + """ + The cost details of the observation. Key is the cost metric name, value is the cost in USD. + """ + + total_cost: typing_extensions.Annotated[ + typing.Optional[float], FieldMetadata(alias="totalCost") + ] = pydantic.Field(default=None) + """ + The total cost of the observation in USD + """ + + prompt_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="promptId") + ] = pydantic.Field(default=None) + """ + The prompt ID associated with the observation + """ + + prompt_name: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="promptName") + ] = pydantic.Field(default=None) + """ + The prompt name associated with the observation + """ + + prompt_version: typing_extensions.Annotated[ + typing.Optional[int], FieldMetadata(alias="promptVersion") + ] = pydantic.Field(default=None) + """ + The prompt version associated with the observation + """ + + latency: typing.Optional[float] = pydantic.Field(default=None) + """ + The latency in seconds + """ + + time_to_first_token: typing_extensions.Annotated[ + typing.Optional[float], FieldMetadata(alias="timeToFirstToken") + ] = pydantic.Field(default=None) + """ + The time to first token in seconds + """ + + model_id: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="modelId") + ] = pydantic.Field(default=None) + """ + The matched model ID + """ + + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) diff --git a/langfuse/api/observations_v2/types/observations_v2response.py b/langfuse/api/observations_v2/types/observations_v2response.py index e833e1918..0ee1fb8bd 100644 --- a/langfuse/api/observations_v2/types/observations_v2response.py +++ b/langfuse/api/observations_v2/types/observations_v2response.py @@ -3,6 +3,7 @@ import typing import pydantic +from ...commons.types.observation_v2 import ObservationV2 from ...core.pydantic_utilities import UniversalBaseModel from .observations_v2meta import ObservationsV2Meta @@ -15,7 +16,7 @@ class ObservationsV2Response(UniversalBaseModel): Use the `cursor` in `meta` to retrieve the next page of results. """ - data: typing.List[typing.Dict[str, typing.Any]] = pydantic.Field() + data: typing.List[ObservationV2] = pydantic.Field() """ Array of observation objects. Fields included depend on the `fields` parameter in the request. """