| | #!/usr/bin/env bash |
| | set -euo pipefail |
| |
|
| | |
| | |
| | |
| |
|
| | ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| | CONFIG_FILE="${CONFIG_FILE:-${ROOT_DIR}/config.yaml}" |
| | BASE_URL="${BASE_URL:-http://localhost:7860}" |
| | CLIENT_KEY="${CLIENT_KEY:-${ANTHROPIC_API_KEY:-${CLAUDE_API_KEY:-}}}" |
| | MODEL="${MODEL:-claude-3-5-haiku-20241022}" |
| |
|
| | tmp_body="$(mktemp)" |
| | cleanup() { rm -f "$tmp_body"; } |
| | trap cleanup EXIT |
| |
|
| | info() { printf '[INFO] %s\n' "$*"; } |
| | warn() { printf '[WARN] %s\n' "$*" >&2; } |
| | fatal() { printf '[FAIL] %s\n' "$*" >&2; exit 1; } |
| |
|
| | info "Using BASE_URL=${BASE_URL}" |
| | info "Using MODEL=${MODEL}" |
| |
|
| | |
| | if [[ -f "$CONFIG_FILE" ]]; then |
| | if grep -nE 'DEIN_(CLAUDE|GEMINI|OPENROUTER)_KEY' "$CONFIG_FILE" >/dev/null; then |
| | warn "config.yaml still contains placeholder provider keys (DEIN_*). Upstream requests will fail." |
| | fi |
| | else |
| | warn "config file not found at ${CONFIG_FILE}" |
| | fi |
| |
|
| | |
| | [[ -n "$CLIENT_KEY" ]] || fatal "No client key set. Export CLIENT_KEY or ANTHROPIC_API_KEY or CLAUDE_API_KEY." |
| |
|
| | |
| | info "Checking /v1/models..." |
| | models_status=$(curl -sS -o "$tmp_body" -w '%{http_code}' \ |
| | -H "Authorization: Bearer ${CLIENT_KEY}" \ |
| | "${BASE_URL}/v1/models") || fatal "curl to /v1/models failed" |
| | if [[ "$models_status" != "200" ]]; then |
| | cat "$tmp_body" >&2 |
| | fatal "/v1/models returned HTTP ${models_status}" |
| | fi |
| | info "/v1/models OK" |
| |
|
| | |
| | info "Checking /v1/messages with model=${MODEL}..." |
| | payload=$(cat <<'JSON' |
| | { |
| | "model": "__MODEL__", |
| | "messages": [ |
| | {"role": "user", "content": "ping"} |
| | ], |
| | "max_tokens": 16 |
| | } |
| | JSON |
| | ) |
| | payload="${payload/__MODEL__/${MODEL}}" |
| |
|
| | msg_status=$(curl -sS -o "$tmp_body" -w '%{http_code}' \ |
| | -X POST "${BASE_URL}/v1/messages" \ |
| | -H "x-api-key: ${CLIENT_KEY}" \ |
| | -H "content-type: application/json" \ |
| | -d "$payload") || fatal "curl to /v1/messages failed" |
| |
|
| | if [[ "$msg_status" != "200" ]]; then |
| | cat "$tmp_body" >&2 |
| | fatal "/v1/messages returned HTTP ${msg_status}" |
| | fi |
| |
|
| | info "/v1/messages OK" |
| | info "Claude proxy looks healthy. You can run Claude Code with:" |
| | info "ANTHROPIC_API_KEY=${CLIENT_KEY} ANTHROPIC_BASE_URL=${BASE_URL} claude" |
| |
|