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
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213 | 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. Falls back to the HH_API_TIMEOUT
env var, then to the SDK default of 5s. Pass a larger value when
fetching large payloads (e.g. datasets.list for many datasets).
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. The request timeout is resolved from the explicit
# arg > HH_API_TIMEOUT env var; when neither is set we omit the key so
# the APIConfig default (5.0s) is preserved. Note: passing timeout=None
# to HoneyHive() keeps the default (None means "unset" here), whereas
# APIConfig(timeout=None) disables timeouts at the low level.
api_config_kwargs: Dict[str, Any] = {
"base_path": resolved_base_url,
"access_token": self._api_key,
}
resolved_timeout = _resolve_api_timeout(timeout)
if resolved_timeout is not None:
api_config_kwargs["timeout"] = resolved_timeout
self._api_config = APIConfig(**api_config_kwargs)
# 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.metric_versions = MetricVersionsAPI(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
|