Team Ai
Apppublic

Yash030/claude-code-proxy

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes
test_cerebras_api.py71 linesDownload Raw Back to root
1"""Test Cerebras API key directly."""2 3import os4import httpx5from openai import AsyncOpenAI6 7CEREBRAS_API_KEY = "csk-2ewy2h26eeph4yex94kmjnfwwx35pdpyyxkv3j6wcj4cxc3t"8CEREBRAS_BASE_URL = "https://api.cerebras.ai/v1"9 10 11async def test_models_list():12    """Test listing models."""13    print("=== Testing /v1/models ===")14    async with httpx.AsyncClient() as client:15        try:16            response = await client.get(17                f"{CEREBRAS_BASE_URL}/models",18                headers={"Authorization": f"Bearer {CEREBRAS_API_KEY}"},19                timeout=10.0,20            )21            print(f"Status: {response.status_code}")22            print(f"Response: {response.text[:800]}")23        except Exception as e:24            print(f"Error: {e}")25 26 27async def test_chat():28    """Test a chat completion."""29    print("\n=== Testing /v1/chat/completions ===")30    client = AsyncOpenAI(31        api_key=CEREBRAS_API_KEY,32        base_url=CEREBRAS_BASE_URL,33        timeout=httpx.Timeout(60.0),34    )35 36    models_to_try = [37        "qwen-3-235b-a22b-instruct-2507",38        "zai-glm-4.7",39        "gpt-oss-120b",40        "llama3.1-8b",41    ]42 43    for model in models_to_try:44        print(f"\nTrying model: {model}")45        try:46            response = await client.chat.completions.create(47                model=model,48                messages=[{"role": "user", "content": "hi"}],49                max_tokens=20,50            )51            print(f"Success!")52            print(f"Model: {response.model}")53            print(f"Content: {response.choices[0].message.content}")54            break55        except Exception as e:56            error_text = str(e)57            if hasattr(e, "response") and e.response:58                error_text = e.response.text59            print(f"Error: {error_text[:300]}")60 61 62async def main():63    await test_models_list()64    await test_chat()65 66 67if __name__ == "__main__":68    import asyncio69 70    asyncio.run(main())71