claude-code-proxy / test_cerebras_api.py
Yash030's picture
Add Cerebras, Silicon Flow, and Groq providers with debug logging.
db83b53
Raw
History Blame Contribute Delete
1.95 kB
"""Test Cerebras API key directly."""
import os
import httpx
from openai import AsyncOpenAI
CEREBRAS_API_KEY = "csk-2ewy2h26eeph4yex94kmjnfwwx35pdpyyxkv3j6wcj4cxc3t"
CEREBRAS_BASE_URL = "https://api.cerebras.ai/v1"
async def test_models_list():
"""Test listing models."""
print("=== Testing /v1/models ===")
async with httpx.AsyncClient() as client:
try:
response = await client.get(
f"{CEREBRAS_BASE_URL}/models",
headers={"Authorization": f"Bearer {CEREBRAS_API_KEY}"},
timeout=10.0,
)
print(f"Status: {response.status_code}")
print(f"Response: {response.text[:800]}")
except Exception as e:
print(f"Error: {e}")
async def test_chat():
"""Test a chat completion."""
print("\n=== Testing /v1/chat/completions ===")
client = AsyncOpenAI(
api_key=CEREBRAS_API_KEY,
base_url=CEREBRAS_BASE_URL,
timeout=httpx.Timeout(60.0),
)
models_to_try = [
"qwen-3-235b-a22b-instruct-2507",
"zai-glm-4.7",
"gpt-oss-120b",
"llama3.1-8b",
]
for model in models_to_try:
print(f"\nTrying model: {model}")
try:
response = await client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "hi"}],
max_tokens=20,
)
print(f"Success!")
print(f"Model: {response.model}")
print(f"Content: {response.choices[0].message.content}")
break
except Exception as e:
error_text = str(e)
if hasattr(e, "response") and e.response:
error_text = e.response.text
print(f"Error: {error_text[:300]}")
async def main():
await test_models_list()
await test_chat()
if __name__ == "__main__":
import asyncio
asyncio.run(main())