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

lithio

v0.1.2

Published

The official Node.js/TypeScript SDK for the Lithio API

Readme

Lithio Node.js/TypeScript SDK

The official Node.js/TypeScript SDK for the Lithio API, designed with an Anthropic/OpenAI-style interface.

Installation

npm install lithio

Or using yarn:

yarn add lithio

Or using pnpm:

pnpm add lithio

Usage

Basic Usage

import { Lithio } from 'lithio';

// Initialize the client
const client = new Lithio({
  apiKey: 'your-api-key',
  baseURL: 'https://api.example.com'
});

// Add a query
const response = await client.add({
  query: 'This is an example query',
  space: 'my-space',
  properties: { custom: 'property' }
});

console.log(response.request); // "processing"

// Search
const results = await client.search({
  query: 'search query',
  limit: 10,
  space: 'my-space'
});

console.log(results.results);

// Pretty print search results
console.log(client.prettyPrintSearchResults(results));

Using Environment Variables

You can set the API key via the LITHIO_API_KEY environment variable:

export LITHIO_API_KEY=your-api-key
import { Lithio } from 'lithio';

// Will automatically use LITHIO_API_KEY from environment
const client = new Lithio();

TypeScript Support

This SDK is written in TypeScript and provides full type definitions:

import { Lithio, SearchResponse } from 'lithio';

const client = new Lithio();

const results: SearchResponse = await client.search({
  query: 'example'
});

API Reference

new Lithio(options?)

Creates a new Lithio client instance.

Parameters:

  • options.apiKey (string, optional): Your Lithio API key. If not provided, will use LITHIO_API_KEY environment variable.
  • options.baseURL (string, optional): Base URL for the API (default: "http://localhost:8000")
  • options.timeout (number, optional): Request timeout in milliseconds (default: 30000)

Throws:

  • Error: If neither apiKey nor LITHIO_API_KEY environment variable is set

client.add(options)

Add a query to the system.

Parameters:

  • options.query (string, required): The query string to add
  • options.space (string, optional): Optional space identifier
  • options.properties (object, optional): Optional properties to include

Returns:

  • Promise<AddResponse>: Response containing the request status

Example:

const response = await client.add({
  query: 'example query',
  space: 'my-space',
  properties: { key: 'value' }
});

client.search(options)

Search for results.

Parameters:

  • options.query (string, required): The search query string
  • options.limit (number, optional): Maximum number of results (default: 5)
  • options.space (string, optional): Optional space identifier
  • options.properties (object, optional): Optional properties to include

Returns:

  • Promise<SearchResponse>: Response containing the search results

Example:

const results = await client.search({
  query: 'search query',
  limit: 10
});

client.prettyPrintSearchResults(response)

Pretty print search results as formatted JSON.

Parameters:

  • response (SearchResponse): The search response to format

Returns:

  • string: Formatted JSON string

Example:

const results = await client.search({ query: 'example' });
console.log(client.prettyPrintSearchResults(results));

Error Handling

The SDK throws errors for HTTP failures. Handle them like this:

import { Lithio } from 'lithio';

const client = new Lithio();

try {
  const response = await client.add({ query: 'example' });
} catch (error) {
  if (error instanceof Error) {
    if (error.message.includes('401')) {
      console.error('Invalid API key');
    } else {
      console.error('Request failed:', error.message);
    }
  }
}

Requirements

  • Node.js >= 18.0.0
  • TypeScript >= 5.0 (optional, for TypeScript projects)

License

MIT