Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion langfuse/api/unstable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -152,6 +160,7 @@
"UpdateDashboardRequest": ".dashboards",
"UpdateDashboardWidgetRequest": ".dashboard_widgets",
"WidgetPlacement": ".dashboards",
"billable_units": ".billable_units",
"dashboard_widgets": ".dashboard_widgets",
"dashboards": ".dashboards",
"errors": ".errors",
Expand Down Expand Up @@ -189,6 +198,9 @@ def __dir__():
__all__ = [
"AccessDeniedError",
"BadRequestError",
"BillableUnitsGranularity",
"BillableUnitsResponse",
"BillableUnitsRow",
"ConflictError",
"CreateDashboardPlacementRequest",
"CreateDashboardPlacementRequest_Preset",
Expand Down Expand Up @@ -255,6 +267,7 @@ def __dir__():
"UpdateDashboardRequest",
"UpdateDashboardWidgetRequest",
"WidgetPlacement",
"billable_units",
"dashboard_widgets",
"dashboards",
"errors",
Expand Down
44 changes: 44 additions & 0 deletions langfuse/api/unstable/billable_units/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
201 changes: 201 additions & 0 deletions langfuse/api/unstable/billable_units/client.py
Original file line number Diff line number Diff line change
@@ -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",
),
Comment on lines +91 to +93

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Examples request an empty interval

Both get examples pass identical from_timestamp and to_timestamp values. The documented range excludes its end, so users copying either example request no time span rather than a useful usage report. Set to_timestamp later than from_timestamp in both examples.

Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/api/unstable/billable_units/client.py
Line: 91-93

Comment:
**Examples request an empty interval**

Both `get` examples pass identical `from_timestamp` and `to_timestamp` values. The documented range excludes its end, so users copying either example request no time span rather than a useful usage report. Set `to_timestamp` later than `from_timestamp` in both examples.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

)
"""
_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
Loading
Loading