"""Test Silicon Flow API key directly.""" import os import httpx from openai import AsyncOpenAI SILICON_API_KEY = "sk-vkswknrlhztbogulqjizbxpkdipbafudnirbrhzosxjkvmri" SILICON_BASE_URL = "https://api.siliconflow.cn/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"{SILICON_BASE_URL}/models", headers={"Authorization": f"Bearer {SILICON_API_KEY}"}, timeout=10.0, ) print(f"Status: {response.status_code}") print(f"Response: {response.text[:500]}") 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=SILICON_API_KEY, base_url=SILICON_BASE_URL, timeout=httpx.Timeout(30.0), ) models_to_try = [ "Qwen/Qwen3.6-35B-A3B", "Qwen3.6-35B-A3B", "Qwen/Qwen2.5-72B-Instruct", "Pro/Qwen/Qwen2.5-72B-Instruct", ] 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=10, ) print(f"Success! Response: {response}") break except Exception as e: error_text = str(e) # Extract useful part of error if hasattr(e, "response") and e.response: error_text = e.response.text print(f"Error: {error_text[:200]}") async def main(): await test_models_list() await test_chat() if __name__ == "__main__": import asyncio asyncio.run(main())