Add extra_body parameter support in openrouter (#3479)

Closes #3263

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds support for an extra_body parameter in ChatOpenRouter to pass
custom request fields to OpenRouter API calls. This adds flexibility for
provider-specific options and fulfills Linear #3263.

- **New Features**
- Added extra_body field to ChatOpenRouter and spread it into ainvoke
requests.
  - Default is None, so no breaking changes.

<sup>Written for commit 7e477ea. Summary will update automatically on
new commits.</sup>

<!-- End of auto-generated description by cubic. -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is
generating a summary for commit
f54d0929b1. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
Magnus Müller
2025-10-30 23:36:02 -07:00
committed by GitHub

View File

@@ -48,6 +48,7 @@ class ChatOpenRouter(BaseChatModel):
default_query: Mapping[str, object] | None = None
http_client: httpx.AsyncClient | None = None
_strict_response_validation: bool = False
extra_body: dict[str, Any] | None = None
# Static
@property
@@ -148,6 +149,7 @@ class ChatOpenRouter(BaseChatModel):
top_p=self.top_p,
seed=self.seed,
extra_headers=extra_headers,
**(self.extra_body or {}),
)
usage = self._get_usage(response)
@@ -178,6 +180,7 @@ class ChatOpenRouter(BaseChatModel):
type='json_schema',
),
extra_headers=extra_headers,
**(self.extra_body or {}),
)
if response.choices[0].message.content is None: