[Frontend] Add cache_salt support to Anthropic Messages API (#49498)
Signed-off-by: aeon-x <talexcao@gmail.com>
Cao Qian committed
Aug 1, 2026 at 00:36 UTC
81a42d37b1d76a34ce75b6871bba57a30cddc812
3 files changed
+35
tests/entrypoints/anthropic/test_anthropic_messages_conversion.py
+23
@@ -1385,3 +1385,26 @@ class TestMessagesFullConverter:
1385
assert len(result.content) == 1
1386
assert result.content[0].type == "text"
1387
assert result.content[0].text == ""
1388
+
1389
+
1390
+# ======================================================================
1391
+# cache_salt pass-through (Issue #46688)
1392
+# ======================================================================
1393
+
1394
+
1395
+class TestCacheSalt:
1396
+ def test_cache_salt_passed_through(self):
1397
+ """cache_salt on the Anthropic request reaches the converted
1398
+ ChatCompletionRequest so prefix-cache isolation works via /v1/messages."""
1399
+ request = _make_request(
1400
+ [{"role": "user", "content": "Hello"}],
1401
+ cache_salt="tenant-abc-secret-salt",
1402
+ )
1403
+ result = _convert(request)
1404
+ assert result.cache_salt == "tenant-abc-secret-salt"
1405
+
1406
+ def test_cache_salt_defaults_to_none(self):
1407
+ """Omitting cache_salt leaves it unset (unchanged default behavior)."""
1408
+ request = _make_request([{"role": "user", "content": "Hello"}])
1409
+ result = _convert(request)
1410
+ assert result.cache_salt is None
vllm/entrypoints/anthropic/protocol.py
+11
@@ -133,6 +133,17 @@ class AnthropicMessagesRequest(BaseModel):
133
top_p: float | None = None
134
135
# vLLM-specific fields that are not in Anthropic spec
136
+ cache_salt: str | None = Field(
137
+ default=None,
138
+ description=(
139
+ "If specified, the prefix cache will be salted with the provided "
140
+ "string to prevent an attacker to guess prompts in multi-user "
141
+ "environments. The salt should be random, protected from "
142
+ "access by 3rd parties, and long enough to be "
143
+ "unpredictable (e.g., 43 characters base64-encoded, corresponding "
144
+ "to 256 bit)."
145
+ ),
146
+ )
147
kv_transfer_params: dict[str, Any] | None = Field(
148
default=None,
149
description="KVTransfer parameters used for disaggregated serving.",
vllm/entrypoints/anthropic/serving.py
+1
@@ -486,6 +486,7 @@ class AnthropicServingMessages(OpenAIServingChat):
486
temperature=anthropic_request.temperature,
487
top_p=anthropic_request.top_p,
488
top_k=anthropic_request.top_k,
489
+ cache_salt=anthropic_request.cache_salt,
490
kv_transfer_params=anthropic_request.kv_transfer_params,
491
ec_transfer_params=anthropic_request.ec_transfer_params,
492
chat_template_kwargs=anthropic_request.chat_template_kwargs,