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

@ottocode/api

v0.1.320

Published

Type-safe API client for ottocode server

Downloads

8,742

Readme

@ottocode/api

Type-safe API client for ottocode server, generated from OpenAPI specification using @hey-api/openapi-ts.

Features

  • Type-safe SDK - Fully typed API functions generated from OpenAPI spec
  • 🚀 Axios-powered - Uses Axios for reliable HTTP requests with interceptors support
  • 📦 Tree-shakeable - Import only what you need
  • 🔄 SSE Streaming - Built-in support for Server-Sent Events
  • Runtime validation - Optional schema validation with generated schemas
  • 🎯 Auto-generated - Always in sync with the server API

Installation

npm install @ottocode/api axios
# or
bun add @ottocode/api axios
# or
pnpm add @ottocode/api axios

Quick Start

import { client, ask, listSessions } from '@ottocode/api';

// Configure the client once at app startup
client.setConfig({
  baseURL: 'http://localhost:3000',
});

// Make type-safe API calls
const response = await ask({
  body: {
    prompt: 'Hello, AI!',
    sessionId: 'optional-session-id',
  },
});

if (response.error) {
  console.error('Error:', response.error);
} else {
  console.log('Response:', response.data);
}

// List all sessions
const sessions = await listSessions();
console.log('Sessions:', sessions.data);

Configuration

Basic Configuration

import { client } from '@ottocode/api';

client.setConfig({
  baseURL: 'http://localhost:3000',
  // Optional: configure timeout
  timeout: 30000,
});

Advanced Configuration with Interceptors

import { client } from '@ottocode/api';

// Access the underlying Axios instance
client.instance.interceptors.request.use((config) => {
  // Add authentication token
  config.headers.set('Authorization', `Bearer ${getToken()}`);
  return config;
});

client.instance.interceptors.response.use(
  (response) => response,
  (error) => {
    console.error('API Error:', error);
    return Promise.reject(error);
  }
);

Authentication

import { client } from '@ottocode/api';

// Configure auth token (will be added to requests that require auth)
client.setConfig({
  baseURL: 'http://localhost:3000',
  auth: () => `Bearer ${getToken()}`,
});

API Reference

All SDK functions are auto-generated and fully typed. Import them directly:

import {
  // Session management
  listSessions,
  createSession,
  subscribeSessionStream,
  
  // Messages
  listMessages,
  createMessage,
  
  // Ask endpoint
  ask,
} from '@ottocode/api';

SSE Streaming

For endpoints that support Server-Sent Events:

import { createSSEStream } from '@ottocode/api';

const stream = createSSEStream({
  url: 'http://localhost:3000/v1/sessions/session-123/stream',
  onMessage: (event) => {
    console.log('Event:', event);
  },
  onError: (error) => {
    console.error('Stream error:', error);
  },
});

// Close the stream when done
stream.close();

Error Handling

import { ask, isApiError, handleApiError } from '@ottocode/api';

const response = await ask({
  body: { prompt: 'Hello' },
});

if (response.error) {
  if (isApiError(response.error)) {
    // Handle API errors
    const { status, message } = handleApiError(response.error);
    console.error(`API Error [${status}]:`, message);
  } else {
    // Handle network or other errors
    console.error('Unexpected error:', response.error);
  }
}

Development

Generating the Client

The client is auto-generated from the server's OpenAPI specification:

# Generate from the latest server spec
bun run generate

# Build the package
bun run build

Configuration

The code generation is configured in openapi-ts.config.ts:

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: './openapi.json',
  output: {
    path: './src/generated',
  },
  plugins: [
    '@hey-api/typescript',     // Generate TypeScript types
    '@hey-api/schemas',        // Generate runtime schemas
    '@hey-api/sdk',            // Generate SDK functions
    '@hey-api/client-axios',   // Use Axios client
  ],
});

Architecture

@ottocode/api/
├── src/
│   ├── generated/          # Auto-generated files (don't edit!)
│   │   ├── client.gen.ts   # Axios client instance
│   │   ├── sdk.gen.ts      # SDK functions
│   │   ├── types.gen.ts    # TypeScript types
│   │   └── schemas.gen.ts  # Runtime schemas
│   ├── runtime-config.ts   # Client runtime configuration
│   ├── streaming.ts        # SSE utilities
│   ├── utils.ts           # Helper functions
│   └── index.ts           # Public API exports
├── openapi-ts.config.ts   # Code generation config
├── generate.ts            # Generation script
└── build.ts              # Build script

Migration from Legacy Client

If you're migrating from the old Fetch-based client:

Before (Legacy)

import { createApiClient } from '@ottocode/api';

const client = createApiClient({
  baseUrl: 'http://localhost:3000',
});

const response = await client.ask({
  prompt: 'Hello',
});

After (New Axios Client)

import { client, ask } from '@ottocode/api';

// Configure once at startup
client.setConfig({
  baseURL: 'http://localhost:3000',
});

// Use SDK functions
const response = await ask({
  body: { prompt: 'Hello' },
});

Resources

License

MIT