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

@patternzones/koine-sdk

v2.3.0

Published

TypeScript SDK for Koine gateway

Readme

@patternzones/koine-sdk

TypeScript SDK for Koine — the HTTP gateway for Claude Code CLI.

Running the Gateway

docker run -d -p 3100:3100 \
  -e CLAUDE_CODE_GATEWAY_API_KEY=your-key \
  -e ANTHROPIC_API_KEY=your-anthropic-api-key \
  ghcr.io/pattern-zones-co/koine:latest

See Docker Deployment for version pinning and production setup.

Installation

bun add @patternzones/koine-sdk
# or: npm install @patternzones/koine-sdk

Quick Start

import { createKoine } from '@patternzones/koine-sdk';

const koine = createKoine({
  baseUrl: 'http://localhost:3100',
  authKey: 'your-api-key',
  timeout: 300000, // 5 minutes
});

const result = await koine.generateText({
  prompt: 'Hello, how are you?',
});

console.log(result.text);

Features

  • Text GenerationgenerateText() for simple prompts
  • StreamingstreamText() with ReadableStream (async iterable)
  • Structured OutputgenerateObject() with Zod schema validation
  • Tool RestrictionsallowedTools parameter to limit CLI tool access
  • Streaming Structured OutputstreamObject() with partial object streaming
  • Cancellation — AbortSignal support for all requests
  • Type Safety — Full TypeScript types for all requests and responses
  • Error HandlingKoineError class with typed error codes

API

Client Factory

const koine = createKoine(config);

Creates a client instance with the given configuration. The config is validated once at creation time.

Methods

| Method | Description | |--------|-------------| | koine.generateText(options) | Generate text from a prompt | | koine.streamText(options) | Stream text via Server-Sent Events | | koine.generateObject(options) | Extract structured data using a Zod schema | | koine.streamObject(options) | Stream structured data with partial updates |

Types

| Type | Description | |------|-------------| | KoineConfig | Client configuration (baseUrl, authKey, timeout, model) | | KoineClient | Client interface returned by createKoine() | | KoineUsage | Token usage stats (inputTokens, outputTokens, totalTokens) | | KoineStreamResult | Streaming result with ReadableStream and promises | | KoineStreamObjectResult<T> | Streaming object result with partialObjectStream | | KoineError | Error class with typed code property | | KoineErrorCode | Union type of all possible error codes |

Error Handling & Retries

The SDK does not automatically retry failed requests. When the gateway returns 429 Too Many Requests (concurrency limit exceeded), your application should implement retry logic:

async function generateWithRetry(prompt: string, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await koine.generateText({ prompt });
    } catch (error) {
      if (error instanceof KoineError && error.code === 'CONCURRENCY_LIMIT_ERROR') {
        await new Promise(r => setTimeout(r, 1000 * (i + 1))); // Exponential backoff
        continue;
      }
      throw error;
    }
  }
  throw new Error('Max retries exceeded');
}

Documentation

See the SDK Guide for:

  • Configuration options
  • Streaming examples
  • Structured output with Zod
  • Tool restrictions
  • Error handling
  • Multi-turn conversations

Examples

Runnable examples are available in the examples/ directory. Run from the SDK directory using the npm scripts (which load .env from the project root):

cd packages/sdks/typescript
bun run example:hello         # Basic text generation
bun run example:recipe        # Structured output with Zod
bun run example:stream        # Real-time streaming
bun run example:stream-object # Streaming structured output
bun run example:conversation  # Multi-turn sessions

License

Dual-licensed under AGPL-3.0 or commercial license.