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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@abstraxn/chat-ai

v0.0.1

Published

Abstraxn ChatAI package for Simple and efficient communication with ChatAI API

Readme

ChatAI

Overview

The Abstraxn ChatAI SDK is a simple and efficient SDK for communicating with the ChatAI API. This SDK provides easy-to-use methods for both streaming and non-streaming chat interactions.

Installation

npm install @abstraxn/chat-ai

Or using yarn package manager:

yarn add @abstraxn/chat-ai

Quick Start

import { ChatAIClient } from "@abstraxn/chat-ai";

const client = new ChatAIClient({
  apiKey: "your-api-key-here",
});

// Simple chat
const response = await client.chat("What is machine learning?");
console.log(response.response);

Features

  • Simple API - Easy to use with minimal configuration
  • Streaming Support - Real-time streaming responses with Server-Sent Events
  • Session Management - Maintain conversation context across requests
  • CORS Support - Configurable headers for cross-origin requests
  • TypeScript Support - Full type definitions included
  • Error Handling - Comprehensive error handling with detailed messages
  • Custom Headers - Support for additional HTTP headers

Usage Examples

Basic Chat (Non-Streaming)

import { ChatAIClient } from "@abstraxn/chat-ai";

const client = new ChatAIClient({
  apiKey: "your-api-key",
});

async function basicChat() {
  try {
    const response = await client.chat("What is artificial intelligence?");
    console.log("AI Response:", response.response);
    console.log("Session ID:", response.sessionId);
  } catch (error) {
    console.error("Error:", error.message);
  }
}

basicChat();

Streaming Chat

import { ChatAIClient } from "@abstraxn/chat-ai";

const client = new ChatAIClient({
  apiKey: "your-api-key",
});

async function streamingChat() {
  try {
    const stream = await client.chatStream("Explain deep learning in detail");

    for await (const chunk of stream) {
      if (chunk.type === "content") {
        process.stdout.write(chunk.content); // Print streaming content
      }
      if (chunk.type === "done") {
        console.log("\n[Stream complete]");
      }
    }
  } catch (error) {
    console.error("Streaming error:", error.message);
  }
}

streamingChat();

Session Management

import { ChatAIClient } from "@abstraxn/chat-ai";

const client = new ChatAIClient({ apiKey: "your-api-key" });

async function conversation() {
  const sessionId = "user-session-123";

  // First message
  const response1 = await client.chat("Hello, my name is John", {
    sessionId: sessionId,
  });
  console.log("AI:", response1.response);

  // Follow-up message (AI will remember the conversation)
  const response2 = await client.chat("What is my name?", {
    sessionId: sessionId,
  });
  console.log("AI:", response2.response);
}

Custom Headers and CORS

const client = new ChatAIClient({
  apiKey: "your-api-key",
  origin: "https://my-frontend.com",
  headers: {
    "X-Request-ID": "abc123",
    "X-Client-Version": "1.0.0",
  },
});

Error Handling

try {
  const response = await client.chat("Tell me about AI");
  console.log(response.response);
} catch (error) {
  if (error.status) {
    console.error(`API Error ${error.status}:`, error.message);
  } else {
    console.error("Network Error:", error.message);
  }
}

API Reference

ChatAIClient

Constructor

new ChatAIClient(config);

Config Options:

  • apiKey (required): Your ChatAI API key
  • timeout (optional): Request timeout in milliseconds (default: 30000)
  • origin (optional): Origin header for CORS (default: *)
  • headers (optional): Additional custom headers

Methods

chat(query, options)

Send a chat message and get a complete response.

Parameters:

  • query (string): The message to send
  • options (object, optional):
    • sessionId (string, optional): Session ID for conversation continuity
    • stream (boolean, optional): Force non-streaming mode (default: false)

Returns: Promise

chatStream(query, options)

Send a chat message and get a streaming response.

Parameters:

  • query (string): The message to send
  • options (object, optional):
    • sessionId (string, optional): Session ID for conversation continuity

Returns: AsyncGenerator

Types

ChatResponse

interface ChatResponse {
  error: boolean;
  sessionId: string;
  response: string;
  outOfContext?: boolean;
}

ChatChunk

interface ChatChunk {
  type: "session" | "content" | "done" | "error";
  sessionId?: string;
  content?: string;
  timestamp?: string;
  timing?: {
    total: number;
  };
  outOfContext?: boolean;
  message?: string;
}