[PR #21] [CLOSED] feat: add Anthropic (Claude) API compatibility #58

Closed
opened 2026-02-27 07:17:45 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jwadow/kiro-gateway/pull/21
Author: @Indokq
Created: 1/8/2026
Status: Closed

Base: mainHead: feat/anthropic-compat-jwadow


📝 Commits (3)

  • cc21188 feat: add Anthropic API compatibility
  • 30c80e5 fix: stabilize auth and config for tests
  • 0c796ea fix: close clients and aggregate tool call deltas

📊 Changes

9 files changed (+1147 additions, -8 deletions)

View changed files

kiro_gateway/anthropic_converters.py (+277 -0)
kiro_gateway/anthropic_models.py (+98 -0)
kiro_gateway/anthropic_streaming.py (+183 -0)
📝 kiro_gateway/config.py (+1 -1)
📝 kiro_gateway/routes.py (+355 -1)
📝 main.py (+8 -6)
tests/unit/test_anthropic_converters.py (+73 -0)
tests/unit/test_anthropic_routes.py (+107 -0)
tests/unit/test_anthropic_streaming.py (+45 -0)

📄 Description

Summary

Adds an Anthropic/Claude-compatible API surface on top of the existing OpenAI-compatible gateway using header-based routing (presence of the anthropic-version header to disambiguate /v1/models) and dual auth header support (Authorization: Bearer ... or x-api-key).

API additions

  • POST /v1/messages (streaming and non-streaming)
  • POST /v1/messages/count_tokens
  • GET /v1/models and GET /v1/models/{model_id} when anthropic-version is present
  • In-memory Message Batches API: POST/GET /v1/messages/batches* with NDJSON results streaming

Implementation notes

  • Adds permissive Pydantic request models for Anthropic payloads
  • Converts Anthropic Messages ↔ OpenAI ChatCompletions (including tool_use/tool_result mapping)
  • Adapts OpenAI SSE streaming into Claude SSE events (message_start, content_block_*, message_delta, message_stop)

Test/Dev stability

  • Skips config validation on import when running under pytest
  • Aligns default PROXY_API_KEY with existing test expectations

Verification

  • python -m pytest

🔄 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/jwadow/kiro-gateway/pull/21 **Author:** [@Indokq](https://github.com/Indokq) **Created:** 1/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/anthropic-compat-jwadow` --- ### 📝 Commits (3) - [`cc21188`](https://github.com/jwadow/kiro-gateway/commit/cc21188ae2dbc7c01beecccc88761b58a5ab2b4e) feat: add Anthropic API compatibility - [`30c80e5`](https://github.com/jwadow/kiro-gateway/commit/30c80e59823dae18ab94521d8b95512b03d9d65b) fix: stabilize auth and config for tests - [`0c796ea`](https://github.com/jwadow/kiro-gateway/commit/0c796ea126f2d1cead12e66656ba11a4a10b5ff7) fix: close clients and aggregate tool call deltas ### 📊 Changes **9 files changed** (+1147 additions, -8 deletions) <details> <summary>View changed files</summary> ➕ `kiro_gateway/anthropic_converters.py` (+277 -0) ➕ `kiro_gateway/anthropic_models.py` (+98 -0) ➕ `kiro_gateway/anthropic_streaming.py` (+183 -0) 📝 `kiro_gateway/config.py` (+1 -1) 📝 `kiro_gateway/routes.py` (+355 -1) 📝 `main.py` (+8 -6) ➕ `tests/unit/test_anthropic_converters.py` (+73 -0) ➕ `tests/unit/test_anthropic_routes.py` (+107 -0) ➕ `tests/unit/test_anthropic_streaming.py` (+45 -0) </details> ### 📄 Description ## Summary Adds an Anthropic/Claude-compatible API surface on top of the existing OpenAI-compatible gateway using header-based routing (presence of the anthropic-version header to disambiguate /v1/models) and dual auth header support (Authorization: Bearer ... or x-api-key). ## API additions - POST /v1/messages (streaming and non-streaming) - POST /v1/messages/count_tokens - GET /v1/models and GET /v1/models/{model_id} when anthropic-version is present - In-memory Message Batches API: POST/GET /v1/messages/batches* with NDJSON results streaming ## Implementation notes - Adds permissive Pydantic request models for Anthropic payloads - Converts Anthropic Messages ↔ OpenAI ChatCompletions (including tool_use/tool_result mapping) - Adapts OpenAI SSE streaming into Claude SSE events (message_start, content_block_*, message_delta, message_stop) ## Test/Dev stability - Skips config validation on import when running under pytest - Aligns default PROXY_API_KEY with existing test expectations ## Verification - python -m pytest --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 07:17:45 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/kiro-gateway-jwadow#58
No description provided.