Files
Zebratic c6b8a8a320 feat: add v1 health, messages, and status endpoints
- Add /v1/health endpoint for service health checks
- Add /v1/messages endpoint for Anthropic Messages API
- Add /v1/status endpoint for service status
- Add planning docs for Claude Code sessions feature
2026-03-12 05:20:46 +01:00

129 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
#
# Claude Code Setup Script
# Usage: ./scripts/claude-code-setup.sh <PROXY_URL> <TOKEN>
#
# This script configures Claude Code to use your LLM proxy instead of Anthropic API.
#
# Arguments:
# PROXY_URL: The base URL of your LLM proxy (e.g., https://your-proxy.com)
# TOKEN: Your API key from the proxy
#
# Example:
# ./scripts/claude-code-setup.sh https://api.yourdomain.com sk-your-api-key
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_error() {
echo -e "${RED}[✗]${NC} $1"
}
print_info() {
echo -e "${YELLOW}[i]${NC} $1"
}
# Check arguments
if [ $# -ne 2 ]; then
echo "Usage: $0 <PROXY_URL> <TOKEN>"
echo ""
echo "Arguments:"
echo " PROXY_URL The base URL of your LLM proxy (e.g., https://your-proxy.com)"
echo " TOKEN Your API key from the proxy"
echo ""
echo "Example:"
echo " $0 https://api.yourdomain.com sk-your-api-key"
exit 1
fi
PROXY_URL="$1"
TOKEN="$2"
print_info "Testing /status endpoint..."
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "${PROXY_URL}/status")
if [ "$STATUS_CODE" = "200" ]; then
print_status "Service is up (status endpoint returned 200)"
else
print_error "Service check failed (status endpoint returned $STATUS_CODE)"
exit 1
fi
print_info "Testing /health endpoint with token..."
HEALTH_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "x-api-key: ${TOKEN}" "${PROXY_URL}/health")
if [ "$HEALTH_CODE" = "200" ]; then
print_status "Token is valid (health endpoint returned 200)"
else
print_error "Token validation failed (health endpoint returned $HEALTH_CODE)"
exit 1
fi
print_info "Testing chat completions through proxy..."
CHAT_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "${PROXY_URL}/v1/chat/completions" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"model":"claude-3-5-sonnet-20241022","messages":[{"role":"user","content":"Hello"}],"max_tokens":10}')
if [ "$CHAT_CODE" = "200" ]; then
print_status "Chat completions working (returned 200)"
else
print_error "Chat completions test failed (returned $CHAT_CODE)"
exit 1
fi
print_info "Creating Claude Code settings..."
# Create settings directory if it doesn't exist
SETTINGS_DIR="$HOME/.claude"
mkdir -p "$SETTINGS_DIR"
# Create settings.json with proxy configuration
SETTINGS_FILE="$SETTINGS_DIR/settings.json"
# Create backup if file exists
if [ -f "$SETTINGS_FILE" ]; then
BACKUP_FILE="$SETTINGS_FILE.backup.$(date +%Y%m%d_%H%M%S)"
cp "$SETTINGS_FILE" "$BACKUP_FILE"
print_info "Backed up existing settings to $BACKUP_FILE"
fi
# Write new settings
cat > "$SETTINGS_FILE" << EOF
{
"ANTHROPIC_BASE_URL": "${PROXY_URL}/v1",
"ANTHROPIC_AUTH_TOKEN": "${TOKEN}",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "true",
"API_TIMEOUT_MS": "300000",
"MODEL_PREferences": {
"haiku": "claude-3-haiku-20240307",
"sonnet": "claude-3-5-sonnet-20241022",
"opus": "claude-3-opus-20240229"
}
}
EOF
print_status "Settings written to $SETTINGS_FILE"
print_info ""
print_info "Claude Code is now configured to use your proxy!"
print_info ""
print_info "Configuration:"
print_info " Proxy URL: ${PROXY_URL}"
print_info " Models:"
print_info " - Haiku: claude-3-haiku-20240307"
print_info " - Sonnet: claude-3-5-sonnet-20241022"
print_info " - Opus: claude-3-opus-20240229"
print_info ""
print_info "You can now use Claude Code with your proxy. If Claude Code was running,"
print_info "you may need to restart it for the changes to take effect."