oobabooga/textgen · error · InvalidRequestError
messages: missing text in content item
Error message
messages: missing text in content item
What it means
A content item with type 'text' must include a 'text' key holding the string. Its absence raises InvalidRequestError (400, param='messages') during multimodal content validation.
Source
Thrown at modules/api/completions.py:519
# Handle multimodal content validation
content = m.get('content')
if content is None:
# OpenAI allows content: null on assistant messages when tool_calls is present
if m['role'] == 'assistant' and m.get('tool_calls'):
m['content'] = ''
else:
raise InvalidRequestError(message="messages: missing content", param='messages')
# Validate multimodal content structure
if isinstance(content, list):
for item in content:
if not isinstance(item, dict) or 'type' not in item:
raise InvalidRequestError(message="messages: invalid content item format", param='messages')
if item['type'] not in ['text', 'image_url']:
raise InvalidRequestError(message="messages: unsupported content type", param='messages')
if item['type'] == 'text' and 'text' not in item:
raise InvalidRequestError(message="messages: missing text in content item", param='messages')
if item['type'] == 'image_url' and ('image_url' not in item or 'url' not in item['image_url']):
raise InvalidRequestError(message="messages: missing image_url in content item", param='messages')
# Chat Completions
object_type = 'chat.completion' if not stream else 'chat.completion.chunk'
created_time = int(time.time())
cmpl_id = "chatcmpl-%d" % (int(time.time() * 1000000000))
resp_list = 'data' if is_legacy else 'choices'
# generation parameters
generate_params = process_parameters(body, is_legacy=is_legacy)
if stop_event is not None:
generate_params['stop_event'] = stop_event
continue_ = body['continue_']
# Instruction template
if body['instruction_template_str']:
instruction_template_str = body['instruction_template_str']View on GitHub (pinned to ed888c71f2)
Solutions
- Include the text key: {"type": "text", "text": "hello"}.
- If the field may be empty, still send an empty string rather than omitting the key.
- Use a client-side content-item builder that always sets both keys.
Example fix
# before
{"type": "text", "content": "describe this image"}
# after
{"type": "text", "text": "describe this image"} Defensive patterns
Strategy: validation
Validate before calling
def text_item(text: str) -> dict:
return {'type': 'text', 'text': text or ''} Type guard
def is_valid_text_item(i) -> bool:
return isinstance(i, dict) and i.get('type') == 'text' and isinstance(i.get('text'), str) Try / catch
try:
resp = client.chat.completions.create(model=m, messages=msgs)
except openai.BadRequestError as e:
if 'missing text in content item' in str(e):
raise ValueError('content builder omitted text field')
raise Prevention
- Never hand-write {'type': 'text'} inline; use a builder that sets both keys.
- Use 'text', not 'content' or 'value', as the payload key.
- Allow empty strings but never omit the key.
When it happens
Trigger: POST /v1/chat/completions with {"type": "text"} or {"type": "text", "content": "hi"} (wrong key name) inside a content list.
Common situations: Using 'content' or 'value' instead of 'text' as the key; constructing items from templates where the text field is conditionally omitted; partial conversion from another API's block schema.
Related errors
- messages: invalid content item format
- messages: unsupported content type
- messages: missing image_url in content item
- functions is not supported.
- function_call is not supported.
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/c8def54ee54c7333.
Report an issue: GitHub.