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

@teerai/sdk

v0.1.2

Published

Official TypeScript SDK for Teer API - Track and manage AI model usage

Readme

Teer TypeScript SDK

@teerai/sdk provides an SDK to interact with the Teer API. Track usage events via the SDK.

GitHub Repository

Installation

npm install @teerai/sdk

Quick Start

import { Teer } from '@teerai/sdk'

// Initialize the client with your API key
const client = new Teer('your-api-key')

// Send usage data
await client.ingest.send({
  provider: 'anthropic',
  model: 'claude-3-haiku-20240307',
  function_id: 'my-function',
  usage: {
    input: 1000,
    output: 2000,
  },
})

Cache usage

  • Optionally include per provider cache usage
import { Teer } from '@teerai/sdk'

// Initialize the client with your API key
const client = new Teer('your-api-key')

// Send usage data
await client.ingest.send({
  provider: 'anthropic',
  model: 'claude-3-haiku-20240307',
  function_id: 'my-function',
  usage: {
    input: 1000,
    output: 2000,
    cache: {
      anthropic: {
        cache_creation_input_tokens: 750,
        cache_read_input_tokens: 0,
      },
    },
  },
})

Import and Usage

ESM

import { Teer } from '@teerai/sdk'

// Initialize the client with your API key
const client = new Teer('your-api-key')

CommonJS

const { Teer } = require('@teerai/sdk')

// Initialize the client with your API key
const client = new Teer('your-api-key')

API Resources

Ingest

The ingest resource allows you to send usage data to Teer. This resource automatically uses the track.teer.ai API endpoint.

await client.ingest.send({
  provider: 'anthropic',
  model: 'claude-3-haiku-20240307',
  function_id: 'my-function',
  usage: {
    input: 1000,
    output: 2000,
  },
})

Advanced Usage

Custom Base URLs

You can specify a custom base URL when initializing the client:

const client = new Teer('your-api-key', { baseURL: 'https://custom-api.example.com' })

Default Request Configuration

You can set default request configuration options when initializing the client:

const client = new Teer('your-api-key', {
  timeoutMs: 8000, // 8 second default timeout
  maxRetries: 2, // Maximum 2 retries by default
  retryDelayMs: 500, // Start with 500ms delay by default
})

These defaults will be used for all requests made through the client, but can be overridden at the individual request level:

// Uses client default configuration
await client.ingest.send(data)

// Overrides just the timeout for this specific request
await client.ingest.send(data, { timeoutMs: 3000 })

// Overrides all request configuration options
await client.ingest.send(data, {
  timeoutMs: 5000,
  maxRetries: 5,
  retryDelayMs: 300,
})

The configuration options are applied with the following precedence (highest to lowest):

  1. Options provided directly to the method call
  2. Options set in the client constructor
  3. Built-in default values

Error Handling

The client implements robust error handling with custom error classes that provide detailed information about what went wrong.

Error Types

  • TeerError: Base class for all Teer-related errors
  • TeerAPIError: Thrown when the API returns an error response
  • TeerTimeoutError: Thrown when a request times out
  • TeerNetworkError: Thrown when there's a network connectivity issue

Handling Errors

import { Teer, TeerAPIError, TeerTimeoutError, TeerNetworkError } from '@teerai/sdk'

// Initialize the client
const client = new Teer('your-api-key')

try {
  await client.ingest.send(data)
} catch (error) {
  if (error instanceof TeerAPIError) {
    // Handle API errors (400, 401, 403, 404, 429, 500, etc.)
    console.error(`API Error (${error.status}): ${error.message}`)

    if (error.isRateLimitError) {
      // Handle rate limiting (429)
      console.error('Rate limit exceeded. Try again later.')
    } else if (error.isClientError) {
      // Handle client errors (4xx)
      console.error('Client error:', error.data)
    } else if (error.isServerError) {
      // Handle server errors (5xx)
      console.error('Server error. Please try again later.')
    }
  } else if (error instanceof TeerTimeoutError) {
    // Handle timeout errors
    console.error(`Request timed out after ${error.timeoutMs}ms`)
  } else if (error instanceof TeerNetworkError) {
    // Handle network connectivity issues
    console.error('Network error:', error.message)
  } else {
    // Handle other errors
    console.error('Error:', error.message)
  }
}

Automatic Retries

The client automatically retries requests that fail due to:

  • Network errors
  • Timeouts
  • Server errors (5xx)
  • Rate limiting (429)

You can customize retry behavior with options:

await client.ingest.send(data, {
  timeoutMs: 5000, // 5 second timeout (default: 10000)
  maxRetries: 5, // Maximum 5 retries (default: 3)
  retryDelayMs: 500, // Start with 500ms delay (default: 300)
})

Module Compatibility

This package is configured to work in various JavaScript environments:

  • Node.js: Both ESM and CommonJS formats are supported
  • Modern browsers: Compatible with modern browsers through bundlers
  • Edge runtimes: Works in Cloudflare Workers, Vercel Edge Functions, etc.
  • Bundlers: Optimized for Vite, Webpack, Rollup, and other modern bundlers

Package Format

The package is published as:

  • ESM: dist/index.js (primary format, used by import statements)
  • CommonJS: dist/index.cjs (for compatibility, used by require() statements)
  • TypeScript declarations: dist/index.d.ts (for TypeScript projects)

The package uses named exports for better tree-shaking and compatibility with modern tooling.