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

@codefionn/llmleaf-client

v0.3.1

Published

Official TypeScript/JavaScript client for the llmleaf LLM proxy.

Readme

@codefionn/llmleaf-client

TypeScript / JavaScript client for the llmleaf LLM proxy.

Speaks llmleaf's OpenAI/OpenRouter-shaped JSON over HTTP (see ../SPEC.md). Zero runtime dependencies beyond the @bufbuild/protobuf runtime, and it runs anywhere a global fetch / ReadableStream / FormData exists — Node 20+, Deno, Bun, browsers.

Install

npm install @codefionn/llmleaf-client

Example

import { LlmleafClient, Role } from "@codefionn/llmleaf-client";

const client = new LlmleafClient({
  baseUrl: "https://gateway.example.com",
  apiKey: process.env.LLMLEAF_API_KEY!,
  timeoutMs: 30_000,   // optional; 0/omitted = no timeout. Also: adminToken, fetch
});

// Non-streaming chat
const res = await client.chat({
  model: "gpt-4o-mini",
  messages: [{ role: Role.USER, content: "Say hi." }],
});
console.log(res.choices[0]?.message.content);

// Streaming chat — async iterable of chunks, stops at `data: [DONE]`
for await (const chunk of client.chatStream({
  model: "gpt-4o-mini",
  messages: [{ role: Role.USER, content: "Count to 5." }],
})) {
  process.stdout.write(chunk.choices[0]?.delta.content ?? "");
}

// Responses dialect (POST /v1/responses) — `input` is a bare string or an item array
const resp = await client.responses({
  model: "gpt-4o-mini",
  input: [{ type: "message", role: "user", content: "Say hi." }],
});

// Streaming responses — typed events, NO `[DONE]`; stops on the terminal
// response.completed / .incomplete / .failed event; unknown event types are skipped
for await (const event of client.responsesStream({
  model: "gpt-4o-mini",
  input: "Count to 5.",
})) {
  if (event.type === "response.output_text.delta") process.stdout.write(event.delta ?? "");
}

Streaming tool calls are exposed as choice.delta.toolCalls. Group fragments by the choice index and each ToolCallDelta.index; retain id / type / function name whenever present, and append every function.arguments fragment in arrival order until finishReason === FinishReason.TOOL_CALLS.

Endpoints

await client.chat(req);              // POST /v1/chat/completions
client.chatStream(req);              // stream:true, async iterable of chunks
await client.responses(req);         // POST /v1/responses (OpenAI Responses dialect)
client.responsesStream(req);         // stream:true, async iterable of typed events (no [DONE])
await client.embeddings(req);        // base64 vectors decoded to floats
await client.rerank(req);            // POST /v1/rerank; results by relevance (plain JSON)
await client.listModels({ type: "llm" });
await client.speech(req);            // -> { bytes, contentType }
await client.voices("tts-1");
await client.transcribe(file, req);  // multipart; json/verbose_json -> object, text/srt/vtt -> tr.text
await client.createBatch(req);
await client.getBatch(id);
await client.cancelBatch(id);
client.batchResults(id);             // async iterable of result lines

Free-form fields (extra, responseFormat.jsonSchema, functionDef.parameters, …) are raw JSON strings — pass JSON.stringify(obj) and the transport splices the parsed value in; extra keys merge at the top level of the request.

Errors

Any non-2xx response throws a typed ApiError:

import { ApiError } from "@codefionn/llmleaf-client";

try {
  await client.chat(req);
} catch (e) {
  if (e instanceof ApiError) console.error(e.status, e.message); // 403 "model not allowed"
}

Run the example

examples/basic.ts does chat, streaming, and a model list:

LLMLEAF_BASE_URL=https://gateway.example.com LLMLEAF_API_KEY=sk-… npx tsx examples/basic.ts

Regenerate from the proto

The generated file (src/gen/llmleaf/v1/llmleaf_pb.ts) is committed; regenerate it after the proto changes:

npm install      # fetch the @bufbuild/protoc-gen-es plugin
npm run gen      # runs scripts/gen.sh (needs protoc on PATH)

Notes

  • The wire mapping is hand-written (src/wire.ts) because protobuf-es's JSON codec emits camelCase + SCREAMING_CASE, which isn't the OpenAI wire (snake_case + lowercase tokens). The generated descriptors stay available under the gen export for reflection.
  • Decoders are lenient (extra/missing fields tolerated). No retries. chatStream / batchResults need a streaming-capable fetch. Realtime WebSocket is out of scope.