feat: add centralized inference gateway - #983
Open
sam-saffron-jarvis wants to merge 3 commits into
Open
Conversation
Centralize provider credentials, OAuth, search, fetch, policy, and attributed usage behind a versioned gateway while preserving satellite provider:model selection and local tool execution. Expose POST /v1/responses and GET /v1/models with provider/model namespaces for Discourse and other OpenAI clients, including streaming, reasoning, images, function calls, stateless continuation, usage, and cancellation.
Contributor
Author
Follow-up: session binding and WebSocket parityAudited and hardened multi-turn gateway resumption after the initial PR:
Fake WebSocket test with an intentional 25ms handshake delay:
The first turn and warm follow-up used one provider and one WebSocket connection. After expiry, the gateway safely created a new connection and replayed the full transcript. |
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.
What
Adds a centralized, multi-provider inference gateway while keeping satellites as full local term-llm runtimes.
A satellite retains its agent, prompt, sessions, tools, approvals, filesystem, jobs, UI, and normal
provider:modelselection. The gateway owns provider configuration, API credentials, OAuth/CLI homes, search/fetch credentials, policy, retries, and attributed usage.Satellite configuration is reduced to a gateway connection plus explicit local exceptions:
Normal selection remains unchanged:
term-llm ask --provider chatgpt:gpt-5.6-sol-high '...' term-llm chat --provider openrouter:moonshotai/kimi-k2Gateway protocol
Adds a versioned private
/g1provider plane:The gateway is a remote
llm.Provider, not a remote agent. It does not run satellite sessions, skills, jobs, or local filesystem tools.OpenAI Responses edge
term-llm gateway servealso exposes:This lets Discourse and standard OpenAI clients use central providers directly with namespaced model IDs:
The edge supports:
/v1/modelsIt deliberately does not instantiate a term-llm agent or execute client function calls on the gateway.
Discourse configuration:
The implementation was matched against the current Discourse Responses endpoint, dialect, message processor, and specs under
plugins/discourse-ai.Security
WorkingDirand local paths are structurally absent from the wireOperations
Adds:
Enrollment writes a separate mode-
0600token file and updates satellite config atomically without printing the long-lived credential.Includes a private-network Compose example, gateway/satellite example configs, health checks, CI YAML validation, and a full deployment/security guide.
Live testing
Tested with isolated gateway and satellite homes in throwaway directories:
provider:modelselection/v1/modelsand streaming/v1/responsesthrough curl, officialopenai-go, and a Discourse-shaped RubyNet::HTTPparserMatched direct and gateway
debug:normalruns, six warm samples each:The difference is measurement noise; no measurable warm inference overhead was observed for that workload.
A 16-way gateway run completed 16/16 requests in 3.5019s wall time, with 3.4950s per-request p50 and 3.4988s maximum.
Verification
After rebasing onto
da927604:All passed with isolated
HOME/XDG directories.Focused race coverage also passed for gateway, Responses, catalog, routing, tool callbacks, limits, retries, cancellation, enrollment, search, and usage.
Scope
Included: text inference, vision/file inputs, function tools/results, reasoning, search/fetch, usage, private satellite protocol, and OpenAI Responses edge.
Not included: image/audio generation, realtime/WebRTC proxying, multi-gateway HA, or provider-hosted non-function tools.