Skip to content

fix(OpenAI): parse custom tool calls of chat completions - #847

Open
skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:fix/chat-custom-tool-call
Open

skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:fix/chat-custom-tool-call

Conversation

@skybleak333

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

With a custom tool ({"type": "custom", "custom": {"name": "code_exec"}}, the free-form tools of GPT-5), a chat completion can return a tool call without function:

{"id": "call_Hrb6BWd1ZW8VnnyJFdtR6dsv", "type": "custom", "custom": {"name": "code_exec", "input": "print(\"hello world\")"}}

This is ChatCompletionMessageCustomToolCall in the API reference and in openai-python. CreateResponseToolCall::from() always read $attributes['function'], so chat()->create() failed with a TypeError on such a response, after OpenAI had run and billed it.

CreateResponseToolCall now has a nullable function and a custom property (CreateResponseToolCallCustom with name and input), and toArray() returns whichever the API sent. Function tool calls don't change. The new tests fail without the fix, and the full suite, Pint and PHPStan pass.

Not changed: streamed chunks. I couldn't check what the API streams for a custom tool call, so CreateStreamedResponseToolCall still expects function.

skybleak333 added a commit to skybleak333/skybleak333 that referenced this pull request Nov 13, 2026
@iBotPeaches

Copy link
Copy Markdown
Collaborator

conflicts as well here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants