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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@inference-ui/js

v1.0.0

Published

JavaScript SDK for Inference UI - browser-compatible client for web applications

Readme

@inference-ui/js

npm version License: MIT

JavaScript SDK for Inference UI - browser-compatible client for web applications without React.

Installation

npm install @inference-ui/js

Or via CDN:

<script type="module">
  import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@inference-ui/js@latest/dist/index.esm.js';
</script>

Quick Start

import { InferenceClient } from '@inference-ui/js';

// Initialize client with your API key
const client = new InferenceClient({
  apiKey: 'sk_live_xxx', // Get from https://inference-ui.dev
});

// Get current user
const user = await client.getCurrentUser();
console.log(user);

// Track events
await client.trackEvent({
  event: 'button_click',
  timestamp: Date.now(),
  data: { button: 'signup' },
});

// Query analytics
const analytics = await client.queryAnalytics({
  startDate: Date.now() - 7 * 24 * 60 * 60 * 1000, // Last 7 days
  endDate: Date.now(),
});

Features

  • Browser-Compatible - Works in all modern browsers with fetch API
  • Framework-Agnostic - Use with vanilla JS, Vue, Angular, Svelte, etc.
  • Type-Safe - Full TypeScript support with type definitions
  • Lightweight - ~5KB gzipped, zero dependencies
  • ESM & CommonJS - Supports both module formats
  • User Management - Get user info, check tier limits
  • API Key Management - Create, list, and revoke API keys
  • Event Tracking - Track events and batch operations
  • Analytics - Query usage metrics and analytics data
  • Flow Management - Create and manage UX flows

API Reference

Client Initialization

const client = new InferenceClient({
  apiKey: 'sk_live_xxx',           // Required: Your API key
  apiUrl: 'https://...',           // Optional: Custom API endpoint
  headers: { 'X-Custom': 'value' } // Optional: Custom headers
});

User Management

// Get current user
const user = await client.getCurrentUser();
// Returns: { id, email, tier, createdAt }

API Key Management

// Create new API key
const apiKey = await client.createApiKey({
  name: 'Production API',
  expiresInDays: 90, // Optional
});
// Returns: { apiKey, keyPrefix, createdAt, expiresAt }
// ⚠️ apiKey is only shown once - store it securely!

// List all API keys
const keys = await client.listApiKeys();
// Returns: [{ id, keyPrefix, name, lastUsedAt, expiresAt, revokedAt, createdAt }]

// Revoke an API key
await client.revokeApiKey('sk_live_abc1');

Event Tracking

// Track single event
await client.trackEvent({
  event: 'page_view',
  timestamp: Date.now(),
  data: { page: '/dashboard' },
});

// Track multiple events (batch)
await client.trackEvents([
  { event: 'button_click', timestamp: Date.now(), data: { button: 'submit' } },
  { event: 'form_submit', timestamp: Date.now(), data: { form: 'contact' } },
]);

Analytics

// Query analytics
const analytics = await client.queryAnalytics({
  userId: 'user_123',              // Optional: specific user
  startDate: 1704067200000,        // Required: start timestamp
  endDate: 1706745600000,          // Required: end timestamp
  metrics: ['events', 'sessions'], // Optional: specific metrics
  groupBy: 'day',                  // Optional: group by time period
});
// Returns: { metrics: {...}, breakdown: [...] }

// Get usage metrics
const usage = await client.getUsageMetrics();
// Returns: { userId, tier, eventsThisMonth, eventsLimit, ... }

Flow Management

// Get all flows
const flows = await client.getFlows();

// Get specific flow
const flow = await client.getFlow('flow_123');

// Create new flow
const newFlow = await client.createFlow('Onboarding', [
  { id: '1', component: 'WelcomeScreen' },
  { id: '2', component: 'ProfileSetup' },
]);

// Delete flow
await client.deleteFlow('flow_123');

Usage Examples

Vanilla JavaScript

<!DOCTYPE html>
<html>
<head>
  <title>Inference UI Example</title>
