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

@apertis/agent

v0.1.0

Published

Agent runtime for Apertis — multi-step tool loops, stop conditions, streaming, approval, and real measured cost. Drop-in shape for @openrouter/agent.

Readme

@apertis/agent

Agent runtime for Apertis — multi-step tool loops, stop conditions, streaming, human-in-the-loop approval, and measured cost control. Drop-in shape for @openrouter/agent, over the Apertis OpenAI-compatible API.

Why

callModel runs the whole agent loop for you: send messages → the model calls tools → execute them → feed results back → repeat, until a stop condition fires or the model stops calling tools. You write tools; the SDK handles the loop, validation, streaming, and state.

The differentiator: maxCost stops on real measured spend, not a token estimate.

Install

npm install @apertis/agent zod
export APERTIS_API_KEY=sk-your-key

Quickstart

import { callModel, tool, stepCountIs, maxCost, hasToolCall } from "@apertis/agent";
import { z } from "zod";

const getWeather = tool({
  name: "get_weather",
  description: "Get the weather for a city",
  inputSchema: z.object({ city: z.string() }),
  execute: async ({ city }) => ({ city, tempC: 21 }),
});

const result = callModel({
  model: "claude-sonnet-4-6",
  input: "What's the weather in Taipei? Then say done.",
  tools: [getWeather],
  stopWhen: [stepCountIs(10), maxCost(0.5), hasToolCall("done")], // OR — any one stops the loop
});

console.log(await result.getText());
console.log("steps:", (await result.getResponse()).steps.length);
console.log("cost: $", (await result.getResponse()).cost);

Streaming

const result = callModel({ model: "gpt-5.2", input: "Write a haiku." });
for await (const delta of result.getTextStream()) process.stdout.write(delta);

Also: getReasoningStream(), getToolCallsStream(), getToolStream(), getNewMessagesStream(), getFullResponsesStream().

Stop conditions

| Condition | Stops when | |---|---| | stepCountIs(n) | the loop has run n steps | | maxTokensUsed(n) | cumulative total tokens reach n | | maxCost(usd) | measured cumulative cost reaches usd | | hasToolCall(name) | the model calls the named tool | | finishReasonIs(reason) | the latest finish_reason matches |

stopWhen combines conditions with OR. With no stopWhen, a stepCountIs(20) backstop applies; an absolute 100-step cap always holds.

How maxCost measures cost

  1. If the API returns usage.cost inline, it is used directly.
  2. Otherwise the SDK reads the used_quota_usd delta from /v1/token/usage after each step (one lightweight GET; enabled only when maxCost is set).

If cost can't be measured for a step, maxCost stops the loop conservatively rather than risk overspend.

Tool approval (human-in-the-loop)

import { InMemoryStateAccessor } from "@apertis/agent";

const state = new InMemoryStateAccessor(); // bring your own (Redis/DB/file) for production

const deleteFile = tool({
  name: "delete_file",
  inputSchema: z.object({ path: z.string() }),
  execute: async ({ path }) => `deleted ${path}`,
  requireApproval: true,
});

const run = callModel({ model: "m", input: "clean up /tmp", tools: [deleteFile], state });
if (await run.requiresApproval()) {
  const pending = await run.getPendingToolCalls();
  // ... ask a human ...
  const resumed = callModel({
    model: "m", input: "clean up /tmp", tools: [deleteFile], state,
    approveToolCalls: [pending[0].id], // or rejectToolCalls
  });
  console.log(await resumed.getText());
}

State persistence is client-side: implement StateAccessor (load/save) over Redis, a database, or files to survive process restarts. Apertis stores no agent state server-side.

Configuration

import { createCallModel } from "@apertis/agent";
const callModel = createCallModel({ apiKey: "sk-...", baseURL: "https://api.apertis.ai/v1" });

Key precedence: opts.apiKeyAPERTIS_API_KEYcreateCallModel config.

Format converters

fromChatMessages / toChatMessage (native) and fromClaudeMessages / toClaudeMessage bridge Anthropic Messages-format history into the chat-completions format the loop uses.

License

Apache-2.0