#!/usr/bin/env python3 import os import asyncio from claude_agent_sdk import ClaudeSDKClient # 设置环境变量 - 包括 BASE_URL os.environ['ANTHROPIC_AUTH_TOKEN'] = 'cr_9792f20a98f055e204248a41f280780ca2fb8f08f35e60c785e5245653937e06' os.environ['ANTHROPIC_BASE_URL'] = 'http://202.79.167.23:3000/api/' async def test(): print('Testing with BASE_URL proxy...') try: client = ClaudeSDKClient() await client.connect() info = await client.get_server_info() print('Account info:', info.get('account')) await client.query('你好,请简单回复') response_text = '' async for chunk in client.receive_response(): chunk_str = str(chunk) if 'AssistantMessage' in chunk_str and 'text=' in chunk_str: import re match = re.search(r"text='([^']*)'", chunk_str) if match: response_text += match.group(1) print('AI Reply:', response_text if response_text else 'No text extracted') await client.disconnect() return 'Error' not in response_text and 'forbidden' not in response_text except Exception as e: print('Failed:', e) import traceback traceback.print_exc() return False if __name__ == '__main__': result = asyncio.run(test()) print('\nResult:', 'SUCCESS!' if result else 'FAILED')