vllm.entrypoints.openai.api_server ¶
ENDPOINT_LOAD_METRICS_FORMAT_HEADER_LABEL module-attribute ¶
parser module-attribute ¶
parser = FlexibleArgumentParser(
description="vLLM OpenAI-Compatible RESTful API server."
)
AuthenticationMiddleware ¶
Pure ASGI middleware that authenticates each request by checking if the Authorization Bearer token exists and equals anyof "{api_key}".
Notes¶
There are two cases in which authentication is skipped: 1. The HTTP method is OPTIONS. 2. The request path doesn't start with /v1 (e.g. /health).
Source code in vllm/entrypoints/openai/api_server.py
__call__ ¶
__call__(
scope: Scope, receive: Receive, send: Send
) -> Awaitable[None]
Source code in vllm/entrypoints/openai/api_server.py
__init__ ¶
verify_token ¶
verify_token(headers: Headers) -> bool
Source code in vllm/entrypoints/openai/api_server.py
PrometheusResponse ¶
SSEDecoder ¶
Robust Server-Sent Events decoder for streaming responses.
Source code in vllm/entrypoints/openai/api_server.py
__init__ ¶
decode_chunk ¶
Decode a chunk of SSE data and return parsed events.
Source code in vllm/entrypoints/openai/api_server.py
extract_content ¶
ScalingMiddleware ¶
Middleware that checks if the model is currently scaling and returns a 503 Service Unavailable response if it is.
This middleware applies to all HTTP requests and prevents processing when the model is in a scaling state.
Source code in vllm/entrypoints/openai/api_server.py
__call__ ¶
__call__(
scope: Scope, receive: Receive, send: Send
) -> Awaitable[None]
Source code in vllm/entrypoints/openai/api_server.py
XRequestIdMiddleware ¶
Middleware the set's the X-Request-Id header for each response to a random uuid4 (hex) value if the header isn't already present in the request, otherwise use the provided request id.
Source code in vllm/entrypoints/openai/api_server.py
__call__ ¶
__call__(
scope: Scope, receive: Receive, send: Send
) -> Awaitable[None]
Source code in vllm/entrypoints/openai/api_server.py
_convert_stream_to_sse_events async ¶
_convert_stream_to_sse_events(
generator: AsyncGenerator[
StreamingResponsesResponse, None
],
) -> AsyncGenerator[str, None]
Convert the generator to a stream of events in SSE format
Source code in vllm/entrypoints/openai/api_server.py
_extract_content_from_chunk ¶
Extract content from a streaming response chunk.
Source code in vllm/entrypoints/openai/api_server.py
_log_non_streaming_response ¶
_log_non_streaming_response(response_body: list) -> None
Log non-streaming response.
Source code in vllm/entrypoints/openai/api_server.py
_log_streaming_response ¶
_log_streaming_response(
response, response_body: list
) -> None
Log streaming response with robust SSE parsing.
Source code in vllm/entrypoints/openai/api_server.py
base ¶
base(request: Request) -> OpenAIServing
build_app ¶
build_app(args: Namespace) -> FastAPI
Source code in vllm/entrypoints/openai/api_server.py
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 | |
build_async_engine_client async ¶
build_async_engine_client(
args: Namespace,
*,
usage_context: UsageContext = OPENAI_API_SERVER,
disable_frontend_multiprocessing: bool | None = None,
client_config: dict[str, Any] | None = None,
) -> AsyncIterator[EngineClient]
Source code in vllm/entrypoints/openai/api_server.py
build_async_engine_client_from_engine_args async ¶
build_async_engine_client_from_engine_args(
engine_args: AsyncEngineArgs,
*,
usage_context: UsageContext = OPENAI_API_SERVER,
disable_frontend_multiprocessing: bool = False,
client_config: dict[str, Any] | None = None,
) -> AsyncIterator[EngineClient]
Create EngineClient, either: - in-process using the AsyncLLMEngine Directly - multiprocess using AsyncLLMEngine RPC
Returns the Client or None if the creation failed.
Source code in vllm/entrypoints/openai/api_server.py
cancel_responses async ¶
cancel_responses(response_id: str, raw_request: Request)
Source code in vllm/entrypoints/openai/api_server.py
chat ¶
chat(request: Request) -> OpenAIServingChat | None
collective_rpc async ¶
Source code in vllm/entrypoints/openai/api_server.py
completion ¶
completion(
request: Request,
) -> OpenAIServingCompletion | None
create_chat_completion async ¶
create_chat_completion(
request: ChatCompletionRequest, raw_request: Request
)
Source code in vllm/entrypoints/openai/api_server.py
create_completion async ¶
create_completion(
request: CompletionRequest, raw_request: Request
)
Source code in vllm/entrypoints/openai/api_server.py
create_messages async ¶
create_messages(
request: AnthropicMessagesRequest, raw_request: Request
)
Source code in vllm/entrypoints/openai/api_server.py
create_responses async ¶
create_responses(
request: ResponsesRequest, raw_request: Request
)
Source code in vllm/entrypoints/openai/api_server.py
create_server_socket ¶
Source code in vllm/entrypoints/openai/api_server.py
create_server_unix_socket ¶
create_transcriptions async ¶
create_transcriptions(
raw_request: Request,
request: Annotated[TranscriptionRequest, Form()],
)
Source code in vllm/entrypoints/openai/api_server.py
create_translations async ¶
create_translations(
request: Annotated[TranslationRequest, Form()],
raw_request: Request,
)
Source code in vllm/entrypoints/openai/api_server.py
detokenize async ¶
detokenize(
request: DetokenizeRequest, raw_request: Request
)
Source code in vllm/entrypoints/openai/api_server.py
engine_client ¶
engine_client(request: Request) -> EngineClient
generate async ¶
generate(request: GenerateRequest, raw_request: Request)
Source code in vllm/entrypoints/openai/api_server.py
generate_tokens ¶
generate_tokens(request: Request) -> ServingTokens | None
get_server_load_metrics async ¶
Source code in vllm/entrypoints/openai/api_server.py
health async ¶
Health check.
Source code in vllm/entrypoints/openai/api_server.py
init_app_state async ¶
init_app_state(
engine_client: EngineClient,
state: State,
args: Namespace,
) -> None
Source code in vllm/entrypoints/openai/api_server.py
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 | |
is_paused async ¶
Return the current pause status.
Source code in vllm/entrypoints/openai/api_server.py
is_scaling_elastic_ep async ¶
is_sleeping async ¶
Source code in vllm/entrypoints/openai/api_server.py
lifespan async ¶
Source code in vllm/entrypoints/openai/api_server.py
load_log_config ¶
Source code in vllm/entrypoints/openai/api_server.py
maybe_register_tokenizer_info_endpoint ¶
Conditionally register the tokenizer info endpoint if enabled.
Source code in vllm/entrypoints/openai/api_server.py
messages ¶
messages(request: Request) -> AnthropicServingMessages
models ¶
models(request: Request) -> OpenAIServingModels
mount_metrics ¶
Mount prometheus metrics to a FastAPI app.
Source code in vllm/entrypoints/openai/api_server.py
pause_generation async ¶
pause_generation(
raw_request: Request,
wait_for_inflight_requests: bool = Query(False),
clear_cache: bool = Query(True),
) -> JSONResponse
Pause generation requests to allow weight updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_for_inflight_requests | bool | When | Query(False) |
clear_cache | bool | Whether to clear KV/prefix caches after draining. | Query(True) |
Source code in vllm/entrypoints/openai/api_server.py
reset_mm_cache async ¶
Reset the multi-modal cache. Note that we currently do not check if the multi-modal cache is successfully reset in the API server.
Source code in vllm/entrypoints/openai/api_server.py
reset_prefix_cache async ¶
Reset the prefix cache. Note that we currently do not check if the prefix cache is successfully reset in the API server.
Source code in vllm/entrypoints/openai/api_server.py
responses ¶
responses(
request: Request,
) -> OpenAIServingResponses | None
resume_generation async ¶
Resume generation after a pause.
Source code in vllm/entrypoints/openai/api_server.py
retrieve_responses async ¶
retrieve_responses(
response_id: str,
raw_request: Request,
starting_after: int | None = None,
stream: bool | None = False,
)
Source code in vllm/entrypoints/openai/api_server.py
run_server async ¶
Run a single-worker API server.
Source code in vllm/entrypoints/openai/api_server.py
run_server_worker async ¶
Run a single API server worker.
Source code in vllm/entrypoints/openai/api_server.py
scale_elastic_ep async ¶
Source code in vllm/entrypoints/openai/api_server.py
setup_server ¶
Validate API server args, set up signal handler, create socket ready to serve.
Source code in vllm/entrypoints/openai/api_server.py
show_available_models async ¶
show_server_info async ¶
show_server_info(
raw_request: Request,
config_format: Annotated[
Literal["text", "json"], Query()
] = "text",
)
Source code in vllm/entrypoints/openai/api_server.py
show_version async ¶
sleep async ¶
Source code in vllm/entrypoints/openai/api_server.py
start_profile async ¶
Source code in vllm/entrypoints/openai/api_server.py
stop_profile async ¶
Source code in vllm/entrypoints/openai/api_server.py
tokenization ¶
tokenization(request: Request) -> OpenAIServingTokenization
tokenize async ¶
tokenize(request: TokenizeRequest, raw_request: Request)
Source code in vllm/entrypoints/openai/api_server.py
transcription ¶
transcription(
request: Request,
) -> OpenAIServingTranscription
translation ¶
translation(request: Request) -> OpenAIServingTranslation