Skip to main content
@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 the Authorization 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

Set HH_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:
This example requires 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

Set the HH_PROJECT_API_KEY environment variable. The client reads it automatically when no projectApiKey option is provided:
The HH_API_KEY environment variable is deprecated and will be removed in the next major version. Using it logs a deprecation warning to stderr on client construction. Migrate to HH_PROJECT_API_KEY.

projectApiKey option

Pass the key directly in ClientConfig.
Never hard-code the key or commit it to source control. Always read it from a secret store or environment variable.
The apiKey option is deprecated and will be removed in the next major version. Setting it logs a deprecation warning to stderr on client construction. Migrate to projectApiKey.

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.
With only an ingestion key configured, the client can call ingestion methods. Other methods fail before sending and name the required key. A client can be constructed without keys, but calls require a credential or custom authentication. At construction, the client validates typed keys supplied through options or environment variables. If a key has the wrong type or is incomplete, the error names its source and expected prefix.

Custom middleware

For advanced scenarios (rotating keys, fetching tokens at request time), you can supply custom middleware that sets the Authorization 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>.
See the openapi-fetch middleware documentation for more details on the Middleware interface.

Data plane URL

By default the client talks to https://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:
The serverUrl constructor option and the HH_API_URL environment variable are deprecated and will be removed in the next major version. Using either logs a deprecation warning to stderr on client construction. Migrate to dataPlaneUrl / HH_DATA_PLANE_URL.

Verbose logging

Set verbose: 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.
Output is written via 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.