-
-
Notifications
You must be signed in to change notification settings - Fork 88
Description
Bug Report
Overview
When using forced function calling (tool_choice with "type": "function") in the Realtime Sessions API via the Unity OpenAI package, the request fails with a 400 error:
Missing required parameter: 'tool_choice.name'.
The issue appears to be caused by the Unity package generating an incorrect JSON structure for tool_choice. The package sends:
"tool_choice": {
"type": "function",
"function": {
"name": "MyFunctionName"
}
}However, the Realtime Sessions API expects:
"tool_choice": {
"type": "function",
"name": "MyFunctionName"
}This mismatch causes the server to reject the request.
To Reproduce
Steps to reproduce the behavior:
- Create a Realtime session using
CreateSessionAsync. - Register one or more tools (functions).
- Configure
tool_choiceto force a specific function. - Start the session.
- Observe the 400 Bad Request response from the server.
Example configuration sent by the package:
"tool_choice": {
"type": "function",
"function": {
"name": "ExecuteAnimation_abc123"
}
}Expected behavior
The session should be created successfully when forcing a valid registered tool via tool_choice.
The request body should match the Realtime Sessions API specification:
"tool_choice": {
"type": "function",
"name": "ExecuteAnimation_abc123"
}Screenshots
N/A (server error response included below)
Server response:
{
"error": {
"message": "Missing required parameter: 'tool_choice.name'.",
"type": "invalid_request_error",
"param": "tool_choice.name",
"code": "missing_required_parameter"
}
}Additional context
The issue originates in the Unity package's ToolExtensions.ProcessTools<T> method:
activeTool = new
{
type = "function",
function = new { name = tool.Function.Name }
};This produces a nested "function": { "name": ... } structure, which does not conform to the Realtime Sessions API specification.
According to the official documentation:
https://developers.openai.com/api/docs/guides/realtime-conversations
When type is "function", the name field must be provided directly under tool_choice.
Suggested Fix
Replace:
activeTool = new
{
type = "function",
function = new { name = tool.Function.Name }
};With:
activeTool = new
{
type = "function",
name = tool.Function.Name
};This aligns the generated request with the API specification and resolves the 400 error.