@honeyhive/api-client is a type-safe TypeScript client for the HoneyHive REST API. It provides a one-to-one mapping of methods to API endpoints, organized into namespaces: client.datasets, client.datapoints, client.experiments, etc.
Built on openapi-fetch, the client handles response parsing, query serialization, and error handling automatically. All request and response types are generated from the OpenAPI specification, so your editor provides full autocompletion and type checking for every API call.
If you’re coming from the legacy @honeyhive/logger package, see the migration guide.
Installation
Quick start
Create a session (trace) and log an OpenAI call:Example: Creating and populating a dataset
Authorization
The HoneyHive API authenticates requests using an API key sent as a Bearer token in theAuthorization header. The client holds three credentials and selects one per operation:
See API Keys to create the keys your workload needs.
Data plane API key
SetHH_DATA_PLANE_API_KEY to a complete hh_fgdp_ key, or pass dataPlaneApiKey. For supported methods, include project_id in the request, even when the key is rooted at that project:
project.chart.list. Copy the project ID and data plane URL from Settings > Project > API Keys > Data Plane. Configure a non-default URL with HH_DATA_PLANE_URL or dataPlaneUrl.
For a method with both legacy and scoped routes, omitting project_id selects the legacy route and project key, even if a data plane key is configured. The legacy chart, dataset, and datapoint calls are deprecated. Passing project_id selects the scoped route, which requires a data plane key and does not accept a project key. See the credential matrix.
Data plane keys cannot send traces. Keep an ingestion key for telemetry and a project key for operations that still require it. The client validates typed key values at construction and rejects calls with missing credentials before sending them.
Use client.dataPlaneApiKeys.create and client.ingestionApiKeys.create with an organization-rooted data plane key to issue project credentials. See How to create API keys programmatically.
Project API key
Environment variable (recommended)
Set theHH_PROJECT_API_KEY environment variable. The client reads it automatically when no projectApiKey option is provided:
projectApiKey option
Pass the key directly inClientConfig.
Never hard-code the key or commit it to source control. Always read it from a secret store or environment variable.
Ingestion API key
An ingestion API key (hh_ingst_) can be held alongside the other keys, in the HH_INGESTION_API_KEY environment variable or the ingestionApiKey option. The methods that create sessions and create or update events (singly or in batches) send it when it is set, and fall back to the project key otherwise. Other methods never use the ingestion key.
Custom middleware
For advanced scenarios (rotating keys, fetching tokens at request time), you can supply custom middleware that sets theAuthorization header on each request. Middleware runs after the initial headers are set, so it can override the selected API key.
When middleware is provided without an API key, the client skips the missing-key error and assumes the middleware handles authentication. If both are provided, the API key sets the initial header and the middleware can override it per-request.
The required header format is Authorization: Bearer <api-key>.
Middleware interface.
Data plane URL
By default the client talks tohttps://api.dp1.us.honeyhive.ai. To point at a self-hosted deployment or a staging environment, set the HH_DATA_PLANE_URL environment variable or pass dataPlaneUrl:
Verbose logging
Setverbose: true (or the HH_VERBOSE environment variable to true) to log the resolved data plane URL, each API key slot (masked, or (none) when unset), and the SDK package + version when the client is constructed. Useful for confirming which environment and credentials the client is configured with.
console.error (stderr in Node, devtools in the browser) and only fires once per client construction. An explicit verbose: false overrides HH_VERBOSE. All three credential slots are logged, with (none) for any unset credential. A classic project API key shows a recognized prefix and the last 4 characters. Ingestion and data plane fine-grained keys show their prefix and key id with the secret replaced by ******, matching the masked forms shown in the HoneyHive app. A typed key with a missing or malformed key id is replaced entirely with asterisks.