vllm.entrypoints.chat_utils
¶
Classes:
-
AsyncMultiModalContentParser– -
AudioURL– -
BaseMultiModalItemTracker–Tracks multi-modal items in a given request and ensures that the number
-
ChatCompletionContentPartAudioEmbedsParam– -
ChatCompletionContentPartAudioParam– -
ChatCompletionContentPartImageEmbedsParam– -
ChatCompletionContentPartPromptEmbedsParam– -
ChatCompletionContentPartVideoEmbedsParam– -
ChatCompletionContentPartVideoParam– -
ChatTemplateResolutionError–Raised when chat template resolution fails.
-
ConversationMessage– -
CustomChatCompletionContentPILImageParam–A simpler version of the param that only accepts a PIL image.
-
CustomChatCompletionContentSimpleAudioParam–A simpler version of the param that only accepts a plain audio_url.
-
CustomChatCompletionContentSimpleImageParam–A simpler version of the param that only accepts a plain image_url.
-
CustomChatCompletionContentSimpleVideoParam–A simpler version of the param that only accepts a plain audio_url.
-
CustomChatCompletionContentToolReferenceParam–A tool reference content param that only accepts a plain tool name.
-
CustomChatCompletionMessageParam–Enables custom roles in the Chat Completion API.
-
CustomThinkCompletionContentParam–A Think Completion Content Param that accepts a plain text and a boolean.
-
MultiModalContentParser– -
PILImage–A PIL.Image.Image object.
-
VideoURL–
Functions:
-
get_tool_call_id_type–Return the tool-call ID type for a given model configuration.
-
has_non_text_content–Whether any message in
messageshas a non-text content part. -
validate_chat_template–Raises if the provided chat template appears invalid.
Attributes:
-
PROMPT_EMBEDS_PLACEHOLDER_TOKEN(Final[str]) –The special token used as a placeholder for each embedding
PROMPT_EMBEDS_PLACEHOLDER_TOKEN = '<prompt_embeds>'
module-attribute
¶
The special token used as a placeholder for each embedding position during chat template rendering.
Registered as an additional special token when --enable-prompt-embeds is set.
See _ensure_prompt_embeds_placeholder_token in vllm/renderers/hf.py.
AsyncMultiModalContentParser
¶
Bases: BaseMultiModalContentParser
Methods:
-
parse_prompt_embeds–Schedule async prompt embeds decode and store the coroutine in the tracker.
Source code in vllm/entrypoints/chat_utils.py
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 1490 1491 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 | |
parse_prompt_embeds(data)
¶
Schedule async prompt embeds decode and store the coroutine in the tracker.
Like the sync variant, emits a single sentinel PROMPT_EMBEDS_PLACEHOLDER_TOKEN
per content part. Unlike the sync variant, the tensor decode is deferred to a
thread-pool executor via safe_load_prompt_embeds_async.
Source code in vllm/entrypoints/chat_utils.py
AudioURL
¶
Bases: TypedDict
Attributes:
Source code in vllm/entrypoints/chat_utils.py
url
instance-attribute
¶
Either a URL of the audio or a data URL with base64 encoded audio data.
BaseMultiModalItemTracker
¶
Tracks multi-modal items in a given request and ensures that the number of multi-modal items in a given request does not exceed the configured maximum per prompt.
Methods:
-
add–Add a multi-modal item to the current prompt and returns the
-
get_media_io–The decoder the model's processor wants for
modality.
Attributes:
-
use_unified_vision_chunk_modality(bool) –Check if model uses unified vision_chunk modality for images/videos.
Source code in vllm/entrypoints/chat_utils.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
use_unified_vision_chunk_modality
cached
property
¶
Check if model uses unified vision_chunk modality for images/videos.
_validate_add(modality)
¶
Validate that one more item of the modality can be tracked.
Source code in vllm/entrypoints/chat_utils.py
add(modality, item)
¶
Add a multi-modal item to the current prompt and returns the placeholder string to use, if any.
An optional uuid can be added which serves as a unique identifier of the media.
Note
prompt_embeds bypass MM-processor validation because they are
pre-computed embeddings that do not go through any HF processor, encoder,
or model-specific placeholder logic. The corresponding placeholder string is
managed by the parser via _add_placeholder, so we return None here.
Source code in vllm/entrypoints/chat_utils.py
get_media_io(modality)
¶
The decoder the model's processor wants for modality.
The connector only transports bytes; which decoder they are paired with -- and therefore the decode spec folded into the item's cache key -- is the model's decision, made by its processing info.
Source code in vllm/entrypoints/chat_utils.py
ChatCompletionContentPartAudioEmbedsParam
¶
Bases: TypedDict
Attributes:
-
audio_embeds(MultiModalEmbedsPayload | None) –The audio embeddings. It can be either:
-
type(Required[Literal['audio_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
Source code in vllm/entrypoints/chat_utils.py
audio_embeds
instance-attribute
¶
The audio embeddings. It can be either: - A single base64 string representing a serialized torch tensor. - A dictionary of base64 tensors or numeric JSON metadata arrays.
type
instance-attribute
¶
The type of the content part.
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
ChatCompletionContentPartAudioParam
¶
Bases: TypedDict
Attributes:
Source code in vllm/entrypoints/chat_utils.py
type
instance-attribute
¶
The type of the content part.
ChatCompletionContentPartImageEmbedsParam
¶
Bases: TypedDict
Attributes:
-
image_embeds(MultiModalEmbedsPayload | None) –The image embeddings. It can be either:
-
type(Required[Literal['image_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
Source code in vllm/entrypoints/chat_utils.py
image_embeds
instance-attribute
¶
The image embeddings. It can be either: - A single base64 string. - A dictionary of base64 tensors or numeric JSON metadata arrays.
type
instance-attribute
¶
The type of the content part.
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
ChatCompletionContentPartPromptEmbedsParam
¶
Bases: TypedDict
Attributes:
-
data(Required[str]) –Base64-encoded bytes of a serialized
torch.Tensorof shape -
type(Required[Literal['prompt_embeds']]) –The type of the content part.
Source code in vllm/entrypoints/chat_utils.py
ChatCompletionContentPartVideoEmbedsParam
¶
Bases: TypedDict
Attributes:
-
type(Required[Literal['video_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
-
video_embeds(MultiModalEmbedsPayload | None) –The video embeddings. It can be either:
Source code in vllm/entrypoints/chat_utils.py
type
instance-attribute
¶
The type of the content part.
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
video_embeds
instance-attribute
¶
The video embeddings. It can be either: - A single base64 string representing a serialized torch tensor. - A dictionary of base64 tensors or numeric JSON metadata arrays.
ChatCompletionContentPartVideoParam
¶
Bases: TypedDict
Attributes:
Source code in vllm/entrypoints/chat_utils.py
type
instance-attribute
¶
The type of the content part.
ChatTemplateResolutionError
¶
Bases: ValueError
Raised when chat template resolution fails.
This is a subclass of ValueError for backward compatibility with existing exception handlers.
ConversationMessage
¶
Bases: TypedDict
Attributes:
-
content(str | None | list[dict[str, str]]) –The contents of the message
-
name(str | None) –The name of the function to call
-
reasoning(str | None) –The reasoning content for interleaved thinking.
-
reasoning_content(str | None) –Deprecated: The reasoning content for interleaved thinking.
-
role(Required[str]) –The role of the message's author.
-
task(str | None) –Model-specific task marker. Currently passed through for DeepSeek V4.
-
tool_call_id(str | None) –Tool call that this message is responding to.
-
tool_calls(list[ChatCompletionMessageToolCallParam] | None) –The tool calls generated by the model, such as function calls.
-
tools(list[ChatCompletionFunctionToolParam] | None) –The tools for developer role.
Source code in vllm/entrypoints/chat_utils.py
content
instance-attribute
¶
The contents of the message
name
instance-attribute
¶
The name of the function to call
reasoning
instance-attribute
¶
The reasoning content for interleaved thinking.
reasoning_content
instance-attribute
¶
Deprecated: The reasoning content for interleaved thinking.
role
instance-attribute
¶
The role of the message's author.
task
instance-attribute
¶
Model-specific task marker. Currently passed through for DeepSeek V4.
tool_call_id
instance-attribute
¶
Tool call that this message is responding to.
tool_calls
instance-attribute
¶
The tool calls generated by the model, such as function calls.
tools
instance-attribute
¶
The tools for developer role.
CustomChatCompletionContentPILImageParam
¶
Bases: TypedDict
A simpler version of the param that only accepts a PIL image.
Example: { "image_pil": ImageAsset('cherry_blossom').pil_image }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentSimpleAudioParam
¶
Bases: TypedDict
A simpler version of the param that only accepts a plain audio_url.
Example: { "audio_url": "https://example.com/audio.mp3" }
Source code in vllm/entrypoints/chat_utils.py
CustomChatCompletionContentSimpleImageParam
¶
Bases: TypedDict
A simpler version of the param that only accepts a plain image_url. This is supported by OpenAI API, although it is not documented.
Example: { "image_url": "https://example.com/image.jpg" }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentSimpleVideoParam
¶
Bases: TypedDict
A simpler version of the param that only accepts a plain audio_url.
Example: { "video_url": "https://example.com/video.mp4" }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid
instance-attribute
¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentToolReferenceParam
¶
Bases: TypedDict
A tool reference content param that only accepts a plain tool name.
Example: { "name": "get_weather", "type": "tool_reference" }
Attributes:
-
name(str) –The name of the tool being referenced.
-
type(Literal['tool_reference']) –The content type.
Source code in vllm/entrypoints/chat_utils.py
CustomChatCompletionMessageParam
¶
Bases: TypedDict
Enables custom roles in the Chat Completion API.
Attributes:
-
content(str | list[ChatCompletionContentPartParam]) –The contents of the message.
-
name(str) –An optional name for the participant.
-
reasoning(str | None) –The reasoning content for interleaved thinking.
-
role(Required[str]) –The role of the message's author.
-
task(str | None) –Model-specific task marker. Currently passed through for DeepSeek V4.
-
tool_call_id(str | None) –Tool call that this message is responding to.
-
tool_calls(list[ChatCompletionMessageToolCallParam] | None) –The tool calls generated by the model, such as function calls.
-
tools(list[ChatCompletionFunctionToolParam] | None) –The tools for developer role.
Source code in vllm/entrypoints/chat_utils.py
content
instance-attribute
¶
The contents of the message.
name
instance-attribute
¶
An optional name for the participant.
Provides the model information to differentiate between participants of the same role.
reasoning
instance-attribute
¶
The reasoning content for interleaved thinking.
role
instance-attribute
¶
The role of the message's author.
task
instance-attribute
¶
Model-specific task marker. Currently passed through for DeepSeek V4.
tool_call_id
instance-attribute
¶
Tool call that this message is responding to.
tool_calls
instance-attribute
¶
The tool calls generated by the model, such as function calls.
tools
instance-attribute
¶
The tools for developer role.
CustomThinkCompletionContentParam
¶
Bases: TypedDict
A Think Completion Content Param that accepts a plain text and a boolean.
Example: { "thinking": "I am thinking about the answer", "closed": True, "type": "thinking" }
Attributes:
-
closed(bool) –Whether the thinking is closed.
-
thinking(Required[str]) –The thinking content.
-
type(Required[Literal['thinking']]) –The thinking type.
Source code in vllm/entrypoints/chat_utils.py
MultiModalContentParser
¶
Bases: BaseMultiModalContentParser
Methods:
-
parse_prompt_embeds–Decode a base64 prompt embeds tensor and store it in the tracker.
Source code in vllm/entrypoints/chat_utils.py
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | |
parse_prompt_embeds(data)
¶
Decode a base64 prompt embeds tensor and store it in the tracker.
Emits a single PROMPT_EMBEDS_PLACEHOLDER_TOKEN sentinel per
content part. The renderer later expands each sentinel to a span of
tensor.shape[0] placeholder tokens after tokenization.
Source code in vllm/entrypoints/chat_utils.py
PILImage
¶
VideoURL
¶
Bases: TypedDict
Attributes:
Source code in vllm/entrypoints/chat_utils.py
url
instance-attribute
¶
Either a URL of the video or a data URL with base64 encoded video data.
_SharedFetch
¶
Bases: Generic[_T]
One fetch awaited by several tracker entries.
use_audio_in_video registers a video item and an audio item for the same
URL, and both have to resolve from a single download. The task is created
on first await, so a request that fails before its items are resolved does
not leave an unawaited task behind.
Source code in vllm/entrypoints/chat_utils.py
_decode_media_ref(data, modality, index)
¶
Return the materialized media, wrapping decode failures.
Decode failures are wrapped as VLLMUnprocessableEntityError so corrupt media surfaces as a client error (422) instead of a server error.
Unlike the processor's _decode_error, this can name a request field:
only image and video are remapped to vision_chunk, and only a
URL-fetched item is a MediaRef, so {modality}_url is where it came
from.
Source code in vllm/entrypoints/chat_utils.py
_get_full_multimodal_text_prompt(placeholder_storage, texts, interleave_strings, multimodal_content_part_separator='\n')
¶
Combine multimodal prompts for a multimodal language model.
Source code in vllm/entrypoints/chat_utils.py
_indexed_vision_chunks(vision_chunk_items, vision_chunks_modality_order)
¶
Pair each vision_chunk item with its index within its own modality.
Numbering per modality rather than per chunk matches the index the mm processor reports for the same item, so a decode failure names the same position whichever layer caught it.
Source code in vllm/entrypoints/chat_utils.py
_parse_chat_message_content_mm_part(part)
¶
Parses a given multi-modal content part based on its type.
Parameters:
-
(part¶ChatCompletionContentPartParam) –A dict containing the content part, with a potential 'type' field.
Returns:
-
str–A tuple (part_type, content) where:
-
_ContentPart–- part_type: Type of the part (e.g., 'text', 'image_url').
-
tuple[str, _ContentPart]–- content: Parsed content (e.g., text, image URL).
Raises:
-
ValueError–If the 'type' field is missing and no direct URL is found.
Source code in vllm/entrypoints/chat_utils.py
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 | |
_parse_chat_message_content_part(part, mm_parser, *, wrap_dicts, interleave_strings)
¶
Parses a single part of a conversation. If wrap_dicts is True, structured dictionary pieces for texts and images will be wrapped in dictionaries, i.e., {"type": "text", "text", ...} and {"type": "image"}, respectively. Otherwise multimodal data will be handled by mm_parser, and texts will be returned as strings to be joined with multimodal placeholders.
Source code in vllm/entrypoints/chat_utils.py
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 | |
_predecode_vision_chunk_items(vision_chunk_items, vision_chunks_modality_order)
async
¶
Decode vision_chunk media refs concurrently on the media thread pool.
Waits for every submitted decode to finish, then wraps the first failure
with _vision_chunk_decode_error.
Source code in vllm/entrypoints/chat_utils.py
_reject_reserved_placeholder_in_text(text, model_config)
¶
Reject user-supplied text parts that contains the reserved prompt_embeds
placeholder sentinel.
When the server accepts prompt_embeds, the placeholder token is
registered as a single unsplittable special token on the tokenizer. Any
user text that happens to contain the literal sequence would tokenize to
the same ID and be mistaken for a splice point by the renderer, letting a
caller move or inject splice positions via plain text content.
Source code in vllm/entrypoints/chat_utils.py
_resolve_items(items_by_modality, mm_processor, modality_order)
¶
Materialize the tracker's per-modality items into mm_data / mm_uuids.
Note
mm_processor is None for text-only models (no registered HF
processor) whose only modality is prompt_embeds. Every other
modality requires a processor, enforced by the guard below.
Source code in vllm/entrypoints/chat_utils.py
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | |
get_tool_call_id_type(model_config)
¶
Return the tool-call ID type for a given model configuration.
Source code in vllm/entrypoints/chat_utils.py
has_non_text_content(messages)
¶
Whether any message in messages has a non-text content part.
Only list content is inspected, so validated chat content that is a one-shot iterator is never consumed.
Source code in vllm/entrypoints/chat_utils.py
validate_chat_template(chat_template)
¶
Raises if the provided chat template appears invalid.