mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-14 04:09:09 +00:00
fix(anthropic): handle /v1-suffixed api_base in _build_count_tokens_url
api_base values ending in /v1 fell through to the catch-all branch and produced a doubled path (/v1/v1/messages/count_tokens). Add an explicit branch to append /messages/count_tokens in that case.
This commit is contained in:
parent
f8eaf7f8bd
commit
ca73e3de44
2 changed files with 11 additions and 0 deletions
|
|
@ -34,6 +34,8 @@ class AnthropicCountTokensConfig:
|
|||
return base
|
||||
if base.endswith("/v1/messages"):
|
||||
return f"{base}/count_tokens"
|
||||
if base.endswith("/v1"):
|
||||
return f"{base}/messages/count_tokens"
|
||||
return f"{base}{self._COUNT_TOKENS_PATH}"
|
||||
|
||||
def transform_request_to_count_tokens(
|
||||
|
|
|
|||
|
|
@ -140,3 +140,12 @@ def test_build_count_tokens_url_trailing_slash_stripped():
|
|||
config._build_count_tokens_url("https://my-proxy.example.com/")
|
||||
== "https://my-proxy.example.com/v1/messages/count_tokens"
|
||||
)
|
||||
|
||||
|
||||
def test_build_count_tokens_url_base_with_v1_only():
|
||||
"""/v1-suffixed base gets /messages/count_tokens appended (not doubled /v1)."""
|
||||
config = AnthropicCountTokensConfig()
|
||||
assert (
|
||||
config._build_count_tokens_url("https://my-proxy.example.com/v1")
|
||||
== "https://my-proxy.example.com/v1/messages/count_tokens"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue