# Free-LLM Router installer for Windows - https://free-llm.com/router # irm https://free-llm.com/install.ps1 | iex # Installs into %USERPROFILE%\.free-llm and adds `free-llm` to your user PATH. No admin rights. # Node.js is not required: when it is missing (or older than 18) a private copy is downloaded # from nodejs.org into %USERPROFILE%\.free-llm\node. Nothing else on the system is touched. # Uninstall: delete the .free-llm folder. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # the progress bar makes downloads many times slower on Windows PowerShell 5.1 # Windows PowerShell 5.1 may default to TLS 1.0/1.1, which GitHub and nodejs.org refuse. try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch {} $url = if ($env:FREE_LLM_TARBALL) { $env:FREE_LLM_TARBALL } else { 'https://github.com/nejib1/Free-LLM/releases/latest/download/free-llm.tgz' } $root = if ($env:FREE_LLM_HOME) { $env:FREE_LLM_HOME } else { Join-Path $env:USERPROFILE '.free-llm' } $app = Join-Path $root 'app' $bin = Join-Path $root 'bin' $nodeDir = Join-Path $root 'node' $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ('free-llm-' + [guid]::NewGuid()) function Step($n, $text) { Write-Host "[$n/3] $text" -ForegroundColor Cyan } function NodeMajor($exe) { # Parse `node -v` (e.g. v24.14.0): Windows PowerShell 5.1 strips inner double quotes # from native arguments, so `node -p "..."` cannot be used here. try { $v = (& $exe -v 2>$null | Out-String).Trim() } catch { return 0 } if ($v -match '^v?(\d+)\.') { return [int]$Matches[1] } return 0 } function Download($from, $to) { for ($i = 1; $i -le 3; $i++) { try { Invoke-WebRequest -Uri $from -OutFile $to -UseBasicParsing; return } catch { if ($i -eq 3) { throw }; Start-Sleep -Seconds (2 * $i) } } } try { Write-Host '' Write-Host 'Free-LLM Router' -ForegroundColor White Write-Host 'Every free LLM API behind one local address. Installing for this user only, no admin rights.' Write-Host '' New-Item -ItemType Directory -Force -Path $root, $bin, $tmp | Out-Null # ---- 1. Node.js: use the one that is installed, or fetch a private copy ---- $nodeExe = $null $nodeCmd = $null # what the free-llm command calls: plain `node` when it is on PATH (version managers move it around) $sys = Get-Command node -ErrorAction SilentlyContinue if ($sys -and (NodeMajor $sys.Source) -ge 18) { $nodeExe = $sys.Source $nodeCmd = 'node' Step 1 "Node.js found ($((& $nodeExe -v | Out-String).Trim()))" } elseif ((Test-Path (Join-Path $nodeDir 'node.exe')) -and (NodeMajor (Join-Path $nodeDir 'node.exe')) -ge 18) { $nodeExe = Join-Path $nodeDir 'node.exe' Step 1 'Node.js: using the private copy already in .free-llm\node' } else { $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $line = 'latest-v24.x'; $cpu = 'x64' if ($arch -eq 'ARM64') { $cpu = 'arm64' } elseif ($arch -eq 'x86') { $cpu = 'x86'; $line = 'latest-v22.x' } # Node 24 has no 32-bit Windows build Step 1 'Node.js is not installed: downloading a private copy from nodejs.org (about 38 MB, one time)...' $base = "https://nodejs.org/dist/$line" $sums = (Invoke-WebRequest -Uri "$base/SHASUMS256.txt" -UseBasicParsing).Content if ($sums -is [byte[]]) { $sums = [Text.Encoding]::ASCII.GetString($sums) } $zipName = $null; $want = $null foreach ($l in ($sums -split "`n")) { if ($l -match "^([0-9a-f]{64})\s+(node-v[0-9.]+-win-$cpu\.zip)\s*$") { $want = $Matches[1]; $zipName = $Matches[2] } } if (-not $zipName) { throw "No Node.js build for this processor ($arch). Install Node.js 18+ from https://nodejs.org and run this installer again." } $zip = Join-Path $tmp $zipName Download "$base/$zipName" $zip $got = (Get-FileHash -Algorithm SHA256 -Path $zip).Hash.ToLower() if ($got -ne $want) { throw 'The Node.js download is damaged (checksum mismatch). Please run the installer again.' } # Only node.exe is needed: take that single file out of the archive. Add-Type -AssemblyName System.IO.Compression.FileSystem New-Item -ItemType Directory -Force -Path $nodeDir | Out-Null $archive = [System.IO.Compression.ZipFile]::OpenRead($zip) try { $entry = $archive.Entries | Where-Object { $_.FullName -match '^node-v[^/\\]+[/\\]node\.exe$' } | Select-Object -First 1 if (-not $entry) { throw 'node.exe was not found in the Node.js archive.' } $target = Join-Path $nodeDir 'node.exe' if (Test-Path $target) { Remove-Item -Force $target } [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target) } finally { $archive.Dispose() } $nodeExe = Join-Path $nodeDir 'node.exe' if ((NodeMajor $nodeExe) -lt 18) { throw 'The downloaded Node.js does not start on this computer. Install Node.js from https://nodejs.org and run this installer again.' } Write-Host " Node.js $((& $nodeExe -v | Out-String).Trim()) ready in $nodeDir (private to the router)" -ForegroundColor DarkGray } # ---- 2. The router itself ---- Step 2 'Downloading Free-LLM Router...' $tgz = Join-Path $tmp 'r.tgz' Download $url $tgz tar -xzf $tgz -C $tmp if ($LASTEXITCODE -ne 0 -or -not (Test-Path (Join-Path $tmp 'package'))) { throw 'Could not unpack the download (tar.exe is part of Windows 10 version 1803 and newer).' } # Stop a router that is running from the old files, so they can be replaced. $wasRunning = $false $oldCli = Join-Path $app 'router\bin\free-llm.js' if (Test-Path $oldCli) { try { $s = (& $nodeExe $oldCli status 2>$null | Out-String); if ($s -match 'running' -and $s -notmatch 'not running') { $wasRunning = $true; & $nodeExe $oldCli stop 2>$null | Out-Null; Start-Sleep -Seconds 1 } } catch {} } if (Test-Path $app) { Remove-Item -Recurse -Force $app } Move-Item (Join-Path $tmp 'package') $app Set-Content -Path (Join-Path $app '.install-method') -Value 'installer' -Encoding ASCII # ---- 3. The `free-llm` command ---- Step 3 'Adding the free-llm command...' $cli = Join-Path $app 'router\bin\free-llm.js' if (-not $nodeCmd) { $nodeCmd = "`"$nodeExe`"" } Set-Content -Path (Join-Path $bin 'free-llm.cmd') -Value "@echo off`r`n$nodeCmd `"$cli`" %*" -Encoding ASCII $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not $userPath) { $userPath = '' } if (-not ($userPath -split ';' | Where-Object { $_ -eq $bin })) { [Environment]::SetEnvironmentVariable('Path', ($userPath.TrimEnd(';') + ';' + $bin).TrimStart(';'), 'User') } if (-not ($env:Path -split ';' | Where-Object { $_ -eq $bin })) { $env:Path = $env:Path + ';' + $bin } $version = (& $nodeExe $cli version | Out-String).Trim() Write-Host '' Write-Host "Installed Free-LLM Router $version" -ForegroundColor Green Write-Host " Command: free-llm (works in any new terminal window)" -ForegroundColor DarkGray Write-Host " Files: $root" -ForegroundColor DarkGray Write-Host '' } catch { Write-Host '' Write-Host "The installation stopped: $($_.Exception.Message)" -ForegroundColor Red Write-Host 'Nothing was changed outside the .free-llm folder. You can run the installer again,' Write-Host 'or ask for help with the message above: https://github.com/nejib1/Free-LLM/issues' return } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } if ($env:FREE_LLM_NO_START) { return } if ($wasRunning) { & $nodeExe $cli start --daemon; return } & $nodeExe $cli }