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

@amlexiahq/node

v1.0.2

Published

Official Amlexia Node.js SDK — monitor APIs, AI providers, payments, and infrastructure with traces, latency, and provider intelligence.

Readme

@amlexiahq/node

Official Node.js SDK for Amlexia. Ship traces, latency, errors, and provider metrics from Express, Fastify, Hono, Next.js, or custom code.

npm install @amlexiahq/node

License: Proprietary — not open source. See LICENSE.
Support: [email protected]


Table of contents

Cross-SDK docs: Environment variables · Event fields


Installation

npm install @amlexiahq/node

Peer dependencies (install only what you use):

npm install express   # for @amlexiahq/node/express
npm install fastify   # for @amlexiahq/node/fastify
npm install hono      # for @amlexiahq/node/hono

Quick start

import { AmlexiaClient } from '@amlexiahq/node';

const client = new AmlexiaClient({
  sdkKey: process.env.AMLEXIA_SDK_KEY!,
  ingestUrl: process.env.AMLEXIA_INGEST_URL ?? 'https://ingest.amlexia.com',
});

client.track({
  endpoint: 'GET /api/health',
  method: 'GET',
  statusCode: 200,
  latencyMs: 8,
});

// Graceful shutdown — flushes buffered events
process.on('SIGTERM', () => void client.shutdown());

AmlexiaClient

Constructor options

new AmlexiaClient({
  sdkKey: string;              // Required — project SDK key (am_...)
  ingestUrl?: string;         // Default: https://ingest.amlexia.com
  flushIntervalMs?: number;   // Default: 5000 — auto-flush interval
  maxBatchSize?: number;      // Default: 50 — flush when buffer reaches this size
  maxRetries?: number;        // Default: 5 — retries per batch on failure
});

| Option | Default | Description | |--------|---------|-------------| | sdkKey | — | Required. From dashboard → Project → SDK key | | ingestUrl | https://ingest.amlexia.com | Base URL without trailing slash | | flushIntervalMs | 5000 | Background flush interval (ms) | | maxBatchSize | 50 | Max events per HTTP request | | maxRetries | 5 | Exponential backoff retries (cap 30s delay) |

Methods

| Method | Description | |--------|-------------| | track(event: TrackEvent): void | Queue one event (sync). Flushes early if batch is full | | flush(): Promise<void> | Send current buffer immediately | | shutdown(): Promise<void> | Stop timer, flush all remaining events |


track() fields

Required

client.track({
  endpoint: 'POST /v1/chat',  // Route or operation name
  method: 'POST',
  statusCode: 200,
  latencyMs: 430,
});

Optional (common)

client.track({
  endpoint: 'POST /v1/chat',
  method: 'POST',
  statusCode: 200,
  latencyMs: 430,
  timestamp: Math.floor(Date.now() / 1000), // Unix seconds
  provider: 'openai',
  providerCategory: 'ai',
  modelName: 'gpt-4o',
  tokensInput: 120,
  tokensOutput: 80,
  totalTokens: 200,
  costUsd: 0.0024,
  errorMessage: null,
  metadata: { plan: 'pro' },
  traceId: '...',
  spanId: '...',
  parentSpanId: '...',
  sessionId: 'sess_abc',
  userId: 'user_123',
  environment: 'production',
  releaseVersion: '1.4.0',
  serviceName: 'api',
  operationName: '/v1/chat',
  requestSizeBytes: 1024,
  responseSizeBytes: 4096,
  streamingLatencyMs: 1200,
  firstTokenLatencyMs: 180,
  cacheHit: false,
  retryCount: 0,
  isWebhook: false,
});

Full reference: Event fields.


Environment variables

| Variable | Description | |----------|-------------| | AMLEXIA_SDK_KEY | Required — SDK key | | AMLEXIA_INGEST_URL | Ingest base URL (optional) | | AMLEXIA_RELEASE | Default release on trace context | | NODE_ENV | Default environment on trace context |

See ENVIRONMENT_VARIABLES.md.


Express

import express from 'express';
import { AmlexiaClient } from '@amlexiahq/node';
import { AmlexiaMiddleware } from '@amlexiahq/node/express';

const client = new AmlexiaClient({ sdkKey: process.env.AMLEXIA_SDK_KEY! });
const app = express();

app.use(AmlexiaMiddleware(client, { serviceName: 'api' }));

app.get('/users/:id', (req, res) => {
  res.json({ ok: true });
});

app.listen(3000);

Middleware options

| Option | Default | Description | |--------|---------|-------------| | serviceName | 'api' | serviceName on tracked events |

