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

t() { local l="$1"; shift; printf '\n=== %s\n' "$l"
  curl -sS -o /tmp/b -w '  HTTP %{http_code} %{time_total}s\n' --max-time 40 -X POST "$U" \
    -H 'content-type: application/json' -H 'accept: text/event-stream' \
    -H 'x-opencode-client: desktop' "$@" -d "$B" 2>&1 | head -2
  printf '  '; head -c 200 /tmp/b | tr -d '\n'; echo; }

t "origin + referer" -H 'origin: https://opencode.ai' -H 'referer: https://opencode.ai/'
t "browser-like set" -H 'origin: https://opencode.ai' -H 'referer: https://opencode.ai/' \
  -H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'sec-fetch-dest: empty' \
  -H 'accept-language: en-US,en;q=0.9'
t "x-opencode-client: web" -H 'x-opencode-client: web' -H 'origin: https://opencode.ai'
