Files
splinter/docs/GATEWAY.md
T
lotherk a01bfe9df1 sessions switch locally, gateway keeps caller settings and mixed calls
- sp_engine_switch(): close the old engine and open the chosen session from
  the same options; if the new one fails, reopen the session the engine was
  on. The protocol's open and the in-process /open both use it. The curses
  screen clears the pane and replays the new history, so /open no longer says
  it needs --attach.
- gateway: temperature, top_p and max_tokens (max_completion_tokens) are
  forwarded to the provider instead of dropped; request bodies may be
  Transfer-Encoding: chunked; a mixed reply runs the gw_ calls, returns the
  caller's calls in tool_calls and puts the local observations in content
  (also in the SSE delta), so the caller can echo them back.
- reconnect: when the remembered session is gone, the screen says which one
  and stays on the session the server has instead of silently swapping the
  transcript.
- ring: the exits' transports are disposed on plugin shutdown.
- /status goes through the catalogues like the rest of the UI (the English
  labels and their alignment are unchanged, so existing parsers still work).
- the man page passes mandoc -Tlint and covers the gateway and /open.

Tests: test_ui.sh covers local /sessions and /open (new, back, history),
test_protocol.sh the shared switch, test_reconnect.sh a vanished session,
test_gateway_openai.sh forwarded parameters, a chunked body and the mixed
reply in JSON and SSE. make check green.
2026-11-16 10:18:41 +00:00

4.3 KiB

The OpenAI gateway

splinter --openai-listen IP [--openai-listen-port N] is a small OpenAI-compatible endpoint. Another harness points its OpenAI client at it and gets an answer from splinter's configured provider, with tools on both sides: splinter executes its own tools where splinter runs, the caller executes its tools where the caller runs.

# the side with the files and the shell
splinter -m myprovider --openai-listen 127.0.0.1 --openai-listen-port 8097

# the other harness
export OPENAI_BASE_URL=http://127.0.0.1:8097/v1
export OPENAI_API_KEY=unused          # unless SPLINTER_GATEWAY_TOKEN is set

GET /v1/models answers with the run's model, so a client that probes first is happy. POST /v1/chat/completions accepts the usual messages, tools and stream fields.

Two tool namespaces

The model sees two kinds of tools in one request:

name who runs it where
gw_read, gw_write, gw_edit, gw_run, … splinter on the host where splinter runs
everything in the caller's tools array the calling harness where the harness runs

gw_ is reserved: a caller tool with that prefix is refused with HTTP 400, because that is how a local read and a caller's read stay apart.

The loop, inside one HTTP request:

  1. splinter asks its provider with the caller's conversation, the caller's tools and its own tools renamed gw_*.
  2. If the model calls gw_*, splinter runs it here (read tools always; mutating and destructive ones only with --autonomous), appends the observation and asks the provider again. The caller never sees these calls.
  3. If the model calls a caller tool, splinter returns a normal chat.completion with tool_calls and finish_reason: "tool_calls". The harness runs them, sends the results as tool messages in the next request, and the gateway continues.
  4. If a reply mixes both, the local calls run here and the caller's calls are returned in the same tool_calls answer. Since the caller cannot answer a gw_ call, the local observations travel in the message content (under "local gateway tools ran on the splinter host:"); the caller sends them back with the assistant message as usual, and the model sees both sides.

Every request is stateless, as the OpenAI protocol says: the conversation travels with it. The loop is capped at 16 local tool rounds and each observation at 32 KiB.

Request shaping

The caller's temperature, top_p and max_tokens (or max_completion_tokens) are forwarded to the provider; absent values stay the provider's default. The response echoes the request's model name, and every message, including the mixed-reply case, stays within the OpenAI chat shape.

Bodies may arrive with Content-Length or Transfer-Encoding: chunked; only one request per connection is read, then the connection closes.

Examples

A local tool, executed by splinter, from the caller's point of view an ordinary completion:

curl -s http://127.0.0.1:8097/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"x","messages":[{"role":"user","content":"read Cargo.toml"}]}'

A caller tool comes back instead:

{"choices":[{"index":0,"message":{"role":"assistant","content":"",
  "tool_calls":[{"id":"c1","type":"function",
    "function":{"name":"browser_open","arguments":"{\"url\":\"...\"}"}}]},
  "finish_reason":"tool_calls"}]}

Security

  • Beyond loopback the server refuses to start without SPLINTER_GATEWAY_TOKEN; with a token set, every request needs Authorization: Bearer <token>.
  • --autonomous is the switch that lets the model use gw_write, gw_edit and gw_run. Without it those calls are denied with an observation the model reads, so it can still answer.
  • There is no TLS. Expose it through ssh, WireGuard or a TLS proxy when the network is not yours.
  • One request is served at a time; the endpoint is a gateway, not a load balanced service.

Where the tools come from

gw_* is the engine's registry: the builtins (read, write, edit, search, list, run, websearch, webfetch), folder_history, delegate, and the memory/skills tools. Plugins loaded with --plugin add theirs. The caller's tools are passed through to the provider untouched, except for the gw_ reservation.