#!/usr/bin/env bash # TheClaudeAPI setup for macOS / Linux # Usage: curl -fsSL https://aisoftdeal.com/setup.sh | bash set -eu BASE="https://aisoftdeal.com/api/public" STATUS_URL="https://aisoftdeal.com/api/public/v1/key-status" echo "" echo "== TheClaudeAPI setup ==" if ! command -v curl >/dev/null 2>&1; then echo "Error: curl is required."; exit 1; fi KEY="$(printenv THECLAUDEAPI_KEY || true)" if [ -z "$KEY" ]; then if [ -r /dev/tty ]; then printf "Enter your API key (sk-...): " > /dev/tty read -r KEY < /dev/tty else echo "Error: no terminal. Run: THECLAUDEAPI_KEY=sk-... bash setup.sh"; exit 1 fi fi KEY="$(printf "%s" "$KEY" | tr -d '[:space:]')" # Only letters, digits, "-" and "_" are allowed, so the key is safe to write into JSON and shell profiles. if ! printf "%s" "$KEY" | grep -Eq '^(sk|kx)-[A-Za-z0-9_-]{10,200}$'; then echo "Error: invalid key format. Paste the full key starting with sk-"; exit 1 fi echo "Checking your key..." RESP="$(curl -sL -w "\n%{http_code}" -H "x-api-key: $KEY" "$STATUS_URL" || true)" CODE="$(printf "%s" "$RESP" | tail -n 1)" BODY="$(printf "%s" "$RESP" | sed '$d')" if [ "$CODE" != "200" ]; then echo "Key check failed (HTTP $CODE): $BODY"; exit 1; fi case "$BODY" in *'"status":"active"'*) ;; *) echo "Key is not active: $BODY"; exit 1;; esac echo "Key OK." DIR="$HOME/.claude" FILE="$DIR/settings.json" mkdir -p "$DIR" if [ -f "$FILE" ]; then cp "$FILE" "$FILE.bak.$(date +%s)"; echo "Backed up old settings.json"; fi cat > "$FILE" <>> theclaudeapi >>>/,/# <<< theclaudeapi <</dev/null || true cat >> "$RC" <>> theclaudeapi >>> export ANTHROPIC_BASE_URL="$BASE" export ANTHROPIC_AUTH_TOKEN="$KEY" export OPENAI_BASE_URL="$BASE/v1" export OPENAI_API_KEY="$KEY" # <<< theclaudeapi <<< EOF echo "Updated $RC" done echo "" echo "Done. Open a NEW terminal (or restart VS Code) and run: claude"