# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import typing

import httpx
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper

if typing.TYPE_CHECKING:
    from .annotation_queues.client import (
        AnnotationQueuesClient,
        AsyncAnnotationQueuesClient,
    )
    from .blob_storage_integrations.client import (
        AsyncBlobStorageIntegrationsClient,
        BlobStorageIntegrationsClient,
    )
    from .comments.client import AsyncCommentsClient, CommentsClient
    from .dataset_items.client import AsyncDatasetItemsClient, DatasetItemsClient
    from .dataset_run_items.client import (
        AsyncDatasetRunItemsClient,
        DatasetRunItemsClient,
    )
    from .datasets.client import AsyncDatasetsClient, DatasetsClient
    from .health.client import AsyncHealthClient, HealthClient
    from .ingestion.client import AsyncIngestionClient, IngestionClient
    from .legacy.client import AsyncLegacyClient, LegacyClient
    from .llm_connections.client import AsyncLlmConnectionsClient, LlmConnectionsClient
    from .media.client import AsyncMediaClient, MediaClient
    from .metrics.client import AsyncMetricsClient, MetricsClient
    from .models.client import AsyncModelsClient, ModelsClient
    from .observations.client import AsyncObservationsClient, ObservationsClient
    from .opentelemetry.client import AsyncOpentelemetryClient, OpentelemetryClient
    from .organizations.client import AsyncOrganizationsClient, OrganizationsClient
    from .projects.client import AsyncProjectsClient, ProjectsClient
    from .prompt_version.client import AsyncPromptVersionClient, PromptVersionClient
    from .prompts.client import AsyncPromptsClient, PromptsClient
    from .scim.client import AsyncScimClient, ScimClient
    from .score_configs.client import AsyncScoreConfigsClient, ScoreConfigsClient
    from .scores.client import AsyncScoresClient, ScoresClient
    from .sessions.client import AsyncSessionsClient, SessionsClient
    from .trace.client import AsyncTraceClient, TraceClient


