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

@ai-sdk-tool/proxy

v0.1.0

Published

OpenAI-compatible proxy server for AI SDK tool middleware

Readme

@ai-sdk-tool/proxy

OpenAI-compatible proxy server for AI SDK tool middleware. This package allows you to expose AI SDK middleware-wrapped language models as standard OpenAI API endpoints, enabling tool calling capabilities for models that don't natively support them.

Features

  • 🔄 OpenAI-compatible /v1/chat/completions endpoint
  • 🌊 Streaming and non-streaming responses
  • 🛠️ Tool calling support for non-native models
  • ⚡ Fast and lightweight Fastify server
  • 🔧 Configurable CORS and server options
  • 📦 Easy integration with existing AI SDK middleware

Installation

pnpm add @ai-sdk-tool/proxy

Quick Start

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { wrapLanguageModel } from "ai";
import { OpenAIProxyServer } from "@ai-sdk-tool/proxy";
import { z } from "zod";

// Create your language model with middleware
const baseModel = createOpenAICompatible({
  name: "openrouter",
  apiKey: process.env.OPENROUTER_API_KEY,
  baseURL: "https://openrouter.ai/api/v1",
});

const wrappedModel = wrapLanguageModel({
});

// Configure tools
const tools = {
  get_weather: {
    description: "Get the weather for a given city",
    inputSchema: z.object({ city: z.string() }),
    execute: ({ city }) => {
      // Your weather API logic here
      return { city, temperature: 22, condition: "sunny" };
    },
  },
};

// Start the proxy server
const server = new OpenAIProxyServer({
  model: wrappedModel,
  port: 3000,
  tools,
});

await server.start();

Usage

Once the server is running, you can make standard OpenAI API calls to http://localhost:3000/v1/chat/completions:

curl -X POST http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wrapped-model",
    "messages": [
      {"role": "user", "content": "What is the weather in New York?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the weather for a given city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {"type": "string"}
            },
            "required": ["city"]
          }
        }
      }
    ],
    "stream": false
  }'

Streaming

Enable streaming by setting "stream": true in your request:

curl -X POST http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wrapped-model",
    "messages": [
      {"role": "user", "content": "Tell me a story"}
    ],
    "stream": true
  }'

API Endpoints

  • POST /v1/chat/completions - OpenAI-compatible chat completions
  • GET /v1/models - List available models
  • GET /health - Health check endpoint

Configuration

interface ProxyConfig {
  model: LanguageModel; // Wrapped language model with middleware
  port?: number; // Server port (default: 3000)
  host?: string; // Server host (default: 'localhost')
  cors?: boolean; // Enable CORS (default: true)
  tools?: Record<string, AISDKTool>; // Available tools (server-registered)
  maxSteps?: number; // Optional: maximum tool-calling steps (experimental)
  logger?: { debug: Function; info: Function; warn: Function; error: Function }; // Optional structured logger
}

Tool Definition

interface AISDKTool {
  description: string;
  inputSchema: z.ZodTypeAny; // Zod schema for tool input
  execute?: (params: unknown) => unknown | Promise<unknown>;
}

Notes:

  • Server merges request-provided tools (schema-only) with server tools (schema + optional execute). Server tools take precedence on name collision. Zod schemas are wrapped for provider compatibility internally.

Testing

This package uses colocated unit tests next to source files. Key areas covered:

  • Request conversion (OpenAI → AI SDK): openai-request-converter.test.ts, openai-request-converter.normalize.test.ts
  • Result conversion (AI SDK → OpenAI): response-converter.result.test.ts
  • Streaming conversion with stateful handling: response-converter.stream.test.ts
  • SSE formatting: response-converter.sse.test.ts

Run tests:

pnpm --filter @ai-sdk-tool/proxy test

Vitest config includes src/**/*.test.ts and excludes src/test/** (legacy).

Internals (Overview)

  • OpenAI request → AI SDK params: src/openai-request-converter.ts
  • AI SDK result/stream → OpenAI response/SSE: src/response-converter.ts
  • SSE helpers: createSSEResponse, createOpenAIStreamConverter(model)

Each streaming request creates a single converter instance to maintain per-request state for correct finish_reason and tool-call handling.

License

Apache-2.0