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. There are three ways to provide a project API key, and an ingestion key has its own slot alongside it. 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 project key, 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. Every other method uses the project key and never the ingestion key.
A client constructed with only an ingestion key works for those ingestion methods; any other method has no credential to send and gets a 404. Construction fails only when neither key is available and no middleware is supplied. The ingestion key’s value is checked at construction: anything that is not an hh_ingst_ key throws, naming where the value came from and the 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 will override any API key provided via projectApiKey or HH_PROJECT_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, a masked API key, and the SDK package + version when the client is constructed. Useful for confirming which environment and credential 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. The masked project API key keeps the recognized prefix (hh_ for a project key, hh_ro_ for a read-only project key) and the last 4 characters; anything else renders as 8 fixed-width asterisks. An ingestion key renders as hh_ingst_<key id>_******, showing its id and none of its secret.