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

: "${LITELLM_BASE_URL:=http://localhost:4000}"
: "${LITELLM_PROXY_KEY:?Set LITELLM_PROXY_KEY first}"
: "${BATCH_FILE:=litellm_batch_requests_1500_llama8b.jsonl}"

file_json=$(curl -sS "$LITELLM_BASE_URL/v1/files"   -H "Authorization: Bearer $LITELLM_PROXY_KEY"   -F purpose="batch"   -F file="@$BATCH_FILE")

file_id=$(printf '%s' "$file_json" | python -c 'import sys,json; print(json.load(sys.stdin)["id"])')
echo "Uploaded batch file: $file_id"

batch_json=$(curl -sS "$LITELLM_BASE_URL/v1/batches"   -H "Authorization: Bearer $LITELLM_PROXY_KEY"   -H "Content-Type: application/json"   -d "{"input_file_id":"$file_id","endpoint":"/v1/chat/completions","completion_window":"24h","metadata":{"run_id":"cubie_wwt_zero_1500_llama8b"}}")

echo "$batch_json"
