1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105 | class HoneyHive:
"""Main HoneyHive API client.
Provides an ergonomic interface to the HoneyHive API with both
sync and async methods.
Example::
client = HoneyHive(api_key="your-api-key")
# Sync
configs = client.configurations.list()
# Async
configs = await client.configurations.list_async()
Attributes:
configurations: API for managing configurations.
datapoints: API for managing datapoints.
datasets: API for managing datasets.
events: API for managing events.
experiments: API for managing experiment runs.
metrics: API for managing metrics.
sessions: API for managing sessions.
"""
def __init__(
self,
api_key: Optional[str] = None,
# `project` sits at positional slot #2 to mirror the legacy SDK shape
# — pre-1.0 callers wrote `HoneyHive("key", "project-name")` positionally.
# Keeping the slot reserved means those calls still execute (with a
# DeprecationWarning) instead of binding the value to `base_url` or
# raising TypeError. The argument is otherwise ignored.
project: Optional[str] = None,
*,
# Primary URL parameter
base_url: Optional[str] = None,
# Backwards compatible alias for base_url
server_url: Optional[str] = None,
# Backwards compatible parameters (accepted but not used in new client)
cp_base_url: Optional[str] = None,
timeout: Optional[float] = None,
retry_config: Optional[Any] = None,
rate_limit_calls: Optional[int] = None,
rate_limit_window: Optional[float] = None,
max_connections: Optional[int] = None,
max_keepalive: Optional[int] = None,
test_mode: Optional[bool] = None,
verbose: Optional[bool] = None,
tracer_instance: Optional[Any] = None,
) -> None:
"""Initialize the HoneyHive client.
Args:
api_key: HoneyHive API key (typically starts with ``hh_``).
Falls back to HH_API_KEY environment variable.
project: Deprecated. Accepted for backwards compatibility only;
the backend infers project context from the API key and session.
Ignored when constructing the client.
base_url: API base URL for HoneyHive.
Falls back to HH_API_URL env var, then https://api.dp1.us.honeyhive.ai.
server_url: Deprecated alias for base_url (for backwards compatibility).
cp_base_url: Deprecated. Accepted for backwards compatibility but ignored;
the SDK now uses a single base_url for all operations.
timeout: Request timeout in seconds (accepted for backwards compat, not used).
retry_config: Retry configuration (accepted for backwards compat, not used).
rate_limit_calls: Max calls per time window (accepted for backwards compat).
rate_limit_window: Time window in seconds (accepted for backwards compat).
max_connections: Max connections in pool (accepted for backwards compat).
max_keepalive: Max keepalive connections (accepted for backwards compat).
test_mode: Enable test mode (accepted for backwards compat, not used).
verbose: Enable verbose logging (accepted for backwards compat, not used).
tracer_instance: Tracer instance (accepted for backwards compat, not used).
"""
import os
if project is not None:
warnings.warn(
"The 'project' argument to HoneyHive() is deprecated and ignored; "
"it will be removed in v2.0. Remove it from HoneyHive() calls.",
DeprecationWarning,
stacklevel=2,
)
if cp_base_url is not None:
warnings.warn(
"The 'cp_base_url' parameter is no longer used and will be removed "
"in v2.0. The SDK now uses a single base_url for all operations.",
DeprecationWarning,
stacklevel=2,
)
# Resolve API key from parameter or environment
self._api_key = api_key or os.environ.get("HH_API_KEY", "")
# Resolve base URL: base_url > server_url (legacy) > env var > default
resolved_base_url = (
base_url
or server_url # Legacy parameter
or os.environ.get("HH_API_URL")
or "https://api.dp1.us.honeyhive.ai"
)
# Store backwards compat params (silently accepted)
self._timeout = timeout
self._test_mode = test_mode if test_mode is not None else False
self._verbose = verbose if verbose is not None else False
self._tracer_instance = tracer_instance
# Create API config
self._api_config = APIConfig(
base_path=resolved_base_url,
access_token=self._api_key,
)
# Initialize API namespaces
self.charts = ChartsAPI(self._api_config)
self.configurations = ConfigurationsAPI(self._api_config)
self.datapoints = DatapointsAPI(self._api_config)
self.datasets = DatasetsAPI(self._api_config)
self.events = EventsAPI(self._api_config)
self.experiments = ExperimentsAPI(self._api_config)
self.metrics = MetricsAPI(self._api_config)
self.sessions = SessionsAPI(self._api_config)
# Alias for backwards compatibility
self.evaluations = self.experiments
@property
def test_mode(self) -> bool:
"""Return whether client is in test mode."""
return self._test_mode
@property
def verbose(self) -> bool:
"""Return whether verbose mode is enabled."""
return self._verbose
@property
def timeout(self) -> Optional[float]:
"""Return the configured timeout."""
return self._timeout
@property
def api_config(self) -> APIConfig:
"""Access the underlying API configuration."""
return self._api_config
@property
def api_key(self) -> str:
"""Get the HoneyHive API key."""
return self._api_key
@property
def server_url(self) -> str:
"""Get the HoneyHive API server URL."""
return self._api_config.base_path
@server_url.setter
def server_url(self, value: str) -> None:
"""Set the HoneyHive API server URL."""
self._api_config.base_path = value
|