[PR #13600] [MERGED] api: implement anthropic api #14287

Closed
opened 2026-04-13 00:50:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13600
Author: @ParthSareen
Created: 1/2/2026
Status: Merged
Merged: 1/9/2026
Merged by: @ParthSareen

Base: mainHead: implement-anthropic-api


📝 Commits (10+)

  • 2b90199 api: add Anthropic Messages API compatibility layer
  • 214563a anthropic: add unit and integration tests
  • f5a85e8 anthropic: fix error handling and update docs
  • 3531fb5 anthropic: remove redundant comments
  • e9f4ef8 anthropic: fix streaming with SDK by including empty fields
  • 4ec2873 anthropic: add tests for SDK-required empty fields
  • b14ba52 docs: add Claude Code integration guide
  • 9a16ad3 anthropic: preserve messages with only thinking content
  • 01d12cd anthropic: use pointer types for Text and Thinking fields
  • 34257b6 middleware: fix test for pointer type Text field

📊 Changes

9 files changed (+2952 additions, -3 deletions)

View changed files

anthropic/anthropic.go (+778 -0)
anthropic/anthropic_test.go (+953 -0)
📝 docs/README.md (+1 -0)
docs/api/anthropic-compatibility.mdx (+406 -0)
📝 docs/docs.json (+9 -3)
docs/integrations/claude-code.mdx (+69 -0)
middleware/anthropic.go (+149 -0)
middleware/anthropic_test.go (+584 -0)
📝 server/routes.go (+3 -0)

📄 Description

Add middleware to support the Anthropic Messages API format at /v1/messages.
This enables tools like Claude Code to work with Ollama models through the Anthropic API interface.

Features:

  • Request/response transformation between Anthropic and internal formats
  • Streaming support with SSE events (message_start, content_block_delta, etc.)
  • Tool calling support (tool_use and tool_result content blocks)
  • Thinking/extended thinking block support
  • Image content block support (base64)
  • System prompt handling
  • Multi-turn conversation support
  • Proper stop_reason mapping (end_turn, max_tokens, tool_use)
  • Error responses in Anthropic format

New files:

  • anthropic/anthropic.go: Types and transformation functions
  • middleware/anthropic.go: Request/response middleware

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13600 **Author:** [@ParthSareen](https://github.com/ParthSareen) **Created:** 1/2/2026 **Status:** ✅ Merged **Merged:** 1/9/2026 **Merged by:** [@ParthSareen](https://github.com/ParthSareen) **Base:** `main` ← **Head:** `implement-anthropic-api` --- ### 📝 Commits (10+) - [`2b90199`](https://github.com/ollama/ollama/commit/2b90199b91841ddf5920183eccbdeff562d915c8) api: add Anthropic Messages API compatibility layer - [`214563a`](https://github.com/ollama/ollama/commit/214563ab171771f13c0fd92b6f4ff48afc9b8795) anthropic: add unit and integration tests - [`f5a85e8`](https://github.com/ollama/ollama/commit/f5a85e8ac662184e94d62feaa641a5213c2dc1bf) anthropic: fix error handling and update docs - [`3531fb5`](https://github.com/ollama/ollama/commit/3531fb5970438b03f4f0099d32bd848f9104d782) anthropic: remove redundant comments - [`e9f4ef8`](https://github.com/ollama/ollama/commit/e9f4ef84fbc8e0d81ade86f259a25ce2ecf94140) anthropic: fix streaming with SDK by including empty fields - [`4ec2873`](https://github.com/ollama/ollama/commit/4ec2873ed110f537dbffd03806308262f33169ef) anthropic: add tests for SDK-required empty fields - [`b14ba52`](https://github.com/ollama/ollama/commit/b14ba5285fa4204415f3a8a56bba6032729068bd) docs: add Claude Code integration guide - [`9a16ad3`](https://github.com/ollama/ollama/commit/9a16ad3857f7bc46c4a3a411cae597bc927ade73) anthropic: preserve messages with only thinking content - [`01d12cd`](https://github.com/ollama/ollama/commit/01d12cd98f216bc235addd3ca528eb8a7ea17071) anthropic: use pointer types for Text and Thinking fields - [`34257b6`](https://github.com/ollama/ollama/commit/34257b6e37de8750f7421f1fa08039a3daa26e79) middleware: fix test for pointer type Text field ### 📊 Changes **9 files changed** (+2952 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `anthropic/anthropic.go` (+778 -0) ➕ `anthropic/anthropic_test.go` (+953 -0) 📝 `docs/README.md` (+1 -0) ➕ `docs/api/anthropic-compatibility.mdx` (+406 -0) 📝 `docs/docs.json` (+9 -3) ➕ `docs/integrations/claude-code.mdx` (+69 -0) ➕ `middleware/anthropic.go` (+149 -0) ➕ `middleware/anthropic_test.go` (+584 -0) 📝 `server/routes.go` (+3 -0) </details> ### 📄 Description Add middleware to support the Anthropic Messages API format at /v1/messages. This enables tools like Claude Code to work with Ollama models through the Anthropic API interface. Features: - Request/response transformation between Anthropic and internal formats - Streaming support with SSE events (message_start, content_block_delta, etc.) - Tool calling support (tool_use and tool_result content blocks) - Thinking/extended thinking block support - Image content block support (base64) - System prompt handling - Multi-turn conversation support - Proper stop_reason mapping (end_turn, max_tokens, tool_use) - Error responses in Anthropic format New files: - anthropic/anthropic.go: Types and transformation functions - middleware/anthropic.go: Request/response middleware --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 00:50:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14287