#!/usr/bin/env bash
# Requires curl with --fail-with-body and jq. Server-side only.
set -euo pipefail
: "${IRANNET_AI_ORIGIN:?Set the official HTTPS origin without /v1}"
: "${IRANNET_API_KEY:?Set the key privately on the server}"
: "${IRANNET_MODEL_ID:?Select a permitted model ID}"

curl --proto '=https' --fail-with-body --max-time 60 \
  "${IRANNET_AI_ORIGIN%/}/v1/models" \
  -H "Authorization: Bearer $IRANNET_API_KEY"

jq -n --arg model "$IRANNET_MODEL_ID" \
  '{model:$model,messages:[{role:"user",content:"یک سلام کوتاه فارسی بنویس."}]}' |
  curl --proto '=https' --fail-with-body --max-time 60 \
    "${IRANNET_AI_ORIGIN%/}/v1/chat/completions" \
    -H "Authorization: Bearer $IRANNET_API_KEY" \
    -H "Content-Type: application/json" --data-binary @-
