oobabooga/textgen · error · InvalidRequestError

function_call is not supported.

Error message

function_call is not supported.

What it means

chat_completions_common rejects the legacy OpenAI 'function_call' parameter (values like 'auto', 'none', or {"name": ...}). Like 'functions', the legacy control field is unsupported; the server supports only the modern 'tool_choice' field and fails fast with an InvalidRequestError (400) so callers get a clear signal.

Source

Thrown at modules/api/completions.py:482

                    current_message = ""
                chat_dialogue.append([content, '', '', {"role": "system"}])

    if not user_input_last:
        user_input = ""

    return user_input, system_message, {
        'internal': chat_dialogue,
        'visible': copy.deepcopy(chat_dialogue),
        'messages': history  # Store original messages for multimodal models
    }


def chat_completions_common(body: dict, is_legacy: bool = False, stream=False, prompt_only=False, stop_event=None) -> dict:
    if body.get('functions', []):
        raise InvalidRequestError(message="functions is not supported.", param='functions')

    if body.get('function_call', ''):
        raise InvalidRequestError(message="function_call is not supported.", param='function_call')

    if 'messages' not in body:
        raise InvalidRequestError(message="messages is required", param='messages')

    tools = None
    if 'tools' in body and body['tools'] is not None and isinstance(body['tools'], list) and body['tools']:
        tools = validateTools(body['tools'])  # raises InvalidRequestError if validation fails

    tool_choice = body.get('tool_choice', None)
    if tool_choice == "none":
        tools = None  # Disable tool detection entirely

    messages = body['messages']
    for m in messages:
        if 'role' not in m:
            raise InvalidRequestError(message="messages: missing role", param='messages')
        elif m['role'] == 'function':
            raise InvalidRequestError(message="role: function is not supported.", param='messages')

View on GitHub (pinned to ed888c71f2)

Solutions

  1. Replace "function_call": "auto" with "tool_choice": "auto".
  2. Replace "function_call": {"name": X} with "tool_choice": {"type": "function", "function": {"name": X}}.
  3. Remove the field entirely when auto behavior is fine.
  4. Migrate the whole call to the tools API (see error 1) since 'functions' is usually present too.

Example fix

# before
body = {"model": "x", "messages": msgs, "function_call": {"name": "get_weather"}}

# after
body = {"model": "x", "messages": msgs, "tool_choice": {"type": "function", "function": {"name": "get_weather"}}, "tools": tools}
Defensive patterns

Strategy: validation

Validate before calling

def to_modern_tool_choice(function_call):
    if function_call in (None, '', 'auto'):
        return 'auto'
    if function_call == 'none':
        return 'none'
    if isinstance(function_call, dict):
        return {'type': 'function', 'function': {'name': function_call['name']}}
    raise ValueError(function_call)

body['tool_choice'] = to_modern_tool_choice(body.pop('function_call', None))

Try / catch

try:
    resp = client.chat.completions.create(**params)
except openai.BadRequestError as e:
    if 'function_call is not supported' in str(e):
        params['tool_choice'] = convert(params.pop('function_call'))
        resp = client.chat.completions.create(**params)
    else:
        raise

Prevention

When it happens

Trigger: POST /v1/chat/completions with any non-empty 'function_call' in the body, e.g. {"function_call": "auto"} or {"function_call": {"name": "get_weather"}}. Truthiness check means the string "none" also triggers it (unlike tool_choice where "none" is honored).

Common situations: Pre-tools OpenAI SDK code; curl examples copied from 2023-era docs; frameworks that emit both 'functions' and 'function_call' together, so fixing only 'functions' still leaves this error.

Related errors


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