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

langchain-pi-ts

v0.5.1

Published

LangChain BaseChatModel adapter for @earendil-works/pi-ai — use Pi with any provider, model and auth. Includes a native opencode/Zen chat model (no pi).

Downloads

1,188

Readme

langchain-pi-ts

A LangChain BaseChatModel adapter for @earendil-works/pi-ai. Use Pi — and any provider, model and credential it resolves — from LangChain and LangGraph, with native tool calling and streaming.

The TypeScript half of a pair. A Python twin (langchain-pi) reuses the same Pi configuration from LangChain/LangGraph in Python.

Install

npm install langchain-pi-ts @langchain/core

@langchain/core is a peer dependency — your app owns its version (^1.1.44). The package is ESM-only and requires Node >= 22.19.0 (inherited from pi-ai and pi-coding-agent).

Usage

createChat is the simplest entry — pass a provider and it routes to the right backend (opencode/opencode-go → native Zen, claude-code → native Anthropic, everything else → Pi):

import { createChat } from "langchain-pi-ts";

const free = createChat({ provider: "opencode", model: "deepseek-v4-flash-free" }); // free, no key
const go = createChat({ provider: "opencode-go", model: "glm-5", apiKey: "..." }); // subscription
const codex = createChat({ provider: "openai-codex", model: "gpt-5.3-codex-spark" }); // via Pi
const claude = createChat({ provider: "claude-code", model: "claude-sonnet-4-6" }); // Claude Code subscription

Or construct a backend directly:

import { ChatPi } from "langchain-pi-ts";

const model = new ChatPi({
  provider: "openai-codex",
  modelId: "gpt-5.3-codex-spark",
  reasoning: "minimal",
  system: "You are a helpful assistant.",
});

const res = await model.invoke("Hello!");
console.log(res.content);

Tool calling

ChatPi accepts any LangChain tool (Zod / tool()); schemas are converted to the JSON Schema pi-ai expects.

import { tool } from "@langchain/core/tools";
import { z } from "zod";

const getWeather = tool(({ city }) => `Sunny in ${city}.`, {
  name: "get_weather",
  description: "Get the weather for a city.",
  schema: z.object({ city: z.string() }),
});

const withTools = model.bindTools([getWeather]);

Streaming

for await (const chunk of await model.stream("Write a haiku.")) {
  process.stdout.write(chunk.content as string);
}

Credentials

Models and credentials resolve through pi-coding-agent's ModelRegistry / AuthStorage. Any provider authenticated in ~/.pi works with no key. ChatPi lazily builds a shared registry on first use (importing the package touches no filesystem); pass a custom one via new ChatPi({ provider, modelId, registry }), or getDefaultAuthStorage().setRuntimeApiKey(provider, key) to inject a key.

For OpenCode Zen, prefer the native ChatOpencode below.

Native opencode/Zen (no Pi)

OpenCode Zen is an OpenAI-compatible endpoint, so you don't need Pi. The langchain-pi-ts/opencode subpath ships ChatOpencode, a thin ChatOpenAI subclass pointed at it (@langchain/openai ships as a dependency).

The API key is optional: free models work with no key (anonymous, IP-rate- limited). For paid models pass a key via OPENCODE_API_KEY (env) or apiKey.

import { ChatOpencode } from "langchain-pi-ts/opencode";

const free = new ChatOpencode({ model: "deepseek-v4-flash-free" }); // no key
const paid = new ChatOpencode({ model: "glm-5" }); // OPENCODE_API_KEY or apiKey
const go = new ChatOpencode({ model: "glm-5", tier: "go" });

Free models: deepseek-v4-flash-free, big-pickle, mimo-v2.5-free, nemotron-3-super-free.

Claude Code / Anthropic subscription (no Pi)

ChatClaudeCode talks to the Anthropic Messages API (via @anthropic-ai/sdk) authenticated with the Claude Code OAuth session already on the machine (~/.claude/.credentials.json), billing requests against your Claude Code subscription — no API key. It needs the Claude Code CLI logged in once. The langchain-pi-ts/claude-code subpath ships it.

import { ChatClaudeCode } from "langchain-pi-ts/claude-code";

const chat = new ChatClaudeCode({ model: "claude-sonnet-4-6" });
const opus = new ChatClaudeCode({ model: "claude-opus-4-8", reasoning: "medium" });
// or: createChat({ provider: "claude-code", model: "claude-opus-4-8" })

Models: claude-opus-4-8, claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5. Adaptive thinking on Opus 4.8/4.7, a token budget on Sonnet 4.6 (Haiku has no reasoning). The 1M-context beta is opt-in via longContext: true; the subscription rejects long-context requests without extra credits otherwise. Tool calling and streaming work as with ChatPi.

Using a subscription OAuth session from a third-party app may violate Anthropic's terms and risk your account — see the pi-claude-code-auth README.

Notes

  • ESM + Node only. pi-ai / pi-coding-agent are ESM-only and Node-native.
  • Tool-call deltas and usage/cost metadata are preserved.

License

MIT