import os
import time
import asyncio
from litellm import acompletion
MODELS = [
"gpt-5.5",
"claude-opus-4-7",
"deepseek-v4-flash",
"coding-glm-5.1-free",
]
QUESTION = "If you could give a programmer only one piece of advice, what would it be?"
async def ask_model(model, question):
start = time.time()
try:
response = await acompletion(
model=f"openai/{model}",
api_base="https://aihubmix.com/v1",
api_key=os.environ.get("AIHUBMIX_API_KEY"),
messages=[{"role": "user", "content": question}]
)
return {
"model": model,
"answer": response.choices[0].message.content.strip(),
"tokens": response.usage.total_tokens,
"time": round(time.time() - start, 2),
"error": None
}
except Exception as e:
return {
"model": model,
"answer": None,
"tokens": 0,
"time": round(time.time() - start, 2),
"error": str(e)
}
async def main():
print(f"Question: {QUESTION}")
print("=" * 60)
tasks = [ask_model(m, QUESTION) for m in MODELS]
results = await asyncio.gather(*tasks)
for r in results:
print(f"\nModel: {r['model']}")
print(f"Time: {r['time']}s | Tokens: {r['tokens']}")
print("-" * 40)
if r["error"]:
print(f"Error: {r['error']}")
else:
print(r["answer"])
print("\n" + "=" * 60)
print(f"{'Model':<30} {'Time':>8} {'Tokens':>8}")
print("-" * 50)
for r in sorted(results, key=lambda x: x["time"]):
status = f"{r['time']}s" if not r["error"] else "failed"
print(f"{r['model']:<30} {status:>8} {r['tokens']:>8}")
asyncio.run(main())