快速结论:当 LlamaIndex 配合 DeepSeek 模型使用 OpenAILike 时,会因默认调用已废弃的 /v1/completions 文本补全端点而返回 400 Bad Request。优先排查是否显式设置了 is_chat_model=True,并确认 model 与 api_base 参数没有写反。
适用环境:LlamaIndex(版本范围 >=0.14.24,<0.15.0),llama-index-llms-openai-like 集成包,DeepSeek API(主域名 https://api.deepseek.com)。Issue 中未涉及 CUDA、显卡、Python 版本或操作系统信息。
最快修复方案:在 OpenAILike 初始化时显式添加 is_chat_model=True,让请求走 /v1/chat/completions 端点,这是 Issue 中明确验证过的解决方法。
注意事项:同时建议把 model 参数改为实际模型名(如 deepseek-chat)而不是 URL,并把 api_base 设为 API 地址;原始代码中两个参数值写反了,这属于已知的人为配置错误。
问题场景
用户在 LlamaIndex 中通过 OpenAILike 类接入 DeepSeek 模型,调用 complete() 方法时触发 400 Bad Request。框架实际请求的是 https://api.deepseek.com/v1/completions,而 DeepSeek 在主域名上已废弃该文本补全端点。
报错原文
Exception has occurred: BadRequestError
Error code: 400 - {'error': {'message': 'completions api is only available when using beta api (set base_url="https://api.deepseek.com/beta")', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.deepseek.com/v1/completions'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
openai.BadRequestError: Error code: 400 - {'error': {'message': 'completions api is only available when using beta api (set base_url="https://api.deepseek.com/beta")', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
原因分析
根本原因是 OpenAILike 的 is_chat_model 参数默认值为 False。当它为 False 时,无论调用 complete() 还是 chat(),都会统一路由到 /v1/completions 文本端点。DeepSeek 已在主域名上废弃该端点,因此返回 400。
另外原始代码中 model 和 api_base 的值被写反了:model 应传模型名(deepseek-chat),api_base 才传 URL,这可能是导致行为异常的又一因素。
环境排查
- 确认 LlamaIndex 版本是否在
>=0.14.24,<0.15.0范围内。 - 确认已安装
llama-index-llms-openai-like且与主 LlamaIndex 版本匹配。 - 确认
model参数传的是 DeepSeek 模型名(如deepseek-chat、deepseek-reasoner),而不是 URL。 - 确认
api_base参数传的是https://api.deepseek.com/v1这类 API 地址。
解决步骤
- 打开调用
OpenAILike的代码文件,检查model和api_base参数是否写反,修正为模型名与 API 地址各归其位。 - 在初始化参数中显式加入
is_chat_model=True,必要时一并设置is_function_calling_model=True以启用 DeepSeek 的函数调用能力。 - 参考修正后的参数写法重新初始化:
online_llm = OpenAILike( model="deepseek-chat", api_base="https://api.deepseek.com/v1", api_key="sk-...", temperature=0.1, context_window=16384, is_chat_model=True, is_function_calling_model=True, system_prompt="You are a senior backend developer", ) response = online_llm.complete("can you explain distributed systems like I'm 5") - 重新运行代码,确认不再请求
/v1/completions端点。
验证方法
重新执行 complete() 调用,若不再出现 400 Bad Request 且能正常返回文本,即可确认问题解决。也可以观察请求日志,确认目标 URL 已变为 https://api.deepseek.com/v1/chat/completions。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。

![[BUG] `crewai create` offers 7 retired Anthropic model ids that 404 on first call](https://www.chat-gpts.plus/wp-content/uploads/2026/08/7124-c5bd0d53-768x403.jpg)
