Class AbstractOpenAICompatibleClient

java.lang.Object
com.tnsai.llm.providers.AbstractLLMClient
com.tnsai.llm.providers.AbstractOpenAICompatibleClient
All Implemented Interfaces:
com.tnsai.llm.LLMClient
Direct Known Subclasses:
CerebrasClient, DatabricksClient, DeepInfraClient, DeepSeekClient, FireworksAIClient, GroqClient, HuggingFaceClient, LlamaCppServerClient, LMStudioClient, MistralClient, NvidiaNIMClient, OpenRouterClient, PerplexityClient, QwenCloudClient, TencentHunyuanClient, TogetherAIClient, VLLMClient, XAIGrokClient, YiClient

public abstract class AbstractOpenAICompatibleClient extends AbstractLLMClient
Base class for providers that speak the OpenAI /chat/completions wire format verbatim — same request body, same choices[].message response, same choices[].delta streaming, Bearer auth.

The OpenAI chat-completions shape is a de-facto standard: roughly a dozen providers (DeepSeek, Groq, Together.ai, Fireworks, Perplexity, xAI, …) expose an endpoint that is byte-compatible with it, differing only in base URL, API-key env var, and a human-readable label. Before this class each of those clients carried its own ~150-line copy of buildChatRequest / parseChatResponse / extractStreamContent / chat / streamChat; a fix to tool-call parsing or stream-delta extraction had to be applied to every copy by hand. Consolidating here removes that drift surface — a pure OpenAI-compatible provider now shrinks to a constructor plus its base-URL/env-var constants.

Providers that are not byte-compatible stay on AbstractLLMClient directly — Anthropic, Gemini, Bedrock, Vertex AI, Cohere (own wire formats), and OpenAI itself plus OpenRouter, Mistral, ZhipuAI, MiniMax, which add response_format / extra headers / JWT auth on top of the base shape.

Extending

Subclasses that are pure-compatible need only forward a constructor. A provider that is identical except for extra HTTP headers (e.g. an HTTP-Referer) can override addProviderHeaders(Request.Builder) and inherit everything else.
Since:
0.11.0
Author:
TnsAI Team