Invalid value for 'tool_choice' #480
-
OverviewAfter upgrading from version 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 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 ReproduceSteps to reproduce the behavior: var chatRequest = new ChatRequest(messages, null, model: model, temperature: temperature);
var result = await Client.ChatEndpoint.GetCompletionAsync(chatRequest); Result: 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 behaviorWhen no tools are specified, tool_choice should not be included in the request payload — or at least not default to "none". Additional contextThis worked correctly in v8.5.4, even with: new ChatRequest(messages, null, toolChoice: "auto", model: model, temperature: temperature, jsonSchema: jsonScheme); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Update / Workaround found After digging into this further, I discovered that the issue only occurs when using the The following causes the error: But using the overload that doesn't accept a So until the internal logic is fixed to avoid setting Thanks again — and hope this helps others running into the same error! |
Beta Was this translation helpful? Give feedback.
Update / Workaround found
After digging into this further, I discovered that the issue only occurs when using the
ChatRequest
constructor that includes the tools parameter, even if tools is explicitly set to null.The following causes the error:
// This triggers tool_choice = "none", which causes the API to reject the request
new ChatRequest(messages, tools: null, model: "gpt-4o");'
But using the overload that doesn't accept a
tools
parameter at all works perfectly:// This avoids the bug entirely
new ChatRequest(messages, model: "gpt-4o");
So until the internal logic is fixed to avoid setting
tool_choice
whentools == null
, the safest workaround is to avoid passing the tools argument ent…