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

@instantapihq/client

v0.1.0

Published

Client SDK for InstantAPI - Run AI agents with an API

Downloads

11

Readme

@instantapihq/client

The official client SDK for InstantAPI — Run AI agents with an API.

Installation

npm install @instantapihq/client
# or
yarn add @instantapihq/client
# or
pnpm add @instantapihq/client

Quick Start

import InstantAPI from '@instantapihq/client';

const api = new InstantAPI({ apiKey: 'ik_your_key' });

// Run any deployed agent with one line
const { result } = await api.run('your-agent-id', { 
  prompt: 'What is the capital of France?' 
});

console.log(result);
// { response: 'The capital of France is Paris.' }

Usage

Initialize the Client

import InstantAPI from '@instantapihq/client';

// With API key (recommended)
const api = new InstantAPI({ 
  apiKey: 'ik_your_key' 
});

// Or use environment variable INSTANT_API_KEY
const api = new InstantAPI();

// Custom configuration
const api = new InstantAPI({
  apiKey: 'ik_your_key',
  baseUrl: 'https://api.instantapi.co', // default
  timeout: 30000, // 30 seconds default
});

Run an Agent

// Simple usage - just get the result
const { result } = await api.run('agent-id', { 
  prompt: 'Hello!' 
});

// Full response with logs and timing
const response = await api.run('agent-id', { data: 'test' });
console.log(response.result);     // Your agent's return value
console.log(response.logs);       // Console output from your agent
console.log(response.durationMs); // Execution time in ms

// With TypeScript generics for typed results
interface ChatResponse {
  response: string;
  model: string;
}

const { result } = await api.run<ChatResponse>('chatbot', { 
  prompt: 'Hi!' 
});
console.log(result.response); // TypeScript knows this is a string

Create an Agent

const endpoint = await api.create({
  code: `
    async function handler(input) {
      const response = await fetch('https://api.openai.com/v1/chat/completions', {
        method: 'POST',
        headers: {
          'Authorization': \`Bearer \${input.apiKey}\`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          model: 'gpt-4o-mini',
          messages: [{ role: 'user', content: input.prompt }]
        })
      });
      const data = await response.json();
      return { response: data.choices[0].message.content };
    }
  `,
  language: 'javascript',
  name: 'my-chatbot',
  description: 'A simple chatbot agent',
  ttlHours: 720, // 30 days
});

console.log(endpoint.url);
// https://api.instantapi.co/run/cmiplsu200013w2qx

// Now run it
const { result } = await api.run(endpoint.id, { 
  apiKey: 'sk-...', 
  prompt: 'Hello!' 
});

List Your Agents

const endpoints = await api.list();

for (const endpoint of endpoints) {
  console.log(`${endpoint.name}: ${endpoint.url}`);
}

Delete an Agent

await api.delete('agent-id');

Error Handling

import InstantAPI, { InstantAPIError } from '@instantapihq/client';

try {
  const { result } = await api.run('agent-id', { prompt: 'Hello' });
} catch (error) {
  if (error instanceof InstantAPIError) {
    console.error('API Error:', error.message);
    console.error('Status:', error.statusCode);
    console.error('Response:', error.response);
  } else {
    console.error('Unknown error:', error);
  }
}

Environment Variables

The SDK supports these environment variables:

| Variable | Description | |----------|-------------| | INSTANT_API_KEY | Your API key (alternative to passing in constructor) | | INSTANT_API_BASE_URL | Custom API base URL |

Examples

OpenAI Chatbot

const { result } = await api.run('openai-chatbot', {
  apiKey: process.env.OPENAI_API_KEY,
  prompt: 'Explain quantum computing',
  model: 'gpt-4o-mini'
});

console.log(result.response);

Image Generation

const { result } = await api.run('image-generator', {
  apiKey: process.env.OPENAI_API_KEY,
  prompt: 'A futuristic city at sunset',
  size: '1024x1024'
});

console.log(result.imageUrl);

Web Scraper

const { result } = await api.run('web-scraper', {
  url: 'https://example.com'
});

console.log(result.title);
console.log(result.links);

License

MIT