feat: transparent anthropic api incl. native anthropic api backend

This commit is contained in:
Alpha Nerd 2026-07-06 10:46:18 +02:00
parent c9e495876b
commit 1d012a92ef
Signed by: alpha-nerd
SSH key fingerprint: SHA256:QkkAgVoYi9TQ0UKPkiKSfnerZy2h4qhi3SVPXJmBN+M
11 changed files with 1431 additions and 20 deletions

View file

@ -70,6 +70,16 @@ def llama_endpoints(cfg) -> list:
return list(dict.fromkeys([*cfg.llama_server_endpoints, *cfg.llama_swap_endpoints]))
def is_anthropic_endpoint(endpoint: str) -> bool:
"""True if the endpoint is a configured native Anthropic Messages-API backend.
These speak the Anthropic wire format (``x-api-key`` / ``anthropic-version``
headers, ``/v1/messages``), not OpenAI Chat Completions, so requests routed to
them are forwarded verbatim rather than translated.
"""
return endpoint in get_config().anthropic_endpoints
def is_ext_openai_endpoint(endpoint: str) -> bool:
"""
Determine if an endpoint is an external OpenAI-compatible endpoint (not Ollama, llama-server or llama-swap).
@ -117,8 +127,8 @@ def get_tracking_model(endpoint: str, model: str) -> str:
This ensures consistent model naming across all routes for usage tracking.
"""
# External OpenAI endpoints are not shown in PS, keep as-is
if is_ext_openai_endpoint(endpoint):
# External OpenAI / native Anthropic endpoints are not shown in PS, keep as-is
if is_ext_openai_endpoint(endpoint) or is_anthropic_endpoint(endpoint):
return model
# llama-server / llama-swap endpoints use normalized names in PS