sgl-project/sglang · error · ValueError
text and input_ids cannot be provided at the same time
Error message
text and input_ids cannot be provided at the same time
What it means
A request may be seeded by exactly one of raw text or pre-tokenized input_ids, not both — tokenizing text that also carries input_ids is ambiguous. Raised at the start of normalize_batch_and_arguments.
Source
Thrown at python/sglang/srt/managers/io_struct.py:1186
def _validate_rid_uniqueness(self):
"""Validate that request IDs within a batch are unique."""
if isinstance(self.rid, list) and len(set(self.rid)) != len(self.rid):
counts = Counter(self.rid)
duplicates = [rid for rid, count in counts.items() if count > 1]
raise ValueError(
f"Duplicate request IDs detected within the request: {duplicates}"
)
def normalize_batch_and_arguments(self):
# at least one of text, input_ids, or image should be provided
if self.text is None and self.input_ids is None and self.image_data is None:
raise ValueError(
"At least one of text, input_ids, or image should be provided"
)
# text and input_ids cannot be provided at the same time
if self.text is not None and self.input_ids is not None:
raise ValueError("text and input_ids cannot be provided at the same time")
# Derive the batch size
self.batch_size = 0
self.is_single = True
# check the batch size of text
if self.text is not None:
if isinstance(self.text, list):
self.batch_size += len(self.text)
self.is_single = False
else:
self.batch_size += 1
# check the batch size of input_ids
if self.input_ids is not None:
if isinstance(self.input_ids[0], list):
self.batch_size += len(self.input_ids)
self.is_single = FalseView on GitHub (pinned to 0132848349)
Solutions
- Drop one field: keep input_ids if you tokenized yourself, otherwise keep text
- Set text=None explicitly when building from token ids
Example fix
// before GenerateReqInput(text='hi', input_ids=[1,2,3]) // after GenerateReqInput(input_ids=[1,2,3])
Defensive patterns
Strategy: validation
Validate before calling
if input_ids is not None:
text = None
assert (text is None) or (input_ids is None) Prevention
- Pick exactly one seeding path per request in your client abstraction
When it happens
Trigger: GenerateReqInput(text='hi', input_ids=[1,2,3]); chat clients that attach cached token ids while still forwarding the raw prompt string.
Common situations: Caching layers that add input_ids for reuse but forget to drop text; template rendering code that populates both fields 'for safety'.
Related errors
- Unknown req_type: {req_type!r} (expected 'generate' or 'embe
- Exactly one of 'prompt' or 'messages' must be provided.
- At least one of text, input_ids, or image should be provided
- token_ids_logprob must be a flat list of integers.
- Unknown serve backend {name!r}. Available values: {available
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/a5a966fb4ab6dcfd.
Report an issue: GitHub.