#!/usr/bin/env python3 import json from urllib import request API_KEY = "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" # Try different model names models = [ "claude-sonnet-4-5-20250514", "claude-3-5-sonnet-20241022", "claude-3-haiku-20240307", "claude-sonnet-4-5-20250514", ] for model in models: try: body = json.dumps({ "model": model, "max_tokens": 20, "messages": [{"role": "user", "content": "Say hi"}], }).encode() req = request.Request( "https://api.anthropic.com/v1/messages", data=body, headers={ "x-api-key": API_KEY, "anthropic-version": "2023-06-01", "content-type": "application/json", }, method="POST", ) with request.urlopen(req, timeout=30) as resp: result = json.loads(resp.read().decode()) text = result.get("content", [{}])[0].get("text", "") print(f" {model}: OK - {text}") break except Exception as e: print(f" {model}: {e}")