class LangfuseAPI:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : str
        The base url to use for requests from the client.

    x_langfuse_sdk_name : typing.Optional[str]
    x_langfuse_sdk_version : typing.Optional[str]
    x_langfuse_public_key : typing.Optional[str]
    username : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    password : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    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",
    )
    """

    def __init__(
        self,
        *,
        base_url: str,
        x_langfuse_sdk_name: typing.Optional[str] = None,
        x_langfuse_sdk_version: typing.Optional[str] = None,
        x_langfuse_public_key: typing.Optional[str] = None,
        username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
    ):
        _defaulted_timeout = (
            timeout
            if timeout is not None
            else 60
            if httpx_client is None
            else httpx_client.timeout.read
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=base_url,
            x_langfuse_sdk_name=x_langfuse_sdk_name,
            x_langfuse_sdk_version=x_langfuse_sdk_version,
            x_langfuse_public_key=x_langfuse_public_key,
            username=username,
            password=password,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(
                timeout=_defaulted_timeout, follow_redirects=follow_redirects
            )
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._annotation_queues: typing.Optional[AnnotationQueuesClient] = None
        self._blob_storage_integrations: typing.Optional[
            BlobStorageIntegrationsClient
        ] = None
        self._comments: typing.Optional[CommentsClient] = None
        self._dataset_items: typing.Optional[DatasetItemsClient] = None
        self._dataset_run_items: typing.Optional[DatasetRunItemsClient] = None
        self._datasets: typing.Optional[DatasetsClient] = None
        self._health: typing.Optional[HealthClient] = None
        self._ingestion: typing.Optional[IngestionClient] = None
        self._legacy: typing.Optional[LegacyClient] = None
        self._llm_connections: typing.Optional[LlmConnectionsClient] = None
        self._media: typing.Optional[MediaClient] = None
        self._metrics: typing.Optional[MetricsClient] = None
        self._models: typing.Optional[ModelsClient] = None
        self._observations: typing.Optional[ObservationsClient] = None
        self._opentelemetry: typing.Optional[OpentelemetryClient] = None
        self._organizations: typing.Optional[OrganizationsClient] = None
        self._projects: typing.Optional[ProjectsClient] = None
        self._prompt_version: typing.Optional[PromptVersionClient] = None
        self._prompts: typing.Optional[PromptsClient] = None
        self._scim: typing.Optional[ScimClient] = None
        self._score_configs: typing.Optional[ScoreConfigsClient] = None
        self._scores: typing.Optional[ScoresClient] = None
        self._sessions: typing.Optional[SessionsClient] = None
        self._trace: typing.Optional[TraceClient] = None

    @property
    def annotation_queues(self):
        if self._annotation_queues is None:
            from .annotation_queues.client import AnnotationQueuesClient  # noqa: E402

            self._annotation_queues = AnnotationQueuesClient(
                client_wrapper=self._client_wrapper
            )
        return self._annotation_queues

    @property
    def blob_storage_integrations(self):
        if self._blob_storage_integrations is None:
            from .blob_storage_integrations.client import BlobStorageIntegrationsClient  # noqa: E402

            self._blob_storage_integrations = BlobStorageIntegrationsClient(
                client_wrapper=self._client_wrapper
            )
        return self._blob_storage_integrations

    @property
    def comments(self):
        if self._comments is None:
            from .comments.client import CommentsClient  # noqa: E402

            self._comments = CommentsClient(client_wrapper=self._client_wrapper)
        return self._comments

    @property
    def dataset_items(self):
        if self._dataset_items is None:
            from .dataset_items.client import DatasetItemsClient  # noqa: E402

            self._dataset_items = DatasetItemsClient(
                client_wrapper=self._client_wrapper
            )
        return self._dataset_items

    @property
    def dataset_run_items(self):
        if self._dataset_run_items is None:
            from .dataset_run_items.client import DatasetRunItemsClient  # noqa: E402

            self._dataset_run_items = DatasetRunItemsClient(
                client_wrapper=self._client_wrapper
            )
        return self._dataset_run_items

    @property
    def datasets(self):
        if self._datasets is None:
            from .datasets.client import DatasetsClient  # noqa: E402

            self._datasets = DatasetsClient(client_wrapper=self._client_wrapper)
        return self._datasets

    @property
    def health(self):
        if self._health is None:
            from .health.client import HealthClient  # noqa: E402

            self._health = HealthClient(client_wrapper=self._client_wrapper)
        return self._health

    @property
    def ingestion(self):
        if self._ingestion is None:
            from .ingestion.client import IngestionClient  # noqa: E402

            self._ingestion = IngestionClient(client_wrapper=self._client_wrapper)
        return self._ingestion

    @property
    def legacy(self):
        if self._legacy is None:
            from .legacy.client import LegacyClient  # noqa: E402

            self._legacy = LegacyClient(client_wrapper=self._client_wrapper)
        return self._legacy

    @property
    def llm_connections(self):
        if self._llm_connections is None:
            from .llm_connections.client import LlmConnectionsClient  # noqa: E402

            self._llm_connections = LlmConnectionsClient(
                client_wrapper=self._client_wrapper
            )
        return self._llm_connections

    @property
    def media(self):
        if self._media is None:
            from .media.client import MediaClient  # noqa: E402

            self._media = MediaClient(client_wrapper=self._client_wrapper)
        return self._media

    @property
    def metrics(self):
        if self._metrics is None:
            from .metrics.client import MetricsClient  # noqa: E402

            self._metrics = MetricsClient(client_wrapper=self._client_wrapper)
        return self._metrics

    @property
    def models(self):
        if self._models is None:
            from .models.client import ModelsClient  # noqa: E402

            self._models = ModelsClient(client_wrapper=self._client_wrapper)
        return self._models

    @property
    def observations(self):
        if self._observations is None:
            from .observations.client import ObservationsClient  # noqa: E402

            self._observations = ObservationsClient(client_wrapper=self._client_wrapper)
        return self._observations

    @property
    def opentelemetry(self):
        if self._opentelemetry is None:
            from .opentelemetry.client import OpentelemetryClient  # noqa: E402

            self._opentelemetry = OpentelemetryClient(
                client_wrapper=self._client_wrapper
            )
        return self._opentelemetry

    @property
    def organizations(self):
        if self._organizations is None:
            from .organizations.client import OrganizationsClient  # noqa: E402

            self._organizations = OrganizationsClient(
                client_wrapper=self._client_wrapper
            )
        return self._organizations

    @property
    def projects(self):
        if self._projects is None:
            from .projects.client import ProjectsClient  # noqa: E402

            self._projects = ProjectsClient(client_wrapper=self._client_wrapper)
        return self._projects

    @property
    def prompt_version(self):
        if self._prompt_version is None:
            from .prompt_version.client import PromptVersionClient  # noqa: E402

            self._prompt_version = PromptVersionClient(
                client_wrapper=self._client_wrapper
            )
        return self._prompt_version

    @property
    def prompts(self):
        if self._prompts is None:
            from .prompts.client import PromptsClient  # noqa: E402

            self._prompts = PromptsClient(client_wrapper=self._client_wrapper)
        return self._prompts

    @property
    def scim(self):
        if self._scim is None:
            from .scim.client import ScimClient  # noqa: E402

            self._scim = ScimClient(client_wrapper=self._client_wrapper)
        return self._scim

    @property
    def score_configs(self):
        if self._score_configs is None:
            from .score_configs.client import ScoreConfigsClient  # noqa: E402

            self._score_configs = ScoreConfigsClient(
                client_wrapper=self._client_wrapper
            )
        return self._score_configs

    @property
    def scores(self):
        if self._scores is None:
            from .scores.client import ScoresClient  # noqa: E402

            self._scores = ScoresClient(client_wrapper=self._client_wrapper)
        return self._scores

    @property
    def sessions(self):
        if self._sessions is None:
            from .sessions.client import SessionsClient  # noqa: E402

            self._sessions = SessionsClient(client_wrapper=self._client_wrapper)
        return self._sessions

    @property
    def trace(self):
        if self._trace is None:
            from .trace.client import TraceClient  # noqa: E402

            self._trace = TraceClient(client_wrapper=self._client_wrapper)
        return self._trace


class AsyncLangfuseAPI:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : str
        The base url to use for requests from the client.

    x_langfuse_sdk_name : typing.Optional[str]
    x_langfuse_sdk_version : typing.Optional[str]
    x_langfuse_public_key : typing.Optional[str]
    username : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    password : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    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",
    )
    """

    def __init__(
        self,
        *,
        base_url: str,
        x_langfuse_sdk_name: typing.Optional[str] = None,
        x_langfuse_sdk_version: typing.Optional[str] = None,
        x_langfuse_public_key: typing.Optional[str] = None,
        username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
    ):
        _defaulted_timeout = (
            timeout
            if timeout is not None
            else 60
            if httpx_client is None
            else httpx_client.timeout.read
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=base_url,
            x_langfuse_sdk_name=x_langfuse_sdk_name,
            x_langfuse_sdk_version=x_langfuse_sdk_version,
            x_langfuse_public_key=x_langfuse_public_key,
            username=username,
            password=password,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(
                timeout=_defaulted_timeout, follow_redirects=follow_redirects
            )
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._annotation_queues: typing.Optional[AsyncAnnotationQueuesClient] = None
        self._blob_storage_integrations: typing.Optional[
            AsyncBlobStorageIntegrationsClient
        ] = None
        self._comments: typing.Optional[AsyncCommentsClient] = None
        self._dataset_items: typing.Optional[AsyncDatasetItemsClient] = None
        self._dataset_run_items: typing.Optional[AsyncDatasetRunItemsClient] = None
        self._datasets: typing.Optional[AsyncDatasetsClient] = None
        self._health: typing.Optional[AsyncHealthClient] = None
        self._ingestion: typing.Optional[AsyncIngestionClient] = None
        self._legacy: typing.Optional[AsyncLegacyClient] = None
        self._llm_connections: typing.Optional[AsyncLlmConnectionsClient] = None
        self._media: typing.Optional[AsyncMediaClient] = None
        self._metrics: typing.Optional[AsyncMetricsClient] = None
        self._models: typing.Optional[AsyncModelsClient] = None
        self._observations: typing.Optional[AsyncObservationsClient] = None
        self._opentelemetry: typing.Optional[AsyncOpentelemetryClient] = None
        self._organizations: typing.Optional[AsyncOrganizationsClient] = None
        self._projects: typing.Optional[AsyncProjectsClient] = None
        self._prompt_version: typing.Optional[AsyncPromptVersionClient] = None
        self._prompts: typing.Optional[AsyncPromptsClient] = None
        self._scim: typing.Optional[AsyncScimClient] = None
        self._score_configs: typing.Optional[AsyncScoreConfigsClient] = None
        self._scores: typing.Optional[AsyncScoresClient] = None
        self._sessions: typing.Optional[AsyncSessionsClient] = None
        self._trace: typing.Optional[AsyncTraceClient] = None

    @property
    def annotation_queues(self):
        if self._annotation_queues is None:
            from .annotation_queues.client import AsyncAnnotationQueuesClient  # noqa: E402

            self._annotation_queues = AsyncAnnotationQueuesClient(
                client_wrapper=self._client_wrapper
            )
        return self._annotation_queues

    @property
    def blob_storage_integrations(self):
        if self._blob_storage_integrations is None:
            from .blob_storage_integrations.client import (
                AsyncBlobStorageIntegrationsClient,
            )  # noqa: E402

            self._blob_storage_integrations = AsyncBlobStorageIntegrationsClient(
                client_wrapper=self._client_wrapper
            )
        return self._blob_storage_integrations

    @property
    def comments(self):
        if self._comments is None:
            from .comments.client import AsyncCommentsClient  # noqa: E402

            self._comments = AsyncCommentsClient(client_wrapper=self._client_wrapper)
        return self._comments

    @property
    def dataset_items(self):
        if self._dataset_items is None:
            from .dataset_items.client import AsyncDatasetItemsClient  # noqa: E402

            self._dataset_items = AsyncDatasetItemsClient(
                client_wrapper=self._client_wrapper
            )
        return self._dataset_items

    @property
    def dataset_run_items(self):
        if self._dataset_run_items is None:
            from .dataset_run_items.client import AsyncDatasetRunItemsClient  # noqa: E402

            self._dataset_run_items = AsyncDatasetRunItemsClient(
                client_wrapper=self._client_wrapper
            )
        return self._dataset_run_items

    @property
    def datasets(self):
        if self._datasets is None:
            from .datasets.client import AsyncDatasetsClient  # noqa: E402

            self._datasets = AsyncDatasetsClient(client_wrapper=self._client_wrapper)
        return self._datasets

    @property
    def health(self):
        if self._health is None:
            from .health.client import AsyncHealthClient  # noqa: E402

            self._health = AsyncHealthClient(client_wrapper=self._client_wrapper)
        return self._health

    @property
    def ingestion(self):
        if self._ingestion is None:
            from .ingestion.client import AsyncIngestionClient  # noqa: E402

            self._ingestion = AsyncIngestionClient(client_wrapper=self._client_wrapper)
        return self._ingestion

    @property
    def legacy(self):
        if self._legacy is None:
            from .legacy.client import AsyncLegacyClient  # noqa: E402

            self._legacy = AsyncLegacyClient(client_wrapper=self._client_wrapper)
        return self._legacy

    @property
    def llm_connections(self):
        if self._llm_connections is None:
            from .llm_connections.client import AsyncLlmConnectionsClient  # noqa: E402

            self._llm_connections = AsyncLlmConnectionsClient(
                client_wrapper=self._client_wrapper
            )
        return self._llm_connections

    @property
    def media(self):
        if self._media is None:
            from .media.client import AsyncMediaClient  # noqa: E402

            self._media = AsyncMediaClient(client_wrapper=self._client_wrapper)
        return self._media

    @property
    def metrics(self):
        if self._metrics is None:
            from .metrics.client import AsyncMetricsClient  # noqa: E402

            self._metrics = AsyncMetricsClient(client_wrapper=self._client_wrapper)
        return self._metrics

    @property
    def models(self):
        if self._models is None:
            from .models.client import AsyncModelsClient  # noqa: E402

            self._models = AsyncModelsClient(client_wrapper=self._client_wrapper)
        return self._models

    @property
    def observations(self):
        if self._observations is None:
            from .observations.client import AsyncObservationsClient  # noqa: E402

            self._observations = AsyncObservationsClient(
                client_wrapper=self._client_wrapper
            )
        return self._observations

    @property
    def opentelemetry(self):
        if self._opentelemetry is None:
            from .opentelemetry.client import AsyncOpentelemetryClient  # noqa: E402

            self._opentelemetry = AsyncOpentelemetryClient(
                client_wrapper=self._client_wrapper
            )
        return self._opentelemetry

    @property
    def organizations(self):
        if self._organizations is None:
            from .organizations.client import AsyncOrganizationsClient  # noqa: E402

            self._organizations = AsyncOrganizationsClient(
                client_wrapper=self._client_wrapper
            )
        return self._organizations

    @property
    def projects(self):
        if self._projects is None:
            from .projects.client import AsyncProjectsClient  # noqa: E402

            self._projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
        return self._projects

    @property
    def prompt_version(self):
        if self._prompt_version is None:
            from .prompt_version.client import AsyncPromptVersionClient  # noqa: E402

            self._prompt_version = AsyncPromptVersionClient(
                client_wrapper=self._client_wrapper
            )
        return self._prompt_version

    @property
    def prompts(self):
        if self._prompts is None:
            from .prompts.client import AsyncPromptsClient  # noqa: E402

            self._prompts = AsyncPromptsClient(client_wrapper=self._client_wrapper)
        return self._prompts

    @property
    def scim(self):
        if self._scim is None:
            from .scim.client import AsyncScimClient  # noqa: E402

            self._scim = AsyncScimClient(client_wrapper=self._client_wrapper)
        return self._scim

    @property
    def score_configs(self):
        if self._score_configs is None:
            from .score_configs.client import AsyncScoreConfigsClient  # noqa: E402

            self._score_configs = AsyncScoreConfigsClient(
                client_wrapper=self._client_wrapper
            )
        return self._score_configs

    @property
    def scores(self):
        if self._scores is None:
            from .scores.client import AsyncScoresClient  # noqa: E402

            self._scores = AsyncScoresClient(client_wrapper=self._client_wrapper)
        return self._scores

    @property
    def sessions(self):
        if self._sessions is None:
            from .sessions.client import AsyncSessionsClient  # noqa: E402

            self._sessions = AsyncSessionsClient(client_wrapper=self._client_wrapper)
        return self._sessions

    @property
    def trace(self):
        if self._trace is None:
            from .trace.client import AsyncTraceClient  # noqa: E402

            self._trace = AsyncTraceClient(client_wrapper=self._client_wrapper)
        return self._trace
