npm install @hone/sdk and configure it once at startup.
init
Configure the SDK with your API key. Call it once, early, before any other Hone call.endpoint to target a non-default base URL, such as a local stack:
Load the key from the environment rather than hard-coding it:
init(process.env.HONE_API_KEY!). See Authentication.Deployment stage (dev / staging / prod)
Tag every event from a process with its deployment stage so the dashboard can separate real production traffic from dev and staging. The Stage filter on the reliability scorecard, cost views, and triage all read it, and the scorecard defaults to production so dev noise never skews your reliability numbers. Set it once atinit, or per-deploy from the HONE_ENV environment variable:
The value is written to
metadata.environment on every event and canonicalized case-insensitively at write time: prod / PROD / prd → production, stg → staging, local / development → dev. Any other value is kept as-is (lowercased), so a custom stage like qa is never folded into the wrong bucket. The explicit init option wins over HONE_ENV.
Leave both unset and no stage tag is written — the scorecard then shows a “Tag traffic” banner. You can also set the stage on an individual turn with
interaction.setProperty("environment", "staging"), which overrides the process-wide value.begin and end
begin() opens an interaction for a single agent turn and returns an object you close with end(). Latency is captured automatically from the time between the two calls.
begin options
end arguments
Mark a failed turn so it surfaces in error analytics:
track
track() records a completed turn in a single call. Reach for it when you already have both the input and the output and do not need to hold an interaction open.
Multi-tenant (customerId)
When one agent serves several of your own customers, passcustomerId so each session and event is scoped to the downstream tenant it belongs to. The end-user’s identity becomes the pair (customerId, userId), and the dashboard can filter and roll up per customer.
customerId is a first-class field — pass it as the option, not via setProperty, so per-customer scoping and rollups work. It is stamped on the session and every event of the turn. Omit it entirely for single-tenant agents.Conversation grouping
A conversation is a series of turns between one user and your agent. Pass the sameconversationId across track() calls to thread them together, so the dashboard shows them as one exchange under User Stories.
identify
identify() attaches traits to a user id. Traits enrich the user profile in the dashboard and become dimensions you can filter and segment on. Keep the id pseudonymous.
setProperty and setProperties
Within an open interaction, attach custom properties such as the model used, token counts, or cost. These ride along on the event and power metadata-driven charts and filters.setProperty for a single key and setProperties to attach several at once. Define the corresponding keys under Settings → Metadata Keys so they become selectable dimensions in the dashboard.
Full example
To capture MCP tool, resource, and prompt calls automatically, see MCP.