npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@honeyhive/api-client

v1.4.0

Published

Client for interacting with the HoneyHive REST API

Downloads

474

Readme

HoneyHive TypeScript Data Plane SDK

@honeyhive/api-client is a fully autogenerated TypeScript client for the HoneyHive Data Plane REST API. It provides a typed, one-to-one mapping of methods to REST 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 can provide full autocompletion and type checking for every API call.

Installation

npm install @honeyhive/api-client

Example: Creating and logging a trace

import { Client } from '@honeyhive/api-client';
import OpenAI from 'openai';

// The API key is read from the HH_PROJECT_API_KEY environment variable.
// The data plane URL is read from the HH_DATA_PLANE_URL environment variable
// and defaults to https://api.dp1.us.honeyhive.ai
const client = new Client();

// The API key is read from the OPENAI_API_KEY environment variable.
const openai = new OpenAI();

// 1. Start a session (trace)
const session = await client.sessions.create({
  session_name: 'openai-example',
  source: 'dev',
});

// 2. Create a model event for the OpenAI call
const startTime = Date.now();
const event = await client.events.create({
  session_id: session.session_id,
  event_type: 'model',
  event_name: 'chat-completion',
  config: { model: 'gpt-4o-mini' },
  inputs: {
    messages: [{ role: 'user', content: 'What is the meaning of life?' }],
  },
});

// 3. Make the OpenAI call
const completion = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'What is the meaning of life?' }],
});
const { content } = completion.choices[0].message;
console.log(content);

// 4. Update the event (span) with the response, if we got content back from OpenAI
if (content) {
  await client.events.update({
    event_id: event.event_id,
    outputs: { content },
    duration: Date.now() - startTime,
    metadata: {
      model: completion.model,
      usage: completion.usage,
    },
  });
}

Example: Creating and Populating a Dataset

The following example creates a dataset, appends a datapoint to it, lists the datasets in the project, and deletes the dataset when finished.

import { Client } from '@honeyhive/api-client';

// The API key is read from the HH_PROJECT_API_KEY environment variable.
// The data plane URL is read from the HH_DATA_PLANE_URL environment variable
// and defaults to https://api.dp1.us.honeyhive.ai
const client = new Client();

// 1. Create a dataset
const created = await client.datasets.create({
  name: 'qa-eval-set',
  description: 'Question/answer pairs for evaluation',
});
const datasetId = created.result.insertedId;

// 2. Append a datapoint linked to the new dataset
await client.datapoints.create({
  inputs: { question: 'What is the capital of France?' },
  ground_truth: { answer: 'Paris' },
  linked_datasets: [datasetId],
});

// 3. List datasets in the current project
const { datasets } = await client.datasets.list();
console.log(datasets.map((d) => d.name));

// 4. Delete the dataset
await client.datasets.delete({
  dataset_id: datasetId,
});

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 it.

Environment variable (recommended)

Set the HH_PROJECT_API_KEY environment variable. The client reads it automatically when no projectApiKey option is provided:

const client = new Client();

Deprecated alias: the HH_API_KEY environment variable is still accepted but 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:

const client = new Client({
  projectApiKey: process.env.MY_HONEYHIVE_KEY,
});

Deprecated alias: the apiKey option is still accepted but will be removed in the next major version. Setting it logs a deprecation warning to stderr on client construction. Migrate to projectApiKey.

Custom middleware

For advanced scenarios (rotating keys, fetching tokens at request time, etc.), 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 — it 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>.

import { Client } from '@honeyhive/api-client';

const client = new Client({
  // Passing the middleware inline lets TypeScript infer the correct type from
  // the `middleware` array — no separate Middleware import needed.
  middleware: [
    {
      async onRequest({ request }) {
        const key = await fetchApiKeyFromVault();
        request.headers.set('Authorization', `Bearer ${key}`);
        return request;
      },
    },
  ],
});

See the openapi-fetch middleware documentation for more details on middleware and additional use cases.

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:

export HH_DATA_PLANE_URL=https://honeyhive.example.com
const client = new Client({
  dataPlaneUrl: 'https://honeyhive.example.com',
});

Deprecated aliases: the serverUrl constructor option and the HH_API_URL environment variable are still accepted but 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 — particularly when debugging "is this hitting prod or staging?" or "did HH_PROJECT_API_KEY actually get picked up?".

const client = new Client({ verbose: true });
// Data plane URL: https://api.dp1.us.honeyhive.ai
// Project API key: hh_****5Qrg
// Package: @honeyhive/api-client v1.0.0
HH_VERBOSE=true node my-script.js

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 API key is masked so only a recognized key prefix and the last 4 characters are shown; anything else is replaced with asterisks.