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

pipilot-ai-sdk

v1.0.0

Published

JavaScript SDK for PiPilot AI Chat API with multiple models, tool calling, and streaming support

Downloads

6

Readme

PiPilot AI SDK

A JavaScript/TypeScript SDK for the PiPilot AI Chat API with support for multiple models, tool calling, and streaming responses.

Installation

npm install pipilot-ai-sdk

Quick Start

Basic Chat

const PiPilotAI = require('pipilot-ai-sdk');

const ai = new PiPilotAI();

// Simple chat
const response = await ai.chat('Hello, how are you?');
console.log(response.choices[0].message.content);

TypeScript Support

import PiPilotAI, { Message, Tool } from 'pipilot-ai-sdk';

const ai = new PiPilotAI();

// Fully typed chat
const messages: Message[] = [
  { role: 'user', content: 'What is the capital of France?' }
];

const response = await ai.createChatCompletion({
  model: 'pipilot-1-chat',
  messages,
  temperature: 0.7
});

console.log(response.choices[0].message.content);

Available Models

  • pipilot-1-chat: General purpose conversational AI
  • pipilot-1-thinking: Advanced reasoning and analysis
  • pipilot-1-code: Programming and development assistance
  • pipilot-1-vision: Image analysis and understanding

Model-Specific Methods

Chat Model

const response = await ai.chat('Tell me about artificial intelligence');

Thinking Model

const response = await ai.think('Analyze the pros and cons of renewable energy');

Code Model

const response = await ai.code('Write a function to reverse a string in JavaScript');

Vision Model

const messages = [
  { role: 'user', content: 'Describe this image' },
  { role: 'user', content: [{ type: 'image_url', image_url: { url: 'https://example.com/image.jpg' } }] }
];

const response = await ai.vision(messages);

Tool Calling

The SDK supports tool calling for extending AI capabilities:

const tools = [
  {
    type: 'function',
    function: {
      name: 'get_weather',
      description: 'Get current weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string', description: 'City name' }
        },
        required: ['location']
      }
    }
  }
];

const response = await ai.chat('What is the weather like in New York?', { tools });

// Execute tool calls
if (response.choices[0].message.tool_calls) {
  const toolHandlers = {
    get_weather: async (args) => {
      // Your weather API logic here
      return { temperature: 72, condition: 'sunny' };
    }
  };

  const results = await ai.executeTools(
    response.choices[0].message.tool_calls,
    toolHandlers
  );

  console.log('Tool results:', results);
}

Streaming Responses

const response = await ai.chat('Tell me a long story', {
  stream: true,
  onChunk: (chunk) => {
    if (chunk.choices[0].delta.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
  }
});

Advanced Configuration

const ai = new PiPilotAI({
  apiUrl: 'https://custom-api-url.com/api/v1', // Custom API endpoint
  maxRetries: 5,        // Retry failed requests
  retryDelay: 2000,     // Delay between retries (ms)
  timeout: 120000       // Request timeout (ms)
});

Error Handling

try {
  const response = await ai.chat('Hello!');
  console.log(response.choices[0].message.content);
} catch (error) {
  console.error('AI request failed:', error.message);
}

Built-in Tools

The API includes several built-in tools that are handled server-side:

  • search_web: Web search functionality
  • Custom tools can be defined and executed client-side

Examples

Complete Chat with Tool Calling

const ai = new PiPilotAI();

// Define custom tools
const tools = [
  {
    type: 'function',
    function: {
      name: 'calculate',
      description: 'Perform mathematical calculations',
      parameters: {
        type: 'object',
        properties: {
          expression: { type: 'string', description: 'Math expression' }
        },
        required: ['expression']
      }
    }
  }
];

// Chat with tools
const response = await ai.chat('Calculate 25 * 15 + 7', { tools });

// Handle tool calls
if (response.choices[0].message.tool_calls) {
  const results = await ai.executeTools(
    response.choices[0].message.tool_calls,
    {
      calculate: async ({ expression }) => {
        // Simple calculator (replace with your logic)
        return eval(expression);
      }
    }
  );

  console.log('Calculation result:', results[0].output);
}

Streaming with Multiple Models

// Thinking model with streaming
await ai.think('Explain quantum computing', {
  stream: true,
  onChunk: (chunk) => {
    if (chunk.choices[0].delta.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
  }
});

// Code model for development
const codeResponse = await ai.code('Create a React component for a todo list');
console.log(codeResponse.choices[0].message.content);

API Reference

Constructor Options

  • apiUrl: Custom API base URL (default: 'https://pipilot.dev/api/v1')
  • maxRetries: Maximum retry attempts (default: 3)
  • retryDelay: Base delay between retries in ms (default: 1000)
  • timeout: Request timeout in ms (default: 60000)

Methods

  • createChatCompletion(options): Raw completion API
  • chat(messages, options): Chat with pipilot-1-chat model
  • think(messages, options): Chat with pipilot-1-thinking model
  • code(messages, options): Chat with pipilot-1-code model
  • vision(messages, options): Chat with pipilot-1-vision model
  • executeTools(toolCalls, handlers): Execute tool calls with handlers

License

ISC