#!/usr/bin/env python3 import os import anthropic # 加载环境变量 with open("/home/atai/telegram-bot/.env") as f: for line in f: line = line.strip() if line and not line.startswith("#") and "=" in line: key, value = line.split("=", 1) os.environ[key] = value try: client = anthropic.Anthropic( api_key=os.environ.get('ANTHROPIC_AUTH_TOKEN'), base_url=os.environ.get('ANTHROPIC_BASE_URL', 'https://api.anthropic.com') ) print("测试模型: claude-sonnet-4-20250514") response = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=100, messages=[{"role": "user", "content": "你好,请用一句话介绍自己"}] ) print(f"✅ API调用成功!") print(f"响应: {response.content[0].text}") except Exception as e: print(f"❌ 错误: {e}")