This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Minimal OpenAI-compatible API client implemented with Node.js built-in http/https modules (no external dependencies).
node index.jsornpm start- Run default chat modenode index.js chat "<prompt>"- Single chat completionnode index.js stream "<prompt>"- Streaming chat completion (SSE)
Copy config.example.json to config.json and fill in baseURL, apiKey, and model before running any command.
Entry Point (index.js)
- Parses CLI arguments:
process.argv[2]is the command (chatorstream), 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
OpenAICompatibleClientmethods
Config Loader (lib/config.js)
- Exports
loadConfig()which reads../config.jsonrelative to its own directory - Returns
nullif the file does not exist; throws on JSON parse errors - Exposes
CONFIG_FILEabsolute path for error messages
API Client (lib/ai.js)
OpenAICompatibleClientclass handles all HTTP(S) communicationbaseURLis normalized (trailing slash removed);modelfalls back togpt-4o-minibuildPayload()constructs the JSON body for/chat/completionschat()returns the full assistant message content stringstreamChat()parses SSE line-delimited events (data: ...\n\n), callingonDeltaper chunk andonCompletewhen the stream endsextractDeltaContent()handles multiple response shapes: plain string, array of strings, and nestedpart.text.value- Both methods share
createRequestOptions()which chooseshttporhttpsbased on the URL protocol and sets a 60-second timeout