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

@byteflyo-agent/sdk

v1.1.1

Published

Zero-dependency TypeScript/JavaScript SDK for the Agent API Anthropic-compatible contract

Readme

Agent API TypeScript SDK

npm version License: MIT

Official, zero-runtime-dependency TypeScript/JavaScript client for the Byteflyo Agent API.

This SDK implements the stable customer subset of the Anthropic-compatible OpenAPI contract. It provides fully-typed models, messages, Server-Sent Events (SSE) streaming, cooperative cancellation, timeouts, and bounded retries.

  • Fast & Lightweight: Zero external runtime dependencies. Built on native fetch and Web Streams.
  • Secure: Completely prevents logging of API keys, request content, and raw HTTP response bodies.
  • Isomorphic: Runs in Node.js 20+, Edge environments, and the browser.

📦 Install

npm install @byteflyo-agent/sdk

🚀 Quick Start

import { AgentApi, apiKey } from "@byteflyo-agent/sdk";

// 1. Initialize the client
const client = new AgentApi({
  apiKey: apiKey(process.env.API_KEY!),
  // baseUrl defaults to https://aiagent-backend.byteflyo.com
});

// 2. Discover available models
const models = await client.listModels();
console.log("Using model:", models.items[0]?.name);

// 3. Send a message
const response = await client.sendMessage({
  model: models.items[0]!.name,
  max_tokens: 256,
  messages: [{ role: "user", content: "Hello, world!" }],
});

console.log(response.content);

⚡ Streaming

The SDK supports parsing Anthropic-compatible Server-Sent Events (SSE).

streamMessage() returns an iterable stream and also supports an onEvent callback. Iteration automatically handles backpressure.

const abortController = new AbortController();

const stream = client.streamMessage(
  {
    model: "claude-opus-5",
    max_tokens: 128,
    messages: [{ role: "user", content: "Write a poem about the sea." }],
  },
  {
    signal: abortController.signal, // For cancellation
  },
);

for await (const event of stream) {
  if (
    event.type === "content_block_delta" &&
    event.delta.type === "text_delta"
  ) {
    process.stdout.write(event.delta.text);
  }

  if (event.type === "message_stop") {
    break;
  }
}

🛡️ Reliability & Errors

Bounded Retries

To ensure idempotent safety and prevent accidental double-billing, message POST requests and active streams are never automatically retried.

However, safe requests like GET /v1/account/models will automatically retry on transient network failures, timeouts, and HTTP status codes 408, 429, 500, 502, 503, and 504. Retries use capped exponential backoff and respect HTTP Retry-After headers.

You can configure retry limits (default 2, max 5):

const client = new AgentApi({
  apiKey: apiKey("..."),
  maxRetries: 3,
  timeoutMs: 30_000,
});

Typed Error Handling

All errors thrown by the SDK are structured and extend from native Error:

  • AgentApiError: Server returned a structured HTTP API error (e.g., Auth, Rate Limit). Contains status, type, code, and requestId.
  • AgentApiStreamError: Stream cleanly parsed a terminal error event sent from the server mid-generation.
  • AgentApiTimeoutError: Request exceeded timeoutMs.
  • AgentApiConnectionError: Network failure, DNS issue, or unparseable JSON/SSE.

🔗 Links

(Note: Replace the GitHub URL above with your actual repository URL before finalizing).