| """Verify teacher API keys work.""" |
|
|
| import os |
| import sys |
| from pathlib import Path |
|
|
| |
| from dotenv import load_dotenv |
| load_dotenv(Path(__file__).parent.parent / ".env") |
|
|
| import httpx |
|
|
| def test_anthropic(): |
| key = os.getenv("BEE_TEACHER_API_KEY", "") |
| if not key: |
| print("[SKIP] Anthropic: No key set") |
| return False |
| try: |
| r = httpx.post( |
| "https://api.anthropic.com/v1/messages", |
| headers={ |
| "x-api-key": key, |
| "anthropic-version": "2023-06-01", |
| "content-type": "application/json", |
| }, |
| json={ |
| "model": "claude-sonnet-4-20250514", |
| "max_tokens": 50, |
| "messages": [{"role": "user", "content": "Say 'Bee teacher connected' and nothing else."}], |
| }, |
| timeout=15, |
| ) |
| if r.status_code == 200: |
| text = r.json()["content"][0]["text"] |
| print(f"[OK] Anthropic Claude: {text.strip()}") |
| return True |
| else: |
| print(f"[FAIL] Anthropic: {r.status_code} β {r.text[:200]}") |
| return False |
| except Exception as e: |
| print(f"[FAIL] Anthropic: {e}") |
| return False |
|
|
|
|
| def test_openai(): |
| key = os.getenv("BEE_OPENAI_API_KEY", "") |
| if not key: |
| print("[SKIP] OpenAI: No key set") |
| return False |
| try: |
| r = httpx.post( |
| "https://api.openai.com/v1/chat/completions", |
| headers={ |
| "Authorization": f"Bearer {key}", |
| "Content-Type": "application/json", |
| }, |
| json={ |
| "model": "gpt-4o-mini", |
| "max_tokens": 50, |
| "messages": [{"role": "user", "content": "Say 'Bee teacher connected' and nothing else."}], |
| }, |
| timeout=15, |
| ) |
| if r.status_code == 200: |
| text = r.json()["choices"][0]["message"]["content"] |
| print(f"[OK] OpenAI GPT-4o-mini: {text.strip()}") |
| return True |
| else: |
| print(f"[FAIL] OpenAI: {r.status_code} β {r.text[:200]}") |
| return False |
| except Exception as e: |
| print(f"[FAIL] OpenAI: {e}") |
| return False |
|
|
|
|
| def test_google(): |
| key = os.getenv("BEE_GOOGLE_API_KEY", "") |
| if not key: |
| print("[SKIP] Google: No key set") |
| return False |
| try: |
| r = httpx.post( |
| f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key={key}", |
| headers={"Content-Type": "application/json"}, |
| json={ |
| "contents": [{"parts": [{"text": "Say 'Bee teacher connected' and nothing else."}]}], |
| "generationConfig": {"maxOutputTokens": 50}, |
| }, |
| timeout=15, |
| ) |
| if r.status_code == 200: |
| text = r.json()["candidates"][0]["content"]["parts"][0]["text"] |
| print(f"[OK] Google Gemini: {text.strip()}") |
| return True |
| else: |
| print(f"[FAIL] Google: {r.status_code} β {r.text[:200]}") |
| return False |
| except Exception as e: |
| print(f"[FAIL] Google: {e}") |
| return False |
|
|
|
|
| if __name__ == "__main__": |
| print("=" * 50) |
| print("BEE TEACHER API β CONNECTION TEST") |
| print("=" * 50) |
| results = [] |
| results.append(("Anthropic", test_anthropic())) |
| results.append(("OpenAI", test_openai())) |
| results.append(("Google", test_google())) |
|
|
| ok = sum(1 for _, v in results if v) |
| print(f"\n{ok}/3 teacher APIs connected") |
| print("=" * 50) |
|
|