#!/usr/bin/env bash
set -Eeuo pipefail

: "${VARION_API_KEY:?Set VARION_API_KEY to the free Varion test key from your dashboard}"
VARION_ROOT="${VARION_BASE_URL:-https://api.varion.tech}"
VARION_ROOT="${VARION_ROOT%/}"
VARION_ROOT="${VARION_ROOT%/v1}"

curl --fail-with-body --silent --show-error \
  "$VARION_ROOT/v1/test/optimize" \
  -H "Authorization: Bearer $VARION_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "request": {
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "system", "content": "Answer clearly and use tools only when required."},
      {"role": "user", "content": "Confirm that order 12345 was received."},
      {"role": "user", "content": "Confirm that order 12345 was received."}
    ]
  }
}
JSON
printf '\n\nVarion optimise-only connection test completed. No provider key was required.\n'
