Skip to content

OpenRouter adapter stops before executing tools #371

@andorep

Description

@andorep

TanStack AI version

v0.6.1

Framework/Library version

N/A

Describe the bug and the steps to reproduce it

When using the openRouterText adapter with any model, the stream terminates immediately upon receiving a TOOL_END event, but before the tool is actually called or executed.

const stream = chat({
  adapter: openRouterText("minimax/minimax-m2.5"),
  messages,
  conversationId,
  tools: [serverTool],
});

Steps to reproduce:

  1. Send a prompt that triggers serverTool.
  2. Monitor the SSE stream.
  3. Observe TOOL_START followed immediately by TOOL_END.
  4. Result: The serverTool function is never invoked, and the connection closes.
  5. Send a second message (e.g., "Why didn't you run the tool?").
  6. The model acknowledges the previous state and execute the tool

NOTE:
I fixed this in a fork by debugging the stream handling logic. The issue was that the for (const choice of chunk.choices) loop was skipping the final message chunk entirely because the choices array was empty, preventing the tool execution from being triggered.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://github.com/andorep/openrouter-error

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Yes, I think I know how to fix it and will discuss it in the comments of this issue

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions