#!/usr/bin/env python3 """Test Dify native API (not the OpenAI proxy) to see raw response.""" import json import httpx # The composite key format is: || # Dify native API base: http://yw-dify.dc.servyou-it.com/v1 # Dify app API key: app-JWI7u1LTn9XPVe95KL6dHzPx DIFY_NATIVE_BASE = "http://yw-dify.dc.servyou-it.com/v1" API_KEY = "app-JWI7u1LTn9XPVe95KL6dHzPx" # Test 1: Dify native chat-messages API url = f"{DIFY_NATIVE_BASE}/chat-messages" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", } body = { "inputs": {}, "query": "我要申请VPN", "response_mode": "blocking", "user": "test_user", } print(f"=== Dify Native API: {url} ===") try: resp = httpx.post(url, json=body, headers=headers, timeout=30.0) print(f" HTTP: {resp.status_code}") print(f" Headers: {dict(resp.headers)}") print(f" Body: {resp.text[:2000]}") if resp.status_code == 200: data = resp.json() print(f"\n Parsed:") print(f" answer: {data.get('answer', '')[:500]}") print(f" conversation_id: {data.get('conversation_id', '')}") print(f" message_id: {data.get('message_id', '')}") # Check if answer is JSON answer = data.get("answer", "") try: parsed = json.loads(answer) print(f" Parsed JSON: {json.dumps(parsed, ensure_ascii=False, indent=2)}") except: print(f" Answer is NOT JSON: {answer[:200]}") except Exception as e: print(f" ERROR: {type(e).__name__}: {e}") # Test 2: Also try /completion-messages (for completion apps) url2 = f"{DIFY_NATIVE_BASE}/completion-messages" body2 = { "inputs": {}, "query": "我要申请VPN", "response_mode": "blocking", "user": "test_user", } print(f"\n=== Dify Completion API: {url2} ===") try: resp = httpx.post(url2, json=body2, headers=headers, timeout=30.0) print(f" HTTP: {resp.status_code}") print(f" Body: {resp.text[:1000]}") except Exception as e: print(f" ERROR: {type(e).__name__}: {e}")