diff --git a/langfuse/api/unstable/__init__.py b/langfuse/api/unstable/__init__.py index 4cc87ca60..73535f376 100644 --- a/langfuse/api/unstable/__init__.py +++ b/langfuse/api/unstable/__init__.py @@ -20,7 +20,12 @@ TooManyRequestsError, UnauthorizedError, ) - from . import dashboard_widgets, dashboards, errors, topics + from . import billable_units, dashboard_widgets, dashboards, errors, topics + from .billable_units import ( + BillableUnitsGranularity, + BillableUnitsResponse, + BillableUnitsRow, + ) from .dashboard_widgets import ( CreateDashboardWidgetRequest, DashboardWidget, @@ -86,6 +91,9 @@ _dynamic_imports: typing.Dict[str, str] = { "AccessDeniedError": ".errors", "BadRequestError": ".errors", + "BillableUnitsGranularity": ".billable_units", + "BillableUnitsResponse": ".billable_units", + "BillableUnitsRow": ".billable_units", "ConflictError": ".errors", "CreateDashboardPlacementRequest": ".dashboards", "CreateDashboardPlacementRequest_Preset": ".dashboards", @@ -152,6 +160,7 @@ "UpdateDashboardRequest": ".dashboards", "UpdateDashboardWidgetRequest": ".dashboard_widgets", "WidgetPlacement": ".dashboards", + "billable_units": ".billable_units", "dashboard_widgets": ".dashboard_widgets", "dashboards": ".dashboards", "errors": ".errors", @@ -189,6 +198,9 @@ def __dir__(): __all__ = [ "AccessDeniedError", "BadRequestError", + "BillableUnitsGranularity", + "BillableUnitsResponse", + "BillableUnitsRow", "ConflictError", "CreateDashboardPlacementRequest", "CreateDashboardPlacementRequest_Preset", @@ -255,6 +267,7 @@ def __dir__(): "UpdateDashboardRequest", "UpdateDashboardWidgetRequest", "WidgetPlacement", + "billable_units", "dashboard_widgets", "dashboards", "errors", diff --git a/langfuse/api/unstable/billable_units/__init__.py b/langfuse/api/unstable/billable_units/__init__.py new file mode 100644 index 000000000..9b93a96ce --- /dev/null +++ b/langfuse/api/unstable/billable_units/__init__.py @@ -0,0 +1,44 @@ +# This file was auto-generated by Fern from our API Definition. + +# isort: skip_file + +import typing +from importlib import import_module + +if typing.TYPE_CHECKING: + from .types import BillableUnitsGranularity, BillableUnitsResponse, BillableUnitsRow +_dynamic_imports: typing.Dict[str, str] = { + "BillableUnitsGranularity": ".types", + "BillableUnitsResponse": ".types", + "BillableUnitsRow": ".types", +} + + +def __getattr__(attr_name: str) -> typing.Any: + module_name = _dynamic_imports.get(attr_name) + if module_name is None: + raise AttributeError( + f"No {attr_name} found in _dynamic_imports for module name -> {__name__}" + ) + try: + module = import_module(module_name, __package__) + if module_name == f".{attr_name}": + return module + else: + return getattr(module, attr_name) + except ImportError as e: + raise ImportError( + f"Failed to import {attr_name} from {module_name}: {e}" + ) from e + except AttributeError as e: + raise AttributeError( + f"Failed to get {attr_name} from {module_name}: {e}" + ) from e + + +def __dir__(): + lazy_attrs = list(_dynamic_imports.keys()) + return sorted(lazy_attrs) + + +__all__ = ["BillableUnitsGranularity", "BillableUnitsResponse", "BillableUnitsRow"] diff --git a/langfuse/api/unstable/billable_units/client.py b/langfuse/api/unstable/billable_units/client.py new file mode 100644 index 000000000..00c2998bc --- /dev/null +++ b/langfuse/api/unstable/billable_units/client.py @@ -0,0 +1,201 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper +from ...core.request_options import RequestOptions +from .raw_client import AsyncRawBillableUnitsClient, RawBillableUnitsClient +from .types.billable_units_granularity import BillableUnitsGranularity +from .types.billable_units_response import BillableUnitsResponse + + +class BillableUnitsClient: + def __init__(self, *, client_wrapper: SyncClientWrapper): + self._raw_client = RawBillableUnitsClient(client_wrapper=client_wrapper) + + @property + def with_raw_response(self) -> RawBillableUnitsClient: + """ + Retrieves a raw implementation of this client that returns raw responses. + + Returns + ------- + RawBillableUnitsClient + """ + return self._raw_client + + def get( + self, + *, + from_timestamp: dt.datetime, + to_timestamp: dt.datetime, + granularity: typing.Optional[BillableUnitsGranularity] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> BillableUnitsResponse: + """ + Unstable: the shape may change without notice. + + Billable units of the organization's projects, per UTC time bucket and + project. These are the numbers of the organization's Usage settings + tab. Requires an organization-scoped API key. + + Units are counted by ingestion time in `[fromTimestamp, toTimestamp)` + as approximate distinct units per bucket (about 0.3% error on large + counts, small counts are exact). A unit counts once in every bucket it + appears in, so the counts stay close to, but are not exactly, what is + billed. Deployments still in the v3 `legacy` write mode count the rows + of the traces, observations and scores tables instead. + + Buckets start at UTC hour, day, Monday or month boundaries. The first + and last bucket cover only the part inside the range, and a + `toTimestamp` in the future is cut off at now. Buckets and projects + without usage are left out, and so are deleted projects. + + Parameters + ---------- + from_timestamp : dt.datetime + Start of the range (inclusive), ISO 8601 with a time zone. + + to_timestamp : dt.datetime + End of the range (exclusive), ISO 8601 with a time zone. At most 31 days after `fromTimestamp` for `hour` granularity, 366 days otherwise. + + granularity : typing.Optional[BillableUnitsGranularity] + Bucket size. Defaults to `day`. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + BillableUnitsResponse + + Examples + -------- + import datetime + + from langfuse import LangfuseAPI + + client = LangfuseAPI( + x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", + x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", + x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", + username="YOUR_USERNAME", + password="YOUR_PASSWORD", + base_url="https://yourhost.com/path/to/api", + ) + client.unstable.billable_units.get( + from_timestamp=datetime.datetime.fromisoformat( + "2024-01-15 09:30:00+00:00", + ), + to_timestamp=datetime.datetime.fromisoformat( + "2024-01-15 09:30:00+00:00", + ), + ) + """ + _response = self._raw_client.get( + from_timestamp=from_timestamp, + to_timestamp=to_timestamp, + granularity=granularity, + request_options=request_options, + ) + return _response.data + + +class AsyncBillableUnitsClient: + def __init__(self, *, client_wrapper: AsyncClientWrapper): + self._raw_client = AsyncRawBillableUnitsClient(client_wrapper=client_wrapper) + + @property + def with_raw_response(self) -> AsyncRawBillableUnitsClient: + """ + Retrieves a raw implementation of this client that returns raw responses. + + Returns + ------- + AsyncRawBillableUnitsClient + """ + return self._raw_client + + async def get( + self, + *, + from_timestamp: dt.datetime, + to_timestamp: dt.datetime, + granularity: typing.Optional[BillableUnitsGranularity] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> BillableUnitsResponse: + """ + Unstable: the shape may change without notice. + + Billable units of the organization's projects, per UTC time bucket and + project. These are the numbers of the organization's Usage settings + tab. Requires an organization-scoped API key. + + Units are counted by ingestion time in `[fromTimestamp, toTimestamp)` + as approximate distinct units per bucket (about 0.3% error on large + counts, small counts are exact). A unit counts once in every bucket it + appears in, so the counts stay close to, but are not exactly, what is + billed. Deployments still in the v3 `legacy` write mode count the rows + of the traces, observations and scores tables instead. + + Buckets start at UTC hour, day, Monday or month boundaries. The first + and last bucket cover only the part inside the range, and a + `toTimestamp` in the future is cut off at now. Buckets and projects + without usage are left out, and so are deleted projects. + + Parameters + ---------- + from_timestamp : dt.datetime + Start of the range (inclusive), ISO 8601 with a time zone. + + to_timestamp : dt.datetime + End of the range (exclusive), ISO 8601 with a time zone. At most 31 days after `fromTimestamp` for `hour` granularity, 366 days otherwise. + + granularity : typing.Optional[BillableUnitsGranularity] + Bucket size. Defaults to `day`. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + BillableUnitsResponse + + Examples + -------- + import asyncio + import datetime + + from langfuse import AsyncLangfuseAPI + + client = AsyncLangfuseAPI( + x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", + x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", + x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", + username="YOUR_USERNAME", + password="YOUR_PASSWORD", + base_url="https://yourhost.com/path/to/api", + ) + + + async def main() -> None: + await client.unstable.billable_units.get( + from_timestamp=datetime.datetime.fromisoformat( + "2024-01-15 09:30:00+00:00", + ), + to_timestamp=datetime.datetime.fromisoformat( + "2024-01-15 09:30:00+00:00", + ), + ) + + + asyncio.run(main()) + """ + _response = await self._raw_client.get( + from_timestamp=from_timestamp, + to_timestamp=to_timestamp, + granularity=granularity, + request_options=request_options, + ) + return _response.data diff --git a/langfuse/api/unstable/billable_units/raw_client.py b/langfuse/api/unstable/billable_units/raw_client.py new file mode 100644 index 000000000..1235bb16f --- /dev/null +++ b/langfuse/api/unstable/billable_units/raw_client.py @@ -0,0 +1,446 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing +from json.decoder import JSONDecodeError + +from ...commons.errors.access_denied_error import ( + AccessDeniedError as commons_errors_access_denied_error_AccessDeniedError, +) +from ...commons.errors.error import Error +from ...commons.errors.method_not_allowed_error import ( + MethodNotAllowedError as commons_errors_method_not_allowed_error_MethodNotAllowedError, +) +from ...commons.errors.not_found_error import NotFoundError +from ...commons.errors.unauthorized_error import ( + UnauthorizedError as commons_errors_unauthorized_error_UnauthorizedError, +) +from ...core.api_error import ApiError +from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper +from ...core.datetime_utils import serialize_datetime +from ...core.http_response import AsyncHttpResponse, HttpResponse +from ...core.pydantic_utilities import parse_obj_as +from ...core.request_options import RequestOptions +from ..errors.errors.access_denied_error import ( + AccessDeniedError as unstable_errors_errors_access_denied_error_AccessDeniedError, +) +from ..errors.errors.bad_request_error import BadRequestError +from ..errors.errors.internal_server_error import InternalServerError +from ..errors.errors.method_not_allowed_error import ( + MethodNotAllowedError as unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError, +) +from ..errors.errors.too_many_requests_error import TooManyRequestsError +from ..errors.errors.unauthorized_error import ( + UnauthorizedError as unstable_errors_errors_unauthorized_error_UnauthorizedError, +) +from ..errors.types.public_api_error import PublicApiError +from .types.billable_units_granularity import BillableUnitsGranularity +from .types.billable_units_response import BillableUnitsResponse + + +class RawBillableUnitsClient: + def __init__(self, *, client_wrapper: SyncClientWrapper): + self._client_wrapper = client_wrapper + + def get( + self, + *, + from_timestamp: dt.datetime, + to_timestamp: dt.datetime, + granularity: typing.Optional[BillableUnitsGranularity] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> HttpResponse[BillableUnitsResponse]: + """ + Unstable: the shape may change without notice. + + Billable units of the organization's projects, per UTC time bucket and + project. These are the numbers of the organization's Usage settings + tab. Requires an organization-scoped API key. + + Units are counted by ingestion time in `[fromTimestamp, toTimestamp)` + as approximate distinct units per bucket (about 0.3% error on large + counts, small counts are exact). A unit counts once in every bucket it + appears in, so the counts stay close to, but are not exactly, what is + billed. Deployments still in the v3 `legacy` write mode count the rows + of the traces, observations and scores tables instead. + + Buckets start at UTC hour, day, Monday or month boundaries. The first + and last bucket cover only the part inside the range, and a + `toTimestamp` in the future is cut off at now. Buckets and projects + without usage are left out, and so are deleted projects. + + Parameters + ---------- + from_timestamp : dt.datetime + Start of the range (inclusive), ISO 8601 with a time zone. + + to_timestamp : dt.datetime + End of the range (exclusive), ISO 8601 with a time zone. At most 31 days after `fromTimestamp` for `hour` granularity, 366 days otherwise. + + granularity : typing.Optional[BillableUnitsGranularity] + Bucket size. Defaults to `day`. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + HttpResponse[BillableUnitsResponse] + """ + _response = self._client_wrapper.httpx_client.request( + "api/public/unstable/organizations/billable-units", + method="GET", + params={ + "fromTimestamp": serialize_datetime(from_timestamp), + "toTimestamp": serialize_datetime(to_timestamp), + "granularity": granularity, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + BillableUnitsResponse, + parse_obj_as( + type_=BillableUnitsResponse, # type: ignore + object_=_response.json(), + ), + ) + return HttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 401: + raise unstable_errors_errors_unauthorized_error_UnauthorizedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 403: + raise unstable_errors_errors_access_denied_error_AccessDeniedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 405: + raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 400: + raise Error( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 401: + raise commons_errors_unauthorized_error_UnauthorizedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 403: + raise commons_errors_access_denied_error_AccessDeniedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 405: + raise commons_errors_method_not_allowed_error_MethodNotAllowedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 404: + raise NotFoundError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, + headers=dict(_response.headers), + body=_response.text, + ) + raise ApiError( + status_code=_response.status_code, + headers=dict(_response.headers), + body=_response_json, + ) + + +class AsyncRawBillableUnitsClient: + def __init__(self, *, client_wrapper: AsyncClientWrapper): + self._client_wrapper = client_wrapper + + async def get( + self, + *, + from_timestamp: dt.datetime, + to_timestamp: dt.datetime, + granularity: typing.Optional[BillableUnitsGranularity] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> AsyncHttpResponse[BillableUnitsResponse]: + """ + Unstable: the shape may change without notice. + + Billable units of the organization's projects, per UTC time bucket and + project. These are the numbers of the organization's Usage settings + tab. Requires an organization-scoped API key. + + Units are counted by ingestion time in `[fromTimestamp, toTimestamp)` + as approximate distinct units per bucket (about 0.3% error on large + counts, small counts are exact). A unit counts once in every bucket it + appears in, so the counts stay close to, but are not exactly, what is + billed. Deployments still in the v3 `legacy` write mode count the rows + of the traces, observations and scores tables instead. + + Buckets start at UTC hour, day, Monday or month boundaries. The first + and last bucket cover only the part inside the range, and a + `toTimestamp` in the future is cut off at now. Buckets and projects + without usage are left out, and so are deleted projects. + + Parameters + ---------- + from_timestamp : dt.datetime + Start of the range (inclusive), ISO 8601 with a time zone. + + to_timestamp : dt.datetime + End of the range (exclusive), ISO 8601 with a time zone. At most 31 days after `fromTimestamp` for `hour` granularity, 366 days otherwise. + + granularity : typing.Optional[BillableUnitsGranularity] + Bucket size. Defaults to `day`. + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + AsyncHttpResponse[BillableUnitsResponse] + """ + _response = await self._client_wrapper.httpx_client.request( + "api/public/unstable/organizations/billable-units", + method="GET", + params={ + "fromTimestamp": serialize_datetime(from_timestamp), + "toTimestamp": serialize_datetime(to_timestamp), + "granularity": granularity, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + _data = typing.cast( + BillableUnitsResponse, + parse_obj_as( + type_=BillableUnitsResponse, # type: ignore + object_=_response.json(), + ), + ) + return AsyncHttpResponse(response=_response, data=_data) + if _response.status_code == 400: + raise BadRequestError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 401: + raise unstable_errors_errors_unauthorized_error_UnauthorizedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 403: + raise unstable_errors_errors_access_denied_error_AccessDeniedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 405: + raise unstable_errors_errors_method_not_allowed_error_MethodNotAllowedError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 500: + raise InternalServerError( + headers=dict(_response.headers), + body=typing.cast( + PublicApiError, + parse_obj_as( + type_=PublicApiError, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 400: + raise Error( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 401: + raise commons_errors_unauthorized_error_UnauthorizedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 403: + raise commons_errors_access_denied_error_AccessDeniedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 405: + raise commons_errors_method_not_allowed_error_MethodNotAllowedError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + if _response.status_code == 404: + raise NotFoundError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, + headers=dict(_response.headers), + body=_response.text, + ) + raise ApiError( + status_code=_response.status_code, + headers=dict(_response.headers), + body=_response_json, + ) diff --git a/langfuse/api/unstable/billable_units/types/__init__.py b/langfuse/api/unstable/billable_units/types/__init__.py new file mode 100644 index 000000000..d43fddaa0 --- /dev/null +++ b/langfuse/api/unstable/billable_units/types/__init__.py @@ -0,0 +1,46 @@ +# This file was auto-generated by Fern from our API Definition. + +# isort: skip_file + +import typing +from importlib import import_module + +if typing.TYPE_CHECKING: + from .billable_units_granularity import BillableUnitsGranularity + from .billable_units_response import BillableUnitsResponse + from .billable_units_row import BillableUnitsRow +_dynamic_imports: typing.Dict[str, str] = { + "BillableUnitsGranularity": ".billable_units_granularity", + "BillableUnitsResponse": ".billable_units_response", + "BillableUnitsRow": ".billable_units_row", +} + + +def __getattr__(attr_name: str) -> typing.Any: + module_name = _dynamic_imports.get(attr_name) + if module_name is None: + raise AttributeError( + f"No {attr_name} found in _dynamic_imports for module name -> {__name__}" + ) + try: + module = import_module(module_name, __package__) + if module_name == f".{attr_name}": + return module + else: + return getattr(module, attr_name) + except ImportError as e: + raise ImportError( + f"Failed to import {attr_name} from {module_name}: {e}" + ) from e + except AttributeError as e: + raise AttributeError( + f"Failed to get {attr_name} from {module_name}: {e}" + ) from e + + +def __dir__(): + lazy_attrs = list(_dynamic_imports.keys()) + return sorted(lazy_attrs) + + +__all__ = ["BillableUnitsGranularity", "BillableUnitsResponse", "BillableUnitsRow"] diff --git a/langfuse/api/unstable/billable_units/types/billable_units_granularity.py b/langfuse/api/unstable/billable_units/types/billable_units_granularity.py new file mode 100644 index 000000000..46dec5aef --- /dev/null +++ b/langfuse/api/unstable/billable_units/types/billable_units_granularity.py @@ -0,0 +1,30 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +from ....core import enum + +T_Result = typing.TypeVar("T_Result") + + +class BillableUnitsGranularity(enum.StrEnum): + HOUR = "hour" + DAY = "day" + WEEK = "week" + MONTH = "month" + + def visit( + self, + hour: typing.Callable[[], T_Result], + day: typing.Callable[[], T_Result], + week: typing.Callable[[], T_Result], + month: typing.Callable[[], T_Result], + ) -> T_Result: + if self is BillableUnitsGranularity.HOUR: + return hour() + if self is BillableUnitsGranularity.DAY: + return day() + if self is BillableUnitsGranularity.WEEK: + return week() + if self is BillableUnitsGranularity.MONTH: + return month() diff --git a/langfuse/api/unstable/billable_units/types/billable_units_response.py b/langfuse/api/unstable/billable_units/types/billable_units_response.py new file mode 100644 index 000000000..4aa6f4a61 --- /dev/null +++ b/langfuse/api/unstable/billable_units/types/billable_units_response.py @@ -0,0 +1,24 @@ +# 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 .billable_units_row import BillableUnitsRow + + +class BillableUnitsResponse(UniversalBaseModel): + data: typing.List[BillableUnitsRow] + usage_recorded_from: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="usageRecordedFrom") + ] = pydantic.Field(default=None) + """ + When usage recording started on this deployment. Buckets before it show no usage. Null while nothing has been recorded, and on deployments that count the legacy tables. + """ + + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) diff --git a/langfuse/api/unstable/billable_units/types/billable_units_row.py b/langfuse/api/unstable/billable_units/types/billable_units_row.py new file mode 100644 index 000000000..bed4fec44 --- /dev/null +++ b/langfuse/api/unstable/billable_units/types/billable_units_row.py @@ -0,0 +1,37 @@ +# 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 + + +class BillableUnitsRow(UniversalBaseModel): + """ + Billable units of one project in one bucket. + """ + + bucket: dt.datetime = pydantic.Field() + """ + Start of the UTC bucket. + """ + + project_id: typing_extensions.Annotated[str, FieldMetadata(alias="projectId")] + count: int = pydantic.Field() + """ + All billable units, the sum of the per-type counts. + """ + + traces: int + observations: int + scores: int + topic_facet_summaries: typing_extensions.Annotated[ + int, FieldMetadata(alias="topicFacetSummaries") + ] + + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) diff --git a/langfuse/api/unstable/client.py b/langfuse/api/unstable/client.py index 314109b0f..9f7a45744 100644 --- a/langfuse/api/unstable/client.py +++ b/langfuse/api/unstable/client.py @@ -8,6 +8,7 @@ from .raw_client import AsyncRawUnstableClient, RawUnstableClient if typing.TYPE_CHECKING: + from .billable_units.client import AsyncBillableUnitsClient, BillableUnitsClient from .dashboard_widgets.client import ( AsyncDashboardWidgetsClient, DashboardWidgetsClient, @@ -20,6 +21,7 @@ class UnstableClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._raw_client = RawUnstableClient(client_wrapper=client_wrapper) self._client_wrapper = client_wrapper + self._billable_units: typing.Optional[BillableUnitsClient] = None self._dashboard_widgets: typing.Optional[DashboardWidgetsClient] = None self._dashboards: typing.Optional[DashboardsClient] = None self._topics: typing.Optional[TopicsClient] = None @@ -35,6 +37,16 @@ def with_raw_response(self) -> RawUnstableClient: """ return self._raw_client + @property + def billable_units(self): + if self._billable_units is None: + from .billable_units.client import BillableUnitsClient # noqa: E402 + + self._billable_units = BillableUnitsClient( + client_wrapper=self._client_wrapper + ) + return self._billable_units + @property def dashboard_widgets(self): if self._dashboard_widgets is None: @@ -66,6 +78,7 @@ class AsyncUnstableClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._raw_client = AsyncRawUnstableClient(client_wrapper=client_wrapper) self._client_wrapper = client_wrapper + self._billable_units: typing.Optional[AsyncBillableUnitsClient] = None self._dashboard_widgets: typing.Optional[AsyncDashboardWidgetsClient] = None self._dashboards: typing.Optional[AsyncDashboardsClient] = None self._topics: typing.Optional[AsyncTopicsClient] = None @@ -81,6 +94,16 @@ def with_raw_response(self) -> AsyncRawUnstableClient: """ return self._raw_client + @property + def billable_units(self): + if self._billable_units is None: + from .billable_units.client import AsyncBillableUnitsClient # noqa: E402 + + self._billable_units = AsyncBillableUnitsClient( + client_wrapper=self._client_wrapper + ) + return self._billable_units + @property def dashboard_widgets(self): if self._dashboard_widgets is None: