Skip to content

Invalid value for 'tool_choice' #479

@Muleskinner

Description

@Muleskinner

Bug Report

Overview

After upgrading from version 8.5.4 to 8.8.1, I now encounter an error when calling GetCompletionAsync without using tools.

DeserializeAsync Failed! HTTP status code: BadRequest | Response body: { "error": { "message": "Invalid value for 'tool_choice': 'tool_choice' is only allowed when 'tools' are specified.", "type": "invalid_request_error", "param": "tool_choice", "code": null } }

Im creating the ChatRequest like this:
new ChatRequest(messages, null, model: model, temperature: temperature, jsonSchema: jsonScheme); ie: tools = null and im not providing tool_choice.

That is, tools = null and I'm not explicitly providing a tool_choice. I've also tested the following variations — all result in the same error:

new ChatRequest(messages, null, toolChoice: "none", model: model, temperature: temperature, jsonSchema: jsonScheme);

and this

new ChatRequest(messages, null, toolChoice: null, model: model, temperature: temperature, jsonSchema: jsonScheme);

all with same error.

To Reproduce

Steps to reproduce the behavior:
var chatRequest = new ChatRequest(messages, null, model: model, temperature: temperature);
var result = await Client.ChatEndpoint.GetCompletionAsync(chatRequest);

Result:

Error: DeserializeAsync Failed! HTTP status code: BadRequest | Response body: { "error": { "message": "Invalid value for 'tool_choice': 'tool_choice' is only allowed when 'tools' are specified.", "type": "invalid_request_error", "param": "tool_choice", "code": null } }

Expected behavior

When no tools are specified, tool_choice should not be included in the request payload — or at least not default to "none".

Additional context

This worked correctly in v8.5.4, even with:
new ChatRequest(messages, null, toolChoice: "auto", model: model, temperature: temperature, jsonSchema: jsonScheme);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions