Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@agi-cli/api

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agi-cli/api

Type-safe API client for AGI CLI server

latest
Source
npmnpm
Version
0.1.172
Version published
Maintainers
1
Created
Source

@agi-cli/api

Type-safe API client for AGI CLI 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 @agi-cli/api axios
# or
bun add @agi-cli/api axios
# or
pnpm add @agi-cli/api axios

Quick Start

import { client, ask, listSessions } from '@agi-cli/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 '@agi-cli/api';

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

Advanced Configuration with Interceptors

import { client } from '@agi-cli/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 '@agi-cli/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 '@agi-cli/api';

SSE Streaming

For endpoints that support Server-Sent Events:

import { createSSEStream } from '@agi-cli/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 '@agi-cli/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

@agi-cli/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 '@agi-cli/api';

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

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

After (New Axios Client)

import { client, ask } from '@agi-cli/api';

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

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

Resources

License

MIT

Keywords

agi

FAQs

Package last updated on 04 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts