{"record":{"id":"deb2838746bc0d79","repo":"oobabooga/textgen","slug":"function-call-is-not-supported","errorCode":null,"errorMessage":"function_call is not supported.","messagePattern":"function_call is not supported\\.","errorType":"exception","errorClass":"InvalidRequestError","httpStatus":400,"severity":"error","filePath":"modules/api/completions.py","lineNumber":482,"sourceCode":"                    current_message = \"\"\n                chat_dialogue.append([content, '', '', {\"role\": \"system\"}])\n\n    if not user_input_last:\n        user_input = \"\"\n\n    return user_input, system_message, {\n        'internal': chat_dialogue,\n        'visible': copy.deepcopy(chat_dialogue),\n        'messages': history  # Store original messages for multimodal models\n    }\n\n\ndef chat_completions_common(body: dict, is_legacy: bool = False, stream=False, prompt_only=False, stop_event=None) -> dict:\n    if body.get('functions', []):\n        raise InvalidRequestError(message=\"functions is not supported.\", param='functions')\n\n    if body.get('function_call', ''):\n        raise InvalidRequestError(message=\"function_call is not supported.\", param='function_call')\n\n    if 'messages' not in body:\n        raise InvalidRequestError(message=\"messages is required\", param='messages')\n\n    tools = None\n    if 'tools' in body and body['tools'] is not None and isinstance(body['tools'], list) and body['tools']:\n        tools = validateTools(body['tools'])  # raises InvalidRequestError if validation fails\n\n    tool_choice = body.get('tool_choice', None)\n    if tool_choice == \"none\":\n        tools = None  # Disable tool detection entirely\n\n    messages = body['messages']\n    for m in messages:\n        if 'role' not in m:\n            raise InvalidRequestError(message=\"messages: missing role\", param='messages')\n        elif m['role'] == 'function':\n            raise InvalidRequestError(message=\"role: function is not supported.\", param='messages')","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/api/completions.py#L464-L500","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Replace \"function_call\": \"auto\" with \"tool_choice\": \"auto\".","Replace \"function_call\": {\"name\": X} with \"tool_choice\": {\"type\": \"function\", \"function\": {\"name\": X}}.","Remove the field entirely when auto behavior is fine.","Migrate the whole call to the tools API (see error 1) since 'functions' is usually present too."],"exampleFix":"# before\nbody = {\"model\": \"x\", \"messages\": msgs, \"function_call\": {\"name\": \"get_weather\"}}\n\n# after\nbody = {\"model\": \"x\", \"messages\": msgs, \"tool_choice\": {\"type\": \"function\", \"function\": {\"name\": \"get_weather\"}}, \"tools\": tools}","handlingStrategy":"validation","validationCode":"def to_modern_tool_choice(function_call):\n    if function_call in (None, '', 'auto'):\n        return 'auto'\n    if function_call == 'none':\n        return 'none'\n    if isinstance(function_call, dict):\n        return {'type': 'function', 'function': {'name': function_call['name']}}\n    raise ValueError(function_call)\n\nbody['tool_choice'] = to_modern_tool_choice(body.pop('function_call', None))","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.chat.completions.create(**params)\nexcept openai.BadRequestError as e:\n    if 'function_call is not supported' in str(e):\n        params['tool_choice'] = convert(params.pop('function_call'))\n        resp = client.chat.completions.create(**params)\n    else:\n        raise","preventionTips":["Migrate 'function_call' and 'functions' together, not one at a time.","Prefer tool_choice='auto' or omitting the field entirely.","Remember 'function_call: \"none\"' is rejected here, unlike tool_choice='none'."],"tags":["openai-api","chat-completions","function-calling","validation"],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}