#!/usr/bin/env python3
"""Test Qwen 3.7 Flash with reasoning.effort=none + response_format=json_object."""
import json, urllib.request
key = ""
with open("/etc/graphiti/graphiti.env") as f:
for line in f:
if line.startswith("OPENROUTER_API_KEY="):
key = line.split("=", 1)[1].strip()
break
# Test 1: With response_format AND reasoning.effort=none
payload1 = {
"model": "qwen/qwen3.7-flash",
"messages": [
{"role": "system", "content": "Output valid JSON only."},
{"role": "user", "content": "Respond with JSON containing key status with value ok"}
],
"max_tokens": 50,
"response_format": {"type": "json_object"},
"reasoning": {"effort": "none"}
}
req = urllib.request.Request(
"https://openrouter.ai/api/v1/chat/completions",
data=json.dumps(payload1).encode(),
headers={"Content-Type": "application/json", "Authorization": f"Bearer {key}"},
)
try:
resp = urllib.request.urlopen(req, timeout=60)
data = json.loads(resp.read())
c = data["choices"][0]["message"].get("content")
print(f"Test 1 (json_object + reasoning.none):")
print(f" HTTP OK: {resp.status}")
print(f" content NULL: {c is None}")
print(f" content: {repr(c)}")
except Exception as e:
print(f"Test 1 ERROR: {e}")
print()
# Test 2: Same WITHOUT reasoning.effort=none
payload2 = {
"model": "qwen/qwen3.7-flash",
"messages": [
{"role": "system", "content": "Output valid JSON only."},
{"role": "user", "content": "Respond with JSON containing key status with value ok"}
],
"max_tokens": 50,
"response_format": {"type": "json_object"}
}
req2 = urllib.request.Request(
"https://openrouter.ai/api/v1/chat/completions",
data=json.dumps(payload2).encode(),
headers={"Content-Type": "application/json", "Authorization": f"Bearer {key}"},
)
try:
resp2 = urllib.request.urlopen(req2, timeout=60)
data2 = json.loads(resp2.read())
c2 = data2["choices"][0]["message"].get("content")
r2 = data2["choices"][0]["message"].get("reasoning", "")
print(f"Test 2 (json_object NO reasoning override):")
print(f" HTTP OK: {resp2.status}")
print(f" content NULL: {c2 is None}")
print(f" reasoning present: {bool(r2)}")
if c2:
print(f" content: {repr(c2[:200])}")
except Exception as e:
print(f"Test 2 ERROR: {e}")