Skip to main content

Proxy server that forwards HTTP requests to a kiapi instance over a relay and returns the result (JSON, files, and chat event streams). Runs anywhere, no MLX required.

Project description

kiapi-proxy

English | 日本語

kiapi-proxy is a proxy server that accepts HTTP requests, forwards them to a kiapi instance over a relay, and returns the result. It relays every kiapi endpoint:

  • JSON responses
  • file / binary responses
  • chat text/event-stream responses (re-emitted as Server-Sent Events)

kiapi only runs on capable Apple Silicon Macs, but kiapi-proxy runs on Linux, Windows, and resource-constrained Macs. It depends only on kiapi-relay (not on kiapi or MLX), so it installs without any heavy inference dependencies.

Installation

pip install kiapi-proxy

# With the GCP relay backend
pip install "kiapi-proxy[relay-gcp]"

Usage

Configure the relay (shared with kiapi via KIAPI_RELAY_* environment variables), then start the proxy:

# Forward through the local filesystem relay
export KIAPI_RELAY_DEFAULT=local
export KIAPI_RELAY_LOCAL_ROOT=/shared/kiapi/relay

kiapi-proxy run --host 0.0.0.0 --port 8080
# or pick the relay explicitly:
kiapi-proxy run --relay local

Then call it as if it were kiapi:

curl http://localhost:8080/health
curl http://localhost:8080/openapi.json
curl -X POST http://localhost:8080/v1/chat/completions \
  -H 'content-type: application/json' \
  -d '{"messages":[{"role":"user","content":"hello"}],"stream":true}'

Command line interface

kiapi-proxy mirrors the kiapi command layout, with its own settings file and service registration so the proxy is managed independently from kiapi.

kiapi-proxy run       # start the proxy server
kiapi-proxy check     # check the relay link to kiapi without starting the server
kiapi-proxy config    # manage the user settings file
kiapi-proxy service   # manage the launchd user service (macOS)

Settings file

The proxy keeps its own user settings file, separate from kiapi's:

kiapi-proxy config init      # create it if it does not exist
kiapi-proxy config show      # print the current file
kiapi-proxy config edit      # open it in $EDITOR / $VISUAL
kiapi-proxy config template  # print the full commented template

The file lives in the user config directory (for example ~/.config/kiapi-proxy/settings.yaml) and holds the proxy settings (kiapi_proxy.api) and the relay settings (kiapi_relay). Values set here are loaded on every command; environment variables still take precedence.

Health check

Confirm that requests can travel over the relay to a live kiapi node without starting the proxy server:

kiapi-proxy check --relay local
kiapi-proxy check --relay gcp

check sends a single request (default /health) through the relay and prints the response. Use --path to probe another endpoint and --timeout to bound the wait. Without --relay it falls back to the configured proxy/relay default. It reuses the proxy's persistent relay node ID and holds the single-instance lock, so it fails fast if the proxy server is already running.

Service (macOS)

Register a launchd user agent (io.github.kiarina.kiapi-proxy) that runs kiapi-proxy run, independent from the kiapi service:

kiapi-proxy service install
kiapi-proxy service start
kiapi-proxy service status    # includes an end-to-end /health probe through the relay
kiapi-proxy service stop
kiapi-proxy service uninstall

Configuration

Environment variable Default Description
KIAPI_PROXY_HOST 127.0.0.1 Bind host.
KIAPI_PROXY_PORT 8080 Bind port.
KIAPI_PROXY_RELAY (relay default) Relay specifier to forward through. Falls back to KIAPI_RELAY_DEFAULT.
KIAPI_PROXY_REQUEST_TIMEOUT_S 1800 Maximum time to wait for a relayed response.

Relay backends are configured through kiapi-relay (KIAPI_RELAY_*). See the kiapi-relay documentation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiapi_proxy-0.3.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kiapi_proxy-0.3.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file kiapi_proxy-0.3.0.tar.gz.

File metadata

  • Download URL: kiapi_proxy-0.3.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.20

File hashes

Hashes for kiapi_proxy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 152d2f3bcfe58e0f2773694fa7821ef1ed299396511c85ee1cf2b8b8208c028e
MD5 48495a98a15e99be14ccba286ab65267
BLAKE2b-256 01cb1fe52d32f2a3b7c57254449f81ef3de074e58de4ef1438d4f4edb071d004

See more details on using hashes here.

File details

Details for the file kiapi_proxy-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kiapi_proxy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba46f3752218bad7c7eb7a331ba5323a05697df9499aa95d77340d916a3ef424
MD5 841d14bcd5eeb7605c2c3ea61ee10881
BLAKE2b-256 208de36a79ef05e449d777e974670df4a371c19242757d1f788e7998aef64f87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page