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

@elsium-ai/client

v0.6.0

Published

HTTP client SDK for ElsiumAI server

Readme

@elsium-ai/client

TypeScript HTTP client for consuming ElsiumAI servers, with full SSE streaming support.

npm License


Install

npm install @elsium-ai/client

What's Inside

| Category | Exports | |----------|---------| | Client | createClient | | Types | ElsiumClient, ClientConfig, ChatRequest, ChatResponse, CompleteRequest, CompleteResponse, HealthResponse, MetricsResponse, AgentInfo | | SSE | parseSSEStream |


Usage

Creating a client

import { createClient } from '@elsium-ai/client'

const client = createClient({
  baseUrl: 'http://localhost:3000',
  apiKey: 'my-api-token',       // Optional — sent as Authorization: Bearer header
  timeout: 30_000,               // Optional — request timeout in ms
})

Chat with an agent

const response = await client.chat({
  agent: 'support-agent',
  message: 'How do I return my order?',
})

console.log(response.message)  // Agent's response text

Raw LLM completion

const response = await client.complete({
  messages: [{ role: 'user', content: 'Explain TypeScript generics.' }],
  model: 'claude-sonnet-4-6',
})

console.log(response.message)
console.log(response.usage)    // { inputTokens, outputTokens, totalTokens }

Streaming (SSE)

// Stream chat responses
for await (const event of client.chatStream({
  agent: 'support-agent',
  message: 'Write a poem about coding',
})) {
  if (event.type === 'text_delta') {
    process.stdout.write(event.text)
  } else if (event.type === 'message_end') {
    console.log('\nDone:', event.usage)
  }
}

// Stream completions
for await (const event of client.completeStream({
  messages: [{ role: 'user', content: 'Count to 10 slowly' }],
})) {
  if (event.type === 'text_delta') {
    process.stdout.write(event.text)
  }
}

Health check

const health = await client.health()
console.log(health.status) // 'ok'

List agents

const agents = await client.agents()
for (const agent of agents) {
  console.log(`${agent.name}: ${agent.description}`)
}

Metrics

const metrics = await client.metrics()
console.log(metrics)

SSE Parser

Use the SSE parser standalone to parse any Server-Sent Events response:

import { parseSSEStream } from '@elsium-ai/client'

const response = await fetch('http://localhost:3000/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ agent: 'assistant', message: 'Hello', stream: true }),
})

for await (const event of parseSSEStream(response)) {
  console.log(event.type, event)
}

ElsiumClient Interface

interface ElsiumClient {
  chat(req: ChatRequest): Promise<ChatResponse>
  chatStream(req: ChatRequest): AsyncIterable<StreamEvent>
  complete(req: CompleteRequest): Promise<CompleteResponse>
  completeStream(req: CompleteRequest): AsyncIterable<StreamEvent>
  health(): Promise<HealthResponse>
  metrics(): Promise<MetricsResponse>
  agents(): Promise<AgentInfo[]>
}

Type Definitions

ClientConfig

Configuration for creating a client instance.

interface ClientConfig {
  baseUrl: string
  apiKey?: string
  timeout?: number
}

| Field | Type | Default | Description | |-------|------|---------|-------------| | baseUrl | string | (required) | The base URL of the ElsiumAI server. | | apiKey | string | undefined | API token sent as Authorization: Bearer header. | | timeout | number | 30000 | Request timeout in milliseconds. |

ChatRequest

interface ChatRequest {
  message: string
  agent?: string
  stream?: boolean
}

ChatResponse

interface ChatResponse {
  message: string
  usage: { inputTokens: number; outputTokens: number; totalTokens: number; cost: number }
  model: string
  traceId: string
}

CompleteRequest

interface CompleteRequest {
  messages: Array<{ role: string; content: string }>
  model?: string
  system?: string
  maxTokens?: number
  temperature?: number
  stream?: boolean
}

CompleteResponse

interface CompleteResponse {
  message: string
  usage: { inputTokens: number; outputTokens: number; totalTokens: number }
  model: string
  stopReason: string
}

HealthResponse

interface HealthResponse {
  status: 'ok' | 'degraded'
  version: string
  uptime: number
  providers: string[]
}

MetricsResponse

interface MetricsResponse {
  uptime: number
  totalRequests: number
  totalTokens: number
  totalCost: number
  byModel: Record<string, { requests: number; tokens: number; cost: number }>
}

AgentInfo

interface AgentInfo {
  name: string
  model?: string
  tools: string[]
  description?: string
}

StreamEvent

type StreamEvent =
  | { type: 'text_delta'; text: string }
  | { type: 'message_end'; usage: { inputTokens: number; outputTokens: number; totalTokens: number } }
  | { type: 'error'; error: string }

Error Handling

The client throws errors with descriptive messages for common failure cases. Wrap calls in try/catch for robust error handling:

import { createClient } from '@elsium-ai/client'

const client = createClient({
  baseUrl: 'http://localhost:3000',
  apiKey: 'my-token',
})

try {
  const response = await client.chat({ message: 'Hello' })
  console.log(response.message)
} catch (error) {
  if (error instanceof Error) {
    // Common errors:
    // - Network errors (server unreachable)
    // - 401 Unauthorized (invalid or missing API key)
    // - 429 Too Many Requests (rate limited)
    // - 500 Internal Server Error
    console.error('Request failed:', error.message)
  }
}

License

MIT - Copyright (c) 2026 Eric Utrera