Ollama v0.14.0 起兼容 Anthropic Messages API,Claude Code 可接开源模型
Claude Code with Anthropic API compatibility · Ollama Blog
Ollama v0.14.0 及之后版本兼容 Anthropic Messages API,使 Claude Code 这类工具可以用上开源模型,既能在本机跑本地模型,也能通过 ollama.com 连接云端模型。官方建议使用上下文长度至少 32K tokens 的模型,云端模型始终以完整上下文长度运行,编码场景推荐 glm-4.7:cloud 和 minimax-m2.1:cloud。已支持消息与多轮对话、流式输出、系统提示词、工具调用、扩展思考和图像输入,现有 Anthropic SDK 应用只需修改 base URL 即可接入。
推荐理由
精选AI 评分 66
Ollama 兼容 Anthropic Messages API 后,Claude Code 可直接接本地或云端开源模型,读者可据此判断自托管编码工作流的可行性。
主题
正文
当前显示原文,中文全文译文尚未就绪。
January 16, 2026
Ollama v0.14.0 and later are now compatible with the Anthropic Messages API, making it possible to use tools like Claude Code with open-source models.
Run Claude Code with local models on your machine, or connect to cloud models through ollama.com.
Using Claude Code with Ollama
Claude Code is Anthropic’s agentic coding tool that lives in your terminal. With Anthropic API support, you can now use Claude Code with any Ollama model.
Configure environment variables to use Ollama:
Run Claude Code with an Ollama model:
Models in Ollama’s Cloud also work with Claude Code:
It is recommended to run a model with at least 32K tokens context length.
For more information, please see context length documentation on how to make changes.
Ollama’s cloud models always run at their full context length.
Recommended models
For coding use cases with Claude Code:
glm-4.7:cloud; minimax-m2.1:cloud
Using the Anthropic SDK
Existing applications using the Anthropic SDK can connect to Ollama by changing the base URL. See the Anthropic compatibility documentation for details.
Models can use tools to interact with external systems:
Supported features
Messages and multi-turn conversations; Streaming; System prompts; Tool calling / function calling; Extended thinking; Vision (image input)
For a complete list of supported features, see the Anthropic compatibility documentation.
Learn more
For more detailed setup instructions and configuration options, see the Claude Code guide.