Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/vllm_router/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from vllm_router.experimental import get_feature_gates, initialize_feature_gates
from vllm_router.parsers.parser import parse_args
from vllm_router.routers.anthropic_router import anthropic_router
from vllm_router.routers.batches_router import batches_router
from vllm_router.routers.files_router import files_router
from vllm_router.routers.main_router import main_router
Expand Down Expand Up @@ -321,6 +322,7 @@ def initialize_all(app: FastAPI, args):

app = FastAPI(lifespan=lifespan)
app.include_router(main_router)
app.include_router(anthropic_router)
app.include_router(files_router)
app.include_router(batches_router)
app.include_router(metrics_router)
Expand Down
26 changes: 26 additions & 0 deletions src/vllm_router/routers/anthropic_router.py
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding a separate module just in case, so we can add future Anthropic-compatible endpoints here if needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a risk that adding this endpoint to the main router module?

Copy link
Author

@nejch nejch Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zerofishnoodles it just made sense to me to split this up logically since it's not part of the OpenAI OpenAPI spec. And we can later add more anthropic endpoints here.

But if you prefer I can put it into the main one, I just thought different providers might make sense in separate routers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Can you put it into the main one for now? Since this router module is not the same level of abstract as the other existing one. If there is more anthropic ep that may have contention with the existing one, we can do refactoring at that time.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024-2025 The vLLM Production Stack Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from fastapi import APIRouter, BackgroundTasks, Request

from vllm_router.log import init_logger
from vllm_router.services.request_service.request import route_general_request

logger = init_logger(__name__)
anthropic_router = APIRouter()


@anthropic_router.post("/v1/messages")
async def route_anthropic_messages(request: Request, background_tasks: BackgroundTasks):
"""Route Anthropic-compatible messages requests to the backend."""
return await route_general_request(request, "/v1/messages", background_tasks)
14 changes: 14 additions & 0 deletions src/vllm_router/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ModelType(enum.Enum):
score = "score"
transcription = "transcription"
vision = "vision"
messages = "messages"

@staticmethod
def get_url(model_type: str):
Expand All @@ -89,6 +90,8 @@ def get_url(model_type: str):
return "/v1/score"
case ModelType.transcription:
return "/v1/audio/transcriptions"
case ModelType.messages:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly cosmetics at the moment, since compatible models presumably have chat defined as their type, but maybe in the future it'd make sense to support multiple types and run health checks against supported endpoints.

return "/v1/messages"

@staticmethod
def get_test_payload(model_type: str):
Expand All @@ -112,6 +115,17 @@ def get_test_payload(model_type: str):
return {"query": "Hello", "documents": ["Test"]}
case ModelType.score:
return {"encoding_format": "float", "text_1": "Test", "test_2": "Test2"}
case ModelType.messages:
return {
"messages": [
{
"role": "user",
"content": "Hello",
}
],
"temperature": 0.0,
"max_tokens": 3,
}
Comment on lines +118 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test payload for messages is identical to the one for chat. To avoid code duplication and improve maintainability, you can simplify this by reusing the payload logic from the chat model type.

            case ModelType.messages:
                return ModelType.get_test_payload("chat")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this makes sense as we're actually inside get_test_payload here, so it wouldn't be that intuitive for humans. I can factor out the payload itself if needed to avoid duplication.

case ModelType.transcription:
if _SILENT_WAV_BYTES is not None:
logger.debug("=====Silent WAV Bytes is being used=====")
Expand Down