cliproxy-api / Start-API.ps1
godzilla865's picture
Add startup scripts for API and Cloudflare tunnel
2ebab25
# CLIProxyAPI Startup Script
# Run this to start the API with a public tunnel
Write-Host "Starting CLIProxyAPI..." -ForegroundColor Cyan
# Stop existing container if running
docker stop cliproxy-api 2>$null
docker rm cliproxy-api 2>$null
# Start the container with restart policy
docker run -d --name cliproxy-api -p 8317:8317 --restart unless-stopped cliproxy-api:latest
Write-Host "Container started. Waiting for API to initialize..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
# Test local API
try {
$response = Invoke-RestMethod -Uri "http://localhost:8317/v1/models" -Headers @{Authorization="Bearer sk-cItvhSBsi7KWnTDZqfFX5gzuVURodOL8pPj1CbyJreAk3HYG"}
Write-Host "Local API is running with $($response.data.Count) models" -ForegroundColor Green
} catch {
Write-Host "Warning: Could not connect to local API" -ForegroundColor Red
}
# Kill any existing cloudflared processes
Get-Process cloudflared -ErrorAction SilentlyContinue | Stop-Process -Force
# Start Cloudflare tunnel
Write-Host "Starting Cloudflare tunnel..." -ForegroundColor Yellow
$tunnelLog = "$env:TEMP\cloudflared-tunnel.log"
Start-Process -FilePath "cloudflared" -ArgumentList "tunnel", "--url", "http://localhost:8317" -WindowStyle Hidden -RedirectStandardError $tunnelLog
Start-Sleep -Seconds 10
# Get tunnel URL
$tunnelUrl = Get-Content $tunnelLog | Select-String "trycloudflare.com" | Select-Object -First 1
if ($tunnelUrl) {
$url = ($tunnelUrl -split "\s+")[-1] -replace "\|", ""
Write-Host ""
Write-Host "============================================" -ForegroundColor Green
Write-Host "API is now publicly accessible!" -ForegroundColor Green
Write-Host ""
Write-Host "Public URL: $url" -ForegroundColor Cyan
Write-Host "API Key: sk-cItvhSBsi7KWnTDZqfFX5gzuVURodOL8pPj1CbyJreAk3HYG" -ForegroundColor Yellow
Write-Host "============================================" -ForegroundColor Green
} else {
Write-Host "Tunnel URL not found yet. Check $tunnelLog" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Press any key to exit (API will continue running in background)..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")