</head>
<body>
  <button id="trackBtn">Track Click</button>
  <div id="analytics"></div>

  <script type="module">
    import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@inference-ui/js@latest/dist/index.esm.js';

    const client = new InferenceClient({
      apiKey: 'sk_live_xxx',
    });

    // Track button clicks
    document.getElementById('trackBtn').addEventListener('click', async () => {
      await client.trackEvent({
        event: 'button_click',
        timestamp: Date.now(),
        data: { button: 'trackBtn' },
      });
      console.log('Event tracked!');
    });

    // Load analytics
    async function loadAnalytics() {
      const analytics = await client.queryAnalytics({
        startDate: Date.now() - 7 * 24 * 60 * 60 * 1000,
        endDate: Date.now(),
      });
      document.getElementById('analytics').textContent = JSON.stringify(analytics, null, 2);
    }

    loadAnalytics();
  </script>
</body>
</html>

Vue.js

<template>
  <div>
    <button @click="trackClick">Track Click</button>
    <div>{{ analytics }}</div>
  </div>
</template>

<script>
import { InferenceClient } from '@inference-ui/js';

export default {
  data() {
    return {
      client: new InferenceClient({ apiKey: process.env.VUE_APP_INFERENCE_KEY }),
      analytics: null,
    };
  },
  methods: {
    async trackClick() {
      await this.client.trackEvent({
        event: 'button_click',
        timestamp: Date.now(),
      });
    },
    async loadAnalytics() {
      this.analytics = await this.client.queryAnalytics({
        startDate: Date.now() - 7 * 24 * 60 * 60 * 1000,
        endDate: Date.now(),
      });
    },
  },
  mounted() {
    this.loadAnalytics();
  },
};
</script>

Angular

import { Component, OnInit } from '@angular/core';
import { InferenceClient } from '@inference-ui/js';

@Component({
  selector: 'app-analytics',
  template: `
    <button (click)="trackClick()">Track Click</button>
    <pre>{{ analytics | json }}</pre>
  `,
})
export class AnalyticsComponent implements OnInit {
  private client = new InferenceClient({
    apiKey: environment.inferenceApiKey,
  });
  analytics: any;

  async ngOnInit() {
    this.analytics = await this.client.queryAnalytics({
      startDate: Date.now() - 7 * 24 * 60 * 60 * 1000,
      endDate: Date.now(),
    });
  }

  async trackClick() {
    await this.client.trackEvent({
      event: 'button_click',
      timestamp: Date.now(),
    });
  }
}

Svelte

<script>
  import { InferenceClient } from '@inference-ui/js';
  import { onMount } from 'svelte';

  const client = new InferenceClient({
    apiKey: import.meta.env.VITE_INFERENCE_KEY,
  });

  let analytics = null;

  async function trackClick() {
    await client.trackEvent({
      event: 'button_click',
      timestamp: Date.now(),
    });
  }

  onMount(async () => {
    analytics = await client.queryAnalytics({
      startDate: Date.now() - 7 * 24 * 60 * 60 * 1000,
      endDate: Date.now(),
    });
  });
</script>

<button on:click={trackClick}>Track Click</button>
<pre>{JSON.stringify(analytics, null, 2)}</pre>

TypeScript Support

Full TypeScript support with exported types:

import type {
  InferenceConfig,
  User,
  ApiKey,
  Event,
  AnalyticsQuery,
  UsageMetrics,
} from '@inference-ui/js';

const config: InferenceConfig = {
  apiKey: 'sk_live_xxx',
};

const event: Event = {
  event: 'page_view',
  timestamp: Date.now(),
};

Error Handling

try {
  const user = await client.getCurrentUser();
} catch (error) {
  if (error.message.includes('Unauthorized')) {
    console.error('Invalid API key');
  } else if (error.message.includes('timeout')) {
    console.error('Request timed out');
  } else {
    console.error('API error:', error);
  }
}

Browser Compatibility

Works in all modern browsers that support:

  • Fetch API
  • Promises
  • ES2020 syntax

For older browsers, use polyfills:

<script src="https://cdn.jsdelivr.net/npm/whatwg-fetch@3/dist/fetch.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>

Environment Variables

# .env
INFERENCE_API_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxx

Bundle Size

  • ESM: ~5KB gzipped
  • CommonJS: ~5KB gzipped
  • Zero runtime dependencies

Links

  • npm: https://www.npmjs.com/package/@inference-ui/js
  • GitHub: https://github.com/Neureus/Inference-UI
  • Documentation: https://inference-ui.dev/docs/js-sdk
  • API Reference: https://inference-ui.dev/docs/api

License

MIT

Related Packages

  • React: npm install inference-ui-react - React hooks and components
  • Node.js: npm install @inference-ui/node - Node.js backend SDK
  • React Native: npm install inference-ui-react-native - Mobile SDK