import anthropic
import config

def check_credits():
    print("💎 Testing Anthropic API Connection & Credits...")
    client = anthropic.Anthropic(api_key=config.ANTHROPIC_API_KEY)
    
    try:
        # Minimum possible usage: 1 token input
        response = client.messages.create(
            model=config.LLM_MODEL,
            max_tokens=1,
            messages=[{"role": "user", "content": "hi"}]
        )
        print("✅ SUCCESS: API is active and credits are available.")
        print(f"   Response Preview: {response.content[0].text}")
    except anthropic.BadRequestError as e:
        if "credit balance" in str(e).lower():
            print("\n❌ FAILED: Your Anthropic credit balance is EMPTY.")
            print("👉 Please add credits at: https://console.anthropic.com/settings/plans")
        else:
            print(f"\n❌ FAILED: API Error (Bad Request): {e}")
    except Exception as e:
        print(f"\n❌ FAILED: Unexpected Error: {e}")

if __name__ == "__main__":
    check_credits()
