Skip to content

[Frontend][Anthropic] Support cache_salt in the Anthropic Messages API - #46744

Draft
abinggo wants to merge 1 commit into
vllm-project:mainfrom
abinggo:feat/anthropic-cache-salt
Draft

abinggo wants to merge 1 commit into
vllm-project:mainfrom
abinggo:feat/anthropic-cache-salt

Conversation

@abinggo

@abinggo abinggo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #46688.

cache_salt (explicit prefix-cache isolation) is available on the
OpenAI-compatible Completions / Chat Completions routes but not on the Anthropic
Messages API. Anthropic-schema clients currently have to switch to the OpenAI
format just to get deterministic cache isolation in multi-tenant setups.

Change

  • Add cache_salt: str | None to AnthropicMessagesRequest, alongside the
    existing vLLM-specific kv_transfer_params / chat_template_kwargs fields.
  • Pass it through _build_base_request into the ChatCompletionRequest, which
    already plumbs cache_salt into the prefix-cache hash — so behavior matches
    the OpenAI route exactly (no engine-side changes needed).
  • A field validator rejects an empty cache_salt at request-validation time
    (HTTP 422) instead of letting it fall through to a 500 from the Messages
    router, mirroring the OpenAI route's non-empty requirement.
  • count_tokens is intentionally left untouched (it only renders/counts).

Tests

tests/entrypoints/anthropic/test_anthropic_messages_conversion.py
(TestCacheSaltPassthrough): field accepted / defaults to None; passthrough
into the built ChatCompletionRequest; None stays None; empty string is
rejected with a ValidationError. All pass locally.

cache_salt (explicit prefix-cache isolation) was available on the
OpenAI-compatible Completions / Chat Completions routes but not on the
Anthropic Messages API, forcing Anthropic-schema clients to switch formats to
get deterministic cache isolation in multi-tenant setups.

Add cache_salt to AnthropicMessagesRequest (alongside the existing
vLLM-specific kv_transfer_params / chat_template_kwargs fields) and pass it
through _build_base_request into the ChatCompletionRequest, which already plumbs
cache_salt into the prefix-cache hash. A field validator rejects an empty
cache_salt at request-validation time (HTTP 422) instead of letting it surface
as a 500 from the Messages router, mirroring the OpenAI route's non-empty rule.

Fixes vllm-project#46688

Signed-off-by: abinggo <107740309+abinggo@users.noreply.github.com>
@mergify mergify Bot added the frontend label Jun 25, 2026
@flexwang

Copy link
Copy Markdown

Thank you!

@mergify

mergify Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @abinggo.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add cache_salt support for Anthropic Messages API

2 participants