Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1.91 KB

File metadata and controls

39 lines (28 loc) · 1.91 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

Minimal OpenAI-compatible API client implemented with Node.js built-in http/https modules (no external dependencies).

Common Commands

  • node index.js or npm start - Run default chat mode
  • node index.js chat "<prompt>" - Single chat completion
  • node index.js stream "<prompt>" - Streaming chat completion (SSE)

Prerequisites

Copy config.example.json to config.json and fill in baseURL, apiKey, and model before running any command.

Architecture

Entry Point (index.js)

  • Parses CLI arguments: process.argv[2] is the command (chat or stream), remaining args form the prompt
  • Loads config via lib/config.js and exits with code 1 if missing
  • Constructs a default message array with a system prompt and the user prompt
  • Delegates to OpenAICompatibleClient methods

Config Loader (lib/config.js)

  • Exports loadConfig() which reads ../config.json relative to its own directory
  • Returns null if the file does not exist; throws on JSON parse errors
  • Exposes CONFIG_FILE absolute path for error messages

API Client (lib/ai.js)

  • OpenAICompatibleClient class handles all HTTP(S) communication
  • baseURL is normalized (trailing slash removed); model falls back to gpt-4o-mini
  • buildPayload() constructs the JSON body for /chat/completions
  • chat() returns the full assistant message content string
  • streamChat() parses SSE line-delimited events (data: ...\n\n), calling onDelta per chunk and onComplete when the stream ends
  • extractDeltaContent() handles multiple response shapes: plain string, array of strings, and nested part.text.value
  • Both methods share createRequestOptions() which chooses http or https based on the URL protocol and sets a 60-second timeout