oobabooga/textgen · error · InvalidRequestError

Missing required input

Error message

Missing required input

What it means

In the text completions path (completions_common), the request must include either a prompt ('prompt' or legacy 'context') or a 'messages' array (from which a prompt is extracted). When neither is present, InvalidRequestError (400) is raised with param=prompt_str pointing at the missing field name.

Source

Thrown at modules/api/completions.py:823

    if prompt_str not in body or body[prompt_str] is None:
        if 'messages' in body:
            # Convert messages format to prompt for completions endpoint
            prompt_text = ""
            for message in body.get('messages', []):
                if isinstance(message, dict) and 'content' in message:
                    # Extract text content from multimodal messages
                    content = message['content']
                    if isinstance(content, str):
                        prompt_text += content
                    elif isinstance(content, list):
                        for item in content:
                            if isinstance(item, dict) and item.get('type') == 'text':
                                prompt_text += item.get('text', '')

            # Allow empty prompts for image-only requests
            body[prompt_str] = prompt_text
        else:
            raise InvalidRequestError("Missing required input", param=prompt_str)

    # common params
    generate_params = process_parameters(body, is_legacy=is_legacy)
    max_tokens = generate_params['max_new_tokens']
    if max_tokens is None:
        generate_params['max_new_tokens'] = 512
        generate_params['auto_max_new_tokens'] = True
        max_tokens = 512
    elif max_tokens < 0:
        raise InvalidRequestError(message="max_tokens must be greater than or equal to 0.", param="max_tokens")
    elif max_tokens == 0 and body.get('logprobs') is None:
        raise InvalidRequestError(message="max_tokens is 0 but no logprobs parameter was specified.", param="max_tokens")

    generate_params['stream'] = stream
    if stop_event is not None:
        generate_params['stop_event'] = stop_event
    requested_model = generate_params.pop('model')
    logprob_proc = generate_params.pop('logprob_proc', None)

View on GitHub (pinned to ed888c71f2)

Solutions

  1. Include a prompt: {"model": ..., "prompt": "Once upon a time"}.
  2. Or include a messages array; its text content is concatenated into the prompt (empty allowed for image-only requests).
  3. For chat use-cases, call /v1/chat/completions instead.
  4. Verify the client is not dropping falsy fields (empty-string prompt counts as present).

Example fix

# before
curl $URL/v1/completions -d '{"model": "x", "temperature": 0.7}'

# after
curl $URL/v1/completions -d '{"model": "x", "temperature": 0.7, "prompt": "Once upon a time"}'
Defensive patterns

Strategy: validation

Validate before calling

def has_prompt_input(body: dict) -> bool:
    return any(k in body and body[k] is not None for k in ('prompt', 'context', 'messages'))

Type guard

def is_completion_ready(body: dict) -> bool:
    return isinstance(body.get('prompt'), (str, list)) or isinstance(body.get('messages'), list)

Try / catch

try:
    resp = client.completions.create(model=m, prompt=p)
except openai.BadRequestError as e:
    if 'Missing required input' in str(e):
        raise ValueError('completion body has neither prompt nor messages')
    raise

Prevention

When it happens

Trigger: POST /v1/completions with a body lacking both 'prompt' and 'messages' (e.g. only model + sampling params), or the legacy endpoint without 'context'/'prompt'. Sending a messages array with only image items yields an empty-string prompt, which is allowed; total absence is not.

Common situations: Sending chat-style bodies without messages to /v1/completions; a client that conditionally includes prompt only when non-empty and passing prompt=None; wrong endpoint chosen for the payload shape.

Related errors


AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15). Data as JSON: /api/errors/49ff338f6b7f2abf. Report an issue: GitHub.