Skip to content

Commit 0975469

Browse files
committed
feat(router): add initial support for anthropic messages endpoint
Signed-off-by: Nejc Habjan <nejc.habjan@siemens.com>
1 parent ab2c023 commit 0975469

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/vllm_router/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from vllm_router.experimental import get_feature_gates, initialize_feature_gates
3030
from vllm_router.parsers.parser import parse_args
31+
from vllm_router.routers.anthropic_router import anthropic_router
3132
from vllm_router.routers.batches_router import batches_router
3233
from vllm_router.routers.files_router import files_router
3334
from vllm_router.routers.main_router import main_router
@@ -287,6 +288,7 @@ def initialize_all(app: FastAPI, args):
287288

288289
app = FastAPI(lifespan=lifespan)
289290
app.include_router(main_router)
291+
app.include_router(anthropic_router)
290292
app.include_router(files_router)
291293
app.include_router(batches_router)
292294
app.include_router(metrics_router)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024-2025 The vLLM Production Stack Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from fastapi import APIRouter, BackgroundTasks, Request
15+
16+
from vllm_router.log import init_logger
17+
from vllm_router.services.request_service.request import route_general_request
18+
19+
logger = init_logger(__name__)
20+
anthropic_router = APIRouter()
21+
22+
23+
@anthropic_router.post("/v1/messages")
24+
async def route_anthropic_messages(request: Request, background_tasks: BackgroundTasks):
25+
"""Route Anthropic-compatible messages requests to the backend."""
26+
return await route_general_request(request, "/v1/messages", background_tasks)

src/vllm_router/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ModelType(enum.Enum):
7373
score = "score"
7474
transcription = "transcription"
7575
vision = "vision"
76+
messages = "messages"
7677

7778
@staticmethod
7879
def get_url(model_type: str):
@@ -89,6 +90,8 @@ def get_url(model_type: str):
8990
return "/v1/score"
9091
case ModelType.transcription:
9192
return "/v1/audio/transcriptions"
93+
case ModelType.messages:
94+
return "/v1/messages"
9295

9396
@staticmethod
9497
def get_test_payload(model_type: str):
@@ -112,6 +115,17 @@ def get_test_payload(model_type: str):
112115
return {"query": "Hello", "documents": ["Test"]}
113116
case ModelType.score:
114117
return {"encoding_format": "float", "text_1": "Test", "test_2": "Test2"}
118+
case ModelType.messages:
119+
return {
120+
"messages": [
121+
{
122+
"role": "user",
123+
"content": "Hello",
124+
}
125+
],
126+
"temperature": 0.0,
127+
"max_tokens": 3,
128+
}
115129
case ModelType.transcription:
116130
if _SILENT_WAV_BYTES is not None:
117131
logger.debug("=====Silent WAV Bytes is being used=====")

0 commit comments

Comments
 (0)