Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

What are some node libraries for sending requests to OpenAI providers. I don’t want to…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-7-sonnet-20250219’s answer.
  1. User

    What are some node libraries for sending requests to OpenAI providers. I don’t want to use the OpenAI library

  2. Assistant

    Below are a handful of popular (and battle-tested) Node.js libraries you can use to hit the OpenAI REST endpoints without relying on the official openai npm package.
    I grouped them so you can pick the level of abstraction you’re comfortable with.


    1. “Pure” HTTP clients (do-it-yourself wrappers)

    LibraryInstallWhy you might like itStreaming support
    axiosnpm i axiosSimple API, automatic JSON, good error handling, interceptors & retries via pluginsYes – access response.data as a stream
    gotnpm i gotModern, ESM-first, built-in retry/back-off and hooks, very little overheadYes – .stream(url) or { isStream: true }
    node-fetch / undiciNode ≥ 18 already has global fetch; for older versions use npm i node-fetchMinimal, Web-standard syntax, “it just works”, great for serverlessYes – body is a ReadableStream
    superagentnpm i superagentChainable API, nice for quick scripts & testsYes – .pipe() or res.on('data')

    When you go “pure HTTP” you manually set the endpoint, headers, query params, etc.—but you stay 100 % in control and keep your bundle size tiny.


    2. Thin, community-built OpenAI helpers (unofficial)

    LibraryInstallWhat it gives youCaveats
    openai-apinpm i openai-apiPromise-based wrapper, tiny (≈ 2 kB), lets you call Chat / Completions / Embeddings with one-linersUnmaintained for a while—check endpoints match current API
    openai-streamsnpm i openai-streamsUtility that wraps the streaming Chat endpoint and returns an async generator → super handy for SSEDoes only ChatCompletions; no images, files, etc.
    gpt-3.5-turbo-proxynpm i gpt-3.5-turbo-proxyLightweight proxy & retry logic, fetch-based, no other depsSmall community, updates may lag

    These libs save a bit of boilerplate but still keep you independent from the official monorepo.


    3. Multi-provider abstractions (if you want OpenAI + Azure + others)

    LibraryInstallSupportsNotes
    openai-proxynpm i openai-proxyOpenAI, Azure OpenAIAdds auth routing, rate-limit helpers
    genAI-clients (experimental)npm i genai-clientsOpenAI, Anthropic, CohereCommunity project; nice if you need to swap providers behind one interface

    Quick usage examples

    Below are two minimal snippets so you can see what “rolling your own” looks like.

    A. Using the built-in fetch (Node 18+)

    // .env:  OPENAI_API_KEY=sk-****
    
    import 'dotenv/config';              // npm i dotenv
    const endpoint = 'https://api.openai.com/v1/chat/completions';
    
    const res = await fetch(endpoint, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
      },
      body: JSON.stringify({
        model: 'gpt-3.5-turbo',
        messages: [
          { role: 'user', content: 'Explain the Doppler effect in 2 sentences.' }
        ],
        stream: false              // stream: true → handle SSE
      })
    });
    
    if (!res.ok) throw new Error(await res.text());
    const data = await res.json();
    console.log(data.choices[0].message.content);
    

    B. Streaming with axios

    import axios from 'axios';
    import { pipeline } from 'stream';
    import { promisify } from 'util';
    
    const api = axios.create({
      baseURL: 'https://api.openai.com/v1',
      headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
      responseType: 'stream'
    });
    
    const rsp = await api.post('/chat/completions', {
      model: 'gpt-3.5-turbo',
      messages: [{ role: 'user', content: 'Stream 5 words.' }],
      stream: true
    });
    
    rsp.data.on('data', chunk => {
      const lines = chunk.toString().split('\n').filter(Boolean);
      for (const line of lines) {
        if (line === 'data: [DONE]') return;
        const payload = JSON.parse(line.replace(/^data: /, ''));
        process.stdout.write(payload.choices[0].delta?.content || '');
      }
    });
    

    Tips when you’re not using the official SDK

    1. Handle rate limits (HTTP 429) & back-off. got already has retry logic; with others add a wrapper (exponential backoff).
    2. Watch for streaming vs. non-streaming responses—set Accept: text/event-stream automatically when stream:true.
    3. If you deploy to Cloudflare Workers, Vercel Edge, etc., prefer fetch/undici for smallest bundles.
    4. Keep up with the OpenAI changelog (new models, parameters) since no SDK will insulate you.

    Happy hacking 🤖✨

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.