Behavior

  • Creates trace + span per request
  • Sets response header traceparent (W3C format)
  • Normalizes paths (/users/42/users/:id)
  • Auto-detects provider from route/host hints
  • Tracks on res.finish with status and latency

Session / user headers

| Header | Attached to event | |--------|-------------------| | x-session-id | sessionId | | x-user-id | userId |


Fastify

import Fastify from 'fastify';
import { AmlexiaClient } from '@amlexiahq/node';
import { amlexiaPlugin } from '@amlexiahq/node/fastify';

const client = new AmlexiaClient({ sdkKey: process.env.AMLEXIA_SDK_KEY! });
const app = Fastify();

await app.register(amlexiaPlugin(client, { serviceName: 'api' }));

Same options and behavior as Express (serviceName, path normalization, traceparent).


Hono

import { Hono } from 'hono';
import { AmlexiaClient } from '@amlexiahq/node';
import { amlexiaHonoMiddleware } from '@amlexiahq/node/hono';

const client = new AmlexiaClient({ sdkKey: process.env.AMLEXIA_SDK_KEY! });
const app = new Hono();

app.use('*', amlexiaHonoMiddleware(client, { serviceName: 'api' }));

Next.js

Wrap App Router route handlers:

import { AmlexiaClient } from '@amlexiahq/node';
import { withAmlexia } from '@amlexiahq/node/next';

const client = new AmlexiaClient({ sdkKey: process.env.AMLEXIA_SDK_KEY! });

export const GET = withAmlexia(
  client,
  async (request) => {
    return Response.json({ ok: true });
  },
  { route: '/api/hello', serviceName: 'nextjs' },
);

withAmlexia options

| Option | Description | |--------|-------------| | route | Static route pattern for cardinality control (e.g. /api/users/[id]) | | serviceName | Default nextjs |

Tracks status, latency, and errors (including thrown exceptions → 500).


Distributed tracing

import {
  createTraceContext,
  childSpan,
  applyTraceToEvent,
} from '@amlexiahq/node/tracing';

const trace = createTraceContext({
  sessionId: 'sess_1',
  userId: 'user_1',
  environment: 'production',
  releaseVersion: process.env.AMLEXIA_RELEASE,
});

const span = childSpan(trace);

client.track(
  applyTraceToEvent(
    {
      endpoint: 'POST /internal/job',
      method: 'POST',
      statusCode: 200,
      latencyMs: 100,
    },
    span,
  ),
);

| Function | Description | |----------|-------------| | createTraceContext(partial?) | New trace id + span id; fills env from NODE_ENV / AMLEXIA_RELEASE | | childSpan(parent) | New span under parent | | applyTraceToEvent(event, ctx) | Merges trace fields into a TrackEvent |


OpenTelemetry bridge

Map OTEL spans into Amlexia events (sends via /v1/events, not a separate OTEL ingest):

import { AmlexiaClient } from '@amlexiahq/node';
import { exportOtelSpans, type OtelSpanInput } from '@amlexiahq/node/otel';

const spans: OtelSpanInput[] = [/* from your OTEL exporter */];
exportOtelSpans(client, spans);

OtelSpanInput fields: traceId, spanId, parentSpanId, name, startTimeUnixNano, endTimeUnixNano, status, attributes.


Errors and retries

| HTTP status | Behavior | |-------------|----------| | 401 | Throws Invalid SDK key (no retry) | | 4xx (other) | Throws with body (no retry) | | 5xx / network | Retries with exponential backoff |

Failed batches are re-queued to the buffer after exhausted retries.


Best practices

  1. One client per process — reuse a singleton AmlexiaClient.
  2. Call shutdown() on SIGTERM/SIGINT in servers and serverless finally blocks.
  3. Use middleware for HTTP so paths are normalized and traces are consistent.
  4. Never expose AMLEXIA_SDK_KEY in browsers — instrument backend only.
  5. Set releaseVersion via AMLEXIA_RELEASE for deploy correlation.
  6. Avoid high-cardinality endpoints — use parameterized routes, not raw URLs with IDs in middleware-covered apps.

Package exports

| Import path | Contents | |-------------|----------| | @amlexiahq/node | AmlexiaClient, types | | @amlexiahq/node/express | AmlexiaMiddleware | | @amlexiahq/node/fastify | amlexiaPlugin | | @amlexiahq/node/hono | amlexiaHonoMiddleware | | @amlexiahq/node/next | withAmlexia | | @amlexiahq/node/tracing | createTraceContext, childSpan, applyTraceToEvent | | @amlexiahq/node/otel | exportOtelSpans |


Links