Skip to content

Incorrect formatting in OpenAI Responses API request body for tool calls #124

@noorbhatia

Description

@noorbhatia

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": "..." }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions