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

@amux.ai/llm-bridge

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amux.ai/llm-bridge

Core IR and adapter interfaces for Amux

latest
Source
npmnpm
Version
0.3.2
Version published
Maintainers
1
Created
Source

@amux.ai/llm-bridge

Core IR (Intermediate Representation) and adapter interfaces for Amux

npm version License: MIT

Overview

@amux.ai/llm-bridge is the core package of Amux that provides:

  • Intermediate Representation (IR): Unified data structures for LLM requests/responses
  • Adapter Interface: Standard interface for building provider adapters
  • Bridge Pattern: Orchestration layer for bidirectional conversion
  • HTTP Client: Built-in HTTP client with SSE streaming support
  • Zero Dependencies: No runtime dependencies

Installation

pnpm add @amux.ai/llm-bridge
# or
npm install @amux.ai/llm-bridge
# or
yarn add @amux.ai/llm-bridge

Quick Start

Create a Bridge

import { createBridge } from '@amux.ai/llm-bridge'
import { openaiAdapter } from '@amux.ai/adapter-openai'
import { anthropicAdapter } from '@amux.ai/adapter-anthropic'

const bridge = createBridge({
  inbound: openaiAdapter,
  outbound: anthropicAdapter,
  config: {
    apiKey: process.env.ANTHROPIC_API_KEY,
    baseURL: 'https://api.anthropic.com'
  }
})

// Send request in OpenAI format, get response in OpenAI format
// But actually calls Anthropic API under the hood
const response = await bridge.chat({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello!' }]
})

Streaming

for await (const chunk of bridge.chatStream({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Tell me a story' }],
  stream: true
})) {
  console.log(chunk)
}

Core Concepts

Intermediate Representation (IR)

The IR is the central data structure that all adapters convert to/from:

  • LLMRequestIR: Unified request format
  • LLMResponseIR: Unified response format
  • LLMStreamEvent: Unified streaming events
  • LLMErrorIR: Unified error format

Adapter Interface

Every adapter implements the LLMAdapter interface:

interface LLMAdapter {
  inbound: {
    parseRequest(request: unknown): Promise<LLMRequestIR>
    parseResponse(response: unknown): Promise<LLMResponseIR>
    parseStream(chunk: string): Promise<LLMStreamEvent | null>
    parseError(error: unknown): LLMErrorIR
  }
  outbound: {
    buildRequest(ir: LLMRequestIR): unknown
    buildResponse(ir: LLMResponseIR): unknown
  }
  capabilities: AdapterCapabilities
  getInfo(): AdapterInfo
}

Bridge Pattern

The Bridge orchestrates the conversion flow:

  • Inbound adapter parses incoming request → IR
  • Validate IR (optional)
  • Outbound adapter builds provider request from IR
  • Send HTTP request to target provider
  • Outbound adapter parses response → IR
  • Inbound adapter builds final response from IR

API Reference

createBridge(options)

Create a new bridge instance.

Options:

  • inbound - Inbound adapter instance
  • outbound - Outbound adapter instance
  • config - Configuration object
    • apiKey - API key for the outbound provider
    • baseURL - Base URL for the outbound provider (optional)
    • timeout - Request timeout in milliseconds (optional)
    • headers - Additional HTTP headers (optional)

Returns: Bridge instance

bridge.chat(request)

Send a chat completion request.

Parameters:

  • request - Request object in inbound adapter format

Returns: Promise<Response> - Response in inbound adapter format

bridge.chatStream(request)

Send a streaming chat completion request.

Parameters:

  • request - Request object in inbound adapter format with stream: true

Returns: AsyncIterable<string> - Server-Sent Events stream

Available Adapters

TypeScript Support

This package is written in TypeScript and provides full type definitions.

import type { 
  LLMRequestIR, 
  LLMResponseIR, 
  LLMAdapter,
  Bridge 
} from '@amux.ai/llm-bridge'

Contributing

Contributions are welcome! Please see our Contributing Guide.

License

MIT © isboyjc

Keywords

amux

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