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()