Skip to content

OpenRouter model options should be camelCase #314

@tombeckenham

Description

@tombeckenham

TanStack AI version

0.5.1

Framework/Library version

React 19

Describe the bug and the steps to reproduce it

There is an issue mixing snake case with camelCase around the openrouter model options. The snake_case options passed through to chat in the openrouter adapter are silently ignored.

There is a test "maps options into the Chat Completions API payload" that tests if tool_choice ends up in the params payload sent to the openrouter sdk - which it does - BUT that doesn't properly test that it gets sent as part of the http request to openrouter.

What happens, is that all fields sent to the openrouter sdk pass through a Zod transformer which transforms camelCase inputs to snake_case outputs and ignores any other field. In the example above, you should pass toolChoice. That gets mapped to tool_choice by the openrouter sdk, but if you pass tool_choice in snake_case it will be stripped out.

This can be solved in one of two ways:

  1. Redo the convert-openrouter-models script to transform all of the snake_case types in the open api specs to camel case. This would be a breaking change, but is probably the right thing to do, OR
  2. Transform modelOptions from snake_case to camelCase before passing to the openrouter SDK

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://github.com/tombeckenham/ai-tom/blob/16069552f84d9a26105e6a18a71c907bf94f81dc/packages/typescript/ai-openrouter/tests/openrouter-adapter.test.ts#L151-L162

Screenshots or Videos (Optional)

It's easier to see this in a PR. I'll raise one

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

Yes, I am also opening a PR that solves the problem along side 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