You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MistralAI Python SDK调用本地Pixtral服务报错400的解决方法

问题解决方法

问题原因

mistralai SDK 1.2.3版本在调用chat.complete时,默认会自动向请求体中添加safe_prompt=False参数,但你的本地Pixtral服务器API不支持这个额外参数,因此返回400错误。

解决步骤

直接在chat.complete调用中显式设置safe_prompt=None,阻止SDK发送该参数:

from mistralai import Mistral

model = "mistralai/Pixtral-12B-2409"
client = Mistral(server_url="http://localhost:8000")

chat_response = client.chat.complete(
    messages=[
        {
            "role": "user",
            "content": "What is the best French cheese?"
        }
    ],
    model=model,
    safe_prompt=None  # 添加这一行,禁用默认的safe_prompt参数
)

print(chat_response.choices[0].message.content)

验证

修改后重新运行代码,请求将不再包含safe_prompt参数,与你之前正常工作的curl请求结构一致,即可成功获取服务器响应。

内容的提问来源于stack exchange,提问作者Javide

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 23:53:19