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

@xiaoliyo/pi-ai

v0.84.2

Published

Unified LLM API with automatic model discovery and provider configuration

Readme

@xiaoliyo/pi-ai

Unified LLM API for the pi coding agent: protocol implementations, token/cost tracking, and a runtime Models collection. There is no built-in provider catalog — providers are user-configured endpoints (baseUrl + API key + protocol), typically created with /connect in the coding-agent TUI and stored in <agentDir>/models.json.

Installation

npm install @xiaoliyo/pi-ai

Quick Start

Build a provider from a configured endpoint:

import { createModels, endpointProvider } from "@xiaoliyo/pi-ai";

const models = createModels();
models.setProvider(
	endpointProvider({
		id: "my-relay",
		name: "My Relay",
		baseUrl: "https://relay.example.com/v1",
		api: "openai-completions",
		apiKey: process.env.RELAY_API_KEY,
		models: [
			{
				id: "gpt-test",
				name: "GPT Test",
				api: "openai-completions",
				provider: "my-relay",
				baseUrl: "https://relay.example.com/v1",
				reasoning: false,
				input: ["text"],
				cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
				contextWindow: 128000,
				maxTokens: 16384,
			},
		],
	}),
);

const model = models.getModel("my-relay", "gpt-test")!;
const response = await models.completeSimple(model, {
	messages: [{ role: "user", content: "Hello", timestamp: Date.now() }],
});

Protocols

Three protocols are supported:

  • openai-completions — OpenAI chat completions
  • openai-responses — OpenAI Responses API
  • anthropic-messages — Anthropic Messages API

Each protocol module exports stream, streamSimple, and lazy wrappers (anthropicMessagesApi(), openAICompletionsApi(), openAIResponsesApi()). Compatibility quirks (thinking formats, session affinity, cache markers) are auto-detected from the endpoint baseUrl and can be overridden per endpoint or per model through compat.

Model Discovery

Endpoints that expose GET {baseUrl}/models can be probed:

import { discoverEndpointModels } from "@xiaoliyo/pi-ai";

const models = await discoverEndpointModels({
	api: "openai-completions",
	baseUrl: "https://relay.example.com/v1",
	apiKey: process.env.RELAY_API_KEY,
});

Imported models get metadata from the hand-maintained known-models.ts table (context window, max tokens, reasoning, input modalities); unknown ids fall back to conservative defaults and cost zero until edited.

Auth

API keys only. No OAuth. A provider's auth.apiKey resolves the configured key (a models.json literal, $ENV_VAR interpolation, or !command execution); keyless local servers (llama.cpp, vLLM) simply carry no auth.

Global API Dispatch

api-registry.ts (exported from the package root) provides registerApiProvider, getApiProvider, unregisterApiProviders, registerFauxProvider, and the global stream/streamSimple/complete/ completeSimple functions. The three built-in protocols are pre-registered; registerFauxProvider() is the test double used by the coding-agent harness.

Images

The ImagesModels collection and createImagesProvider remain available for extensions that register image APIs (registerImagesApiProvider). No built-in image provider or catalog ships with the package.

Links

  • packages/coding-agent — the CLI/TUI that uses this package; run /connect to add endpoints.
  • docs/plans/2026-07-29-user-endpoints-design.md — the design that replaced the built-in provider catalog.