-
Notifications
You must be signed in to change notification settings - Fork 55
Description
The Responses.createRequestBody method in OpenAILanguageModel was incorrectly formatting several parts of the request body using Chat Completions API conventions instead of Responses API conventions. This caused tool call round-trips to fail when using apiVariant: .responses.
Three distinct bugs were identified:
Bug 1: Tool output formatted as user content blocks
When building function_call_output items from .tool messages, the code was:
Wrapping text in input_text content blocks (user message style)
JSON-serializing the blocks back into a string
Sending that string as the output field
The Responses API expects the output field to be the tool's output directly — a plain string for text, not a re-serialized JSON content block.
Bug 2: image_url nested object instead of flat string
Inside tool output blocks, image URLs were formatted as:
"image_url": { "url": "https://..." }
This is the Chat Completions format. The Responses API expects:
"image_url": "https://..."
Bug 3: Raw assistant tool call messages passed through unconverted
When the model returns tool calls, the assistant message is stored as .raw(rawContent:) in Chat Completions format:
{ "role": "assistant", "tool_calls": [{ "id": "...", "function": { "name": "...", "arguments": "..." } }] }
This was appended directly to the Responses API input array. The Responses API expects individual function_call items:
{ "type": "function_call", "call_id": "...", "name": "...", "arguments": "..." }