import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.nonelinear.com.cn/v1",
api_key=os.environ["NONELINEAR_API_KEY"],
timeout=120.0,
max_retries=0,
)
res = client.chat.completions.create(
model="deepseek-v4-flash", # 请替换为控制台模型列表中账号可用的 Model ID
messages=[{"role": "user", "content": "请只回复:连接正常"}],
)
print("响应 ID:", res.id)
if not res.choices or not (res.choices[0].message.content or "").strip():
raise RuntimeError("已收到响应但没有可见正文,请结合响应 ID、结束原因及用量排查")
print("结束原因:", res.choices[0].finish_reason)
print("返回内容:", res.choices[0].message.content)
print("用量明细:", res.usage)