#!/bin/bash
export LC_ALL=C
BODY='{"model":"mimo-v2.6-flash-free","messages":[{"role":"user","content":"hi"}],"stream":true,"max_tokens":16}'
U=https://opencode.ai/zen/v1/chat/completions

try() {
  local label="$1"; shift
  printf '\n=== %s\n' "$label"
  curl -sS -o /tmp/b -w '  HTTP %{http_code}  %{time_total}s\n' --max-time 40 -X POST "$U" \
    -H 'Content-Type: application/json' -d "$BODY" "$@" 2>&1 | head -2
  printf '  '; head -c 220 /tmp/b | tr -d '\n'; echo
}

try "UA=opencode/1.18.31 + client header" \
  -H 'User-Agent: opencode/1.18.31' -H 'x-opencode-client: desktop' -H 'Accept: text/event-stream'

try "UA only (no client header)" \
  -H 'User-Agent: opencode/1.18.31' -H 'Accept: text/event-stream'

try "UA + client + json accept" \
  -H 'User-Agent: opencode/1.18.31' -H 'x-opencode-client: desktop' -H 'Accept: application/json'

try "UA + client, non-stream" \
  -H 'User-Agent: opencode/1.18.31' -H 'x-opencode-client: desktop' -H 'Accept: text/event-stream' \
  --data-binary '{"model":"mimo-v2.6-flash-free","messages":[{"role":"user","content":"hi"}]}'
