Initial commit: llm-router — smart OpenAI/Anthropic/Ollama router

A stdlib pre-router in front of Ollama with LiteLLM backend:
- auto model selection by content/tools/modality, with fallbacks
- OpenAI /v1, Anthropic /v1/messages, and Ollama-native /api/* endpoints
- Whisper-shaped /v1/audio/transcriptions + in-chat audio
- key-based fleet policies (e.g. force a client onto uncensored models)
- optional Bearer auth; launchd/systemd service install
- benchmark harnesses (speed, quality, agentic tool use) with sample results

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Joseph Costa
2026-07-05 02:05:16 -05:00
co-authored by Claude Opus 4.8
commit 9938d46a67
32 changed files with 2419 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- macOS launchd user agent. Placeholders __INSTALL_DIR__ and __PATH__ are
filled in by deploy/install-service.sh. Do not install this template directly. -->
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.llm-router</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>__INSTALL_DIR__/run.sh</string>
</array>
<key>WorkingDirectory</key>
<string>__INSTALL_DIR__</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
<string>__INSTALL_DIR__/launchd.out.log</string>
<key>StandardErrorPath</key>
<string>__INSTALL_DIR__/launchd.err.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>__PATH__</string>
</dict>
</dict>
</plist>
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Install llm-router as a boot service: launchd on macOS, systemd (user) on Linux.
# Run from the repo root: ./deploy/install-service.sh
set -euo pipefail
cd "$(dirname "$0")/.."
INSTALL_DIR="$(pwd)"
PATH_VAL="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
fill() { sed -e "s|__INSTALL_DIR__|$INSTALL_DIR|g" -e "s|__PATH__|$PATH_VAL|g" "$1"; }
case "$(uname -s)" in
Darwin)
PLIST="$HOME/Library/LaunchAgents/com.llm-router.plist"
fill deploy/com.llm-router.plist.template > "$PLIST"
launchctl bootout "gui/$(id -u)/com.llm-router" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PLIST"
echo ">> installed launchd agent: $PLIST"
echo " status: launchctl print gui/$(id -u)/com.llm-router | grep state"
echo " logs: tail -f $INSTALL_DIR/launchd.out.log"
echo " remove: launchctl bootout gui/$(id -u)/com.llm-router && rm $PLIST"
;;
Linux)
UNIT_DIR="$HOME/.config/systemd/user"; mkdir -p "$UNIT_DIR"
fill deploy/llm-router.service.template > "$UNIT_DIR/llm-router.service"
systemctl --user daemon-reload
systemctl --user enable --now llm-router.service
echo ">> installed systemd user service"
echo " status: systemctl --user status llm-router"
echo " logs: journalctl --user -u llm-router -f"
echo " remove: systemctl --user disable --now llm-router && rm $UNIT_DIR/llm-router.service"
echo " (tip: 'loginctl enable-linger $USER' to run without being logged in)"
;;
*) echo "Unsupported OS: $(uname -s). Run ./run.sh manually or add your own unit."; exit 1 ;;
esac
+16
View File
@@ -0,0 +1,16 @@
# systemd user service (Linux). Placeholders filled by deploy/install-service.sh.
# Installed to ~/.config/systemd/user/llm-router.service
[Unit]
Description=llm-router — smart router in front of Ollama
After=network.target
[Service]
Type=simple
WorkingDirectory=__INSTALL_DIR__
ExecStart=/bin/bash __INSTALL_DIR__/run.sh
Restart=always
RestartSec=10
Environment=PATH=__PATH__
[Install]
WantedBy=default.target