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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ajent-api

v1.0.14

Published

Library to create a LLM Api with function calling

Downloads

41

Readme

Ajent API

Ajent API is a modular, extensible Node.js API server for interacting with Large Language Models (LLMs) such as OpenAI (GPT-4) and Google Gemini (Vertex AI). It provides a unified HTTP interface for chat, streaming, and speech-to-text (STT) operations, with built-in support for retries, error handling, and custom hooks.

Features

  • Unified API for multiple LLM providers (OpenAI, Vertex AI/Gemini, and more)
  • Chat completions (single and streaming)
  • Speech-to-text (audio transcription via OpenAI Whisper)
  • Pluggable architecture: easily add new LLM providers
  • Custom hooks for request/response/error handling
  • File upload support for audio transcription
  • Robust retry logic with exponential backoff and error simulation
  • TypeScript-friendly (JSDoc types)
  • Easy to embed or run standalone

Quick Start

1. Install dependencies

npm install ajent-api

2. Set up environment variables

For OpenAI:

  • AJENT_LLM_TOKEN — Your OpenAI API key

For Vertex AI (Gemini):

  • GOOGLE_APPLICATION_CREDENTIALS — Path to your Google Cloud service account JSON
  • AJENT_LLM_PROJECT — Your Google Cloud project ID

3. Start the server

You can create a simple server using the provided API:

const { createLLMServer } = require('ajent-api');

const server = createLLMServer({
  llmName: process.env.LLM_NAME || 'openai', // or 'gemini'
  llmToken: process.env.LLM_TOKEN,
  llmProject: process.env.LLM_PROJECT, // for Vertex AI
  llmLocation: process.env.LLM_LOCATION, // for Vertex AI
  llmModel: process.env.LLM_MODEL || 'gpt-4.1' // or Gemini model name
  port: process.env.PORT || 3000
});

server.start();

Or run your own entrypoint that uses the API server.

4. API Endpoints

All endpoints are mounted under /agent:

POST /agent/message

  • Body: { messages: [...], tools?: [...] }
  • Response: { message: ... }

POST /agent/message/stream

  • Body: { messages: [...], tools?: [...] }
  • Response: [Server-Sent Events (SSE) stream]

POST /agent/audio_message

  • Form-data: audio (file upload)
  • Response: { transcription: ... }

5. Customization

You can pass hooks to customize request/response/error handling:

const server = createLlmServer({
  beforeRequest: (req, res) => { /* ... */ },
  afterResponse: (req, response) => { /* ... */ },
  errorHandler: (err, req, res) => { /* ... */ }
});

Project Structure

  • src/api/factory-api-server.js — Main API server factory
  • src/llm/llm-client.js — Abstract LLM client (retry logic, error handling)
  • src/openai/openai-client.js — OpenAI implementation
  • src/gemini/vertexai-client.js — Vertex AI (Gemini) implementation
  • src/llm/response-serializer.js — Response serialization utilities
  • src/utils/ — Utility modules (logger, converters, etc.)

Testing

Run tests with:

npm test

License

MIT


Ajent API — Unified, extensible LLM API server for modern AI applications.