Repository navigation
feat(ai): add the openai, anthropic and gemini providers - #17
Merged
Merged
Conversation
A provider that talks to a model API over HTTP has to do two things the Claude CLI does on its own: read a server-sent event stream, and run the tool calls the model asks for. sseData() yields the data payload of each event wherever the chunks are cut, with LF or CRLF line endings, and keeps a last event that has no blank line after it. tool-calls.ts lists the read-only tools under the mcp__loxilb__ names the system prompt and the skills already use, runs a call through executeTool(), and turns a thrown error into a result the model can read. A call whose arguments are not a JSON object, or that lacks a required one, is not run, and the model is told so; the MCP server makes the same check before it runs a tool. One answer may take at most ten rounds of tool calls. InferenceRequest gains disableTools, for a request that should be answered from the prompt alone, and signal, to cancel one. The Claude CLI and Ollama providers do not read either. Signed-off-by: KP <kp@attlab.org>
OpenAiProvider streams from the Responses API and runs the read-only tools in this process until the model answers. The current models reject function tools on Chat Completions unless reasoning is turned off, which gpt-6.2-astra does not accept, so the hosted API is reached through /v1/responses. Requests are stateless (store: false): the output items of a turn, encrypted reasoning included, go back unchanged with the tool results. The tools carry strict: false; left out, the API applies strict mode and makes every optional parameter a required one. OpenAiChatProvider speaks Chat Completions, for servers that implement that API (vLLM, llama.cpp, LM Studio). It needs a model name and sends a key only when one is set. Fields a server adds to a tool call are returned with it; Gemini's OpenAI-compatible endpoint rejects the follow-up request without them. Calls are told apart by index, and by id when a server leaves the index out or repeats it. Both ask for at least 4096 output tokens, because reasoning tokens count against the cap. A turn the token limit cuts off inside a tool call is reported and the call is not run, an answer with no text is reported as empty, and the caller's signal cancels the request. Signed-off-by: KP <kp@attlab.org>
AnthropicProvider streams from the Messages API and runs the read-only tools in this process until the model answers. Content blocks are rebuilt from the stream and sent back as received, thinking blocks and their signatures included, since the API checks them on the request that carries the tool results. All results of a turn travel in one user message, and a call that threw is marked is_error. Thinking is always on for claude-opus-5-5 and counts against max_tokens, so the request asks for at least 16000. A refusal, a turn that hits the token limit before any text and an answer with no text are reported as errors. The caller's signal cancels the request. A message that is only whitespace is left out of the request. The API rejects one, and the sidebar keeps it in the history when the model writes just a line break before a tool call. Signed-off-by: KP <kp@attlab.org>
GeminiProvider streams from the Interactions API and runs the read-only tools in this process until the model answers. Requests are stateless (store: false): the conversation goes as input steps, and the steps of a turn, thought signatures included, go back unchanged with the function results. max_output_tokens covers thinking as well, so the request asks for at least 16000. A turn the token limit cuts off inside a function call is reported and the call is not run, an answer with no text is reported as empty, and the caller's signal cancels the request. Signed-off-by: KP <kp@attlab.org>
[ai] provider now accepts openai, anthropic and gemini. The key comes from [ai] api_key, or from OPENAI_API_KEY, ANTHROPIC_API_KEY or GEMINI_API_KEY when that is empty. openai with a base_url is taken as another server that speaks Chat Completions. It needs no key and is sent only the one in [ai] api_key, never OPENAI_API_KEY. The config's default model is a placeholder, so the providers read it as unset and use their own default. The hosted APIs do the same with the sonnet that setup writes for the Claude CLI; another server may serve a model by that name, so there it is kept. AiClient.isConfigured, which was always true, is false while an API provider has no key, and the log-analysis shortcut uses the same check. A question and the skill classifier now pass their abort signal to the provider, so Ctrl+C and the classifier's five-second limit cancel the request of an API provider; the classifier also asks those providers for no tools, since it wants only a skill name. setup asks for the model and the key, and for openai a base URL, in which case the model has no default and stays unset when left blank. doctor reports what the provider's validate() finds. Signed-off-by: KP <kp@attlab.org>
The AI sidebar guide, the user guide and the README list the three API providers and their key variables, and say what openai does with a base_url. The sidebar guide also gives the default models, says how the tool calls run (in loxitui, not in an MCP subprocess, with the [loxilb] token), what leaves the machine for the provider's API, and that a free-tier Gemini key allows only a few requests a day on the default model. Signed-off-by: KP <kp@attlab.org>
`loxitui ask` created its provider without the [loxilb] settings, so the assistant's tools reached 127.0.0.1:11111 without a token whatever the config said. It now passes them, as the sidebar and doctor do. The sidebar records ai.query, ai.response and ai.error for every question. ask wrote only cmd.dispatch, so the audit log did not show which provider and model a headless question went to. It now writes the same three records. After a provider error it waits for the log before it exits with code 2, because process.exit does not wait for writes that are still pending. The tests run ask with each API provider and check where the request went, what was recorded, and that a tool call reaches the configured gateway with its token. Signed-off-by: KP <kp@attlab.org>
kp-attlab
marked this pull request as ready for review
November 24, 2026 06:22
kp-attlab
requested review from
NLX-SeokHwanKong,
backguynn,
inhogog2 and
loxilb-devel
as code owners
November 24, 2026 06:22
NLX-SeokHwanKong
approved these changes
Nov 26, 2026
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.
Description
Adds three assistant providers that talk to a model API directly:
openai,anthropicandgemini. Until now the assistant needed the Claude CLI for live data (through the MCP subprocess) or Ollama for text-only answers. With these,[ai] providerplus an API key is enough, and the model still queries the gateway through the same read-only tools.How it works:
executeTool()against the configured LoxiLB instance and sends the results back, until the model answers. One answer may take at most ten rounds of tool calls.mcp__loxilb__<name>names the system prompt and the skills already use, so prompts, skills and the sidebar's tool display are unchanged.fetch; no SDK packages are added andbun.lockis unchanged.[ai] api_key, or fromOPENAI_API_KEY,ANTHROPIC_API_KEYorGEMINI_API_KEYwhen that is empty.Per provider:
openaiuses the Responses API (default modelgpt-6.2-astra). The current models reject function tools on Chat Completions unless reasoning is turned off, which the default model does not accept.openaiwith abase_urlis taken as an OpenAI-compatible server (vLLM, llama.cpp, LM Studio) and uses Chat Completions.modelis then required and a key is optional. That server is sent only the key in[ai] api_key; anOPENAI_API_KEYin the environment is not sent to it. Every question carries the tool definitions; there is no text-only fallback for a server that rejects them.anthropicuses the Messages API (default modelclaude-opus-5-5).geminiuses the Interactions API (default modelgemini-4-hydrogen).Things worth a look:
claude-cli, what the assistant works with leaves the machine for the provider's API: the question and the conversation so far, the system prompt (skill text, matched knowledge-base excerpts, the live-state summary) and the tool results (live LoxiLB state).docs/ai-sidebar.mdsays so.modelcan hold a name nobody chose: the config default (claude-3-5-sonnet-20241022), or thesonnetthatsetupwrites forclaude-cli. The providers read the config default as unset and use their own default, and the hosted APIs do the same withsonnet. With abase_url,sonnetis kept, since that server may serve a model by that name.AiClient.isConfiguredwas always true; it is now false while an API provider has no key, and the log-analysis shortcut uses the same check.claude-cliandollamabehave as before.claude-cliandollamado not read the signal.strict: false. Left out, the Responses API applies strict mode and makes every optional parameter required: asked for the global rate-limit defaults, the model then sent{"rule_ident": ""}, and withstrict: falseit sends{}. An answer with no text is reported as empty.loxitui askcreated its provider without the[loxilb]settings, so with any provider its tools reached127.0.0.1:11111without a token. It now passes them, as the sidebar anddoctordo. This changesaskonclaude-clitoo.loxitui asknow writes theai.query,ai.responseandai.erroraudit records the sidebar writes, so the audit log shows which provider and model a headless question went to. Until nowaskleft onlycmd.dispatch, with any provider. After a provider error it waits for the log before it exits with code 2.Not changed here:
[loxilb] tokenonly; ausername/passwordlogin is not used.setupwritesconfig.tomlwith default file permissions, as before. An API key entered there is as readable as the[loxilb] tokenalready is; leaving the prompt blank and using the environment variable avoids that.The commits can be read one at a time: shared helpers, one commit per provider, the wiring, docs, then
ask(the gateway settings and the audit records).Type of change
How has this been tested?
bun run lint,bun run typecheckandbun testpassghcr.io/loxilb-io/loxilb-inference-gateway:latest-u24, built 2026-11-15)Linux, Bun 1.3.6 (the CI version): lint 0 errors, typecheck clean, 735 pass, 0 fail. Line coverage 69.27% (floor 60%), no schema drift, all four builds and the
linux-x64smoke test pass,scripts/release-hygiene.sh(with gitleaks) passes.Windows 11, Bun 1.4.4: 734 pass, 0 fail.
tests/ai-providers.test.ts(37 tests) runs each provider against a fakefetchthat delivers the event stream in 17-byte pieces: text, a full tool round with what is sent back on the second request, HTTP and stream errors, an answer or a tool call cut off by the token limit, tool arguments that are not valid JSON or lack a required one, an empty answer, a cancel while the model is silent, tool calls from a server that sends no index, the round cap, key validation, and key and provider selection. It also runsloxitui askwith each of the three providers and checks where the request went, what the audit log holds, and that a tool call reaches the gateway in the config with its token.Against the real APIs on 2026-11-23, with the gateway above:
gpt-6.2-astra), Anthropic (claude-opus-5-5) and Gemini:validate(), a plain answer, an answer that needs tool calls ("how many LB rules are there"), a follow-up turn, and stopping mid-stream. A cancel 400 ms into a request ended it at once on all three (Gemini ongemini-3.5-flash-lite), and all three accepted a history that starts with an assistant message or repeats a role, which the sidebar can send after it trims or summarizes.loxitui askend to end andloxitui doctorwith each provider;doctoralso with a wrong key and an unreachable server.loxitui askwith each provider again: the audit log holdsai.querywith the provider and model, theai.tool_callandai.response. The same day, OpenAI withgpt-4.1andgpt-4o-mini, with and without a tool call, to check models without reasoning. Andaskwith[loxilb] portset to a port nothing listens on: the tool call is refused there, where it used to reach the default port.Not tested:
gemini-4-hydrogenand the API often answered 503; the remaining scenarios ran ongemini-3.5-flash-lite.linux-x64build onlydoctorwith a wrong Anthropic key was run: the request reaches the API and the 401 is reported.Checklist
git commit -s).github/CODEOWNERS) has been requested for reviewRelated issues
Follows #15.