Skip to content

[Go] Tool Calls in OpenAI Plugin Fails #3247

@kingsleyzhong

Description

@kingsleyzhong

Describe the bug

When using tool calls with OpenAI the tool call ID is not passed properly in the messages.

Sample error message:
failed to create completion: POST "https://api.openai.com/v1/chat/completions": 400 Bad Request { "error": { "message": "Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.", "type": "invalid_request_error", "param": "messages.[5].role", "code": null } }

To Reproduce
Define any tool with Go and attempt to generate using an OpenAI model that supports tool calling. (ie. openai/gpt-4.1).

Expected behavior
Tool call succeeds.

Runtime (please complete the following information):

  • OS: MacOS

** Go version
go1.24.1 darwin/arm64

Additional context
I have a fix. Opening PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggo

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions