ai: use OpenAI-compatible chat endpoint (gateway-friendly) - #1
Merged
Merged
Conversation
/api/ai/chat now POSTs to an OpenAI-compatible /chat/completions endpoint
(OPENAI_BASE_URL + OPENAI_API_KEY) instead of calling Anthropic directly.
This lets it sit behind an OpenAI-compatible gateway like LiteLLM (which
is the provider/format abstraction) and reach any model the gateway
exposes — the homelab points it at LiteLLM -> OpenCode Zen (Kimi 2.6).
Client request/response shape is unchanged ({messages,system,model,
max_tokens} -> {content,model,stop_reason}). Plain net/http, no AI SDK
dependency (dropped anthropic-sdk-go). SHARED_AI_MODEL default unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/api/ai/chatnow talks to an OpenAI-compatible/chat/completionsendpoint (OPENAI_BASE_URL+OPENAI_API_KEY) instead of calling Anthropic directly.Why: lets shared sit behind an OpenAI-compatible gateway (LiteLLM), which is the real provider/format abstraction — so shared stays a thin client and can reach any model the gateway exposes. The homelab routes it to LiteLLM → OpenCode Zen (Kimi 2.6). The Anthropic SDK path couldn't be used through LiteLLM (the
/v1/messages→openai-provider translation didn't round-trip).{messages,system,model,max_tokens}→{content,model,stop_reason}.net/http, no AI-SDK dependency (droppedanthropic-sdk-go; didn't addopenai-go— its param unions are heavy for one call, and LiteLLM is the abstraction).ANTHROPIC_API_KEY→OPENAI_BASE_URL/OPENAI_API_KEY).