langchain - ✅(Solved) Fix OpenRouter.__init__() got an unexpected keyword argument 'x_title' [4 pull requests, 4 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36339Fetched 2026-04-08 01:45:25
View on GitHub
Comments
4
Participants
4
Timeline
16
Reactions
0
Timeline (top)
commented ×4cross-referenced ×4labeled ×3closed ×1

Since the last release of langchain-openrouter, I get the error bellow, linked to the x_title parameter if app_title is not provided when initializing ChatOpenRouter().

I could fix it by setting explicitly app_title=None at initialization, i.e. ChatOpenRouter( model=os.getenv("OPENROUTER_LLM_MODEL"), api_key=os.getenv("OPENROUTER_API_KEY"), app_title=None )

With the new release, app_title is set to the value "langchain" by default if no value is provided and it seems to create a problem. I didn't have a deeper look about the reason. You may however use the workaround for now :)

Error Message

llm = ChatOpenRouter(model="<model>") Traceback (most recent call last): File "<python-input-10>", line 1, in <module> llm = ChatOpenRouter(model="<model>") File "C:\Users<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_core\load\serializable.py", line 118, in init super().init(*args, **kwargs) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "C:\Users<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pydantic\main.py", line 250, in init validated_self = self.pydantic_validator.validate_python(data, self_instance=self) File "C:\Users<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 398, in validate_environment self.client = self._build_client() ~~~~~~~~~~~~~~~~~~^^ File "C:\Users<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 377, in _build_client return openrouter.OpenRouter(**client_kwargs) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ TypeError: OpenRouter.init() got an unexpected keyword argument 'x_title'

Root Cause

Since the last release of langchain-openrouter, I get the error bellow, linked to the x_title parameter if app_title is not provided when initializing ChatOpenRouter().

I could fix it by setting explicitly app_title=None at initialization, i.e. ChatOpenRouter( model=os.getenv("OPENROUTER_LLM_MODEL"), api_key=os.getenv("OPENROUTER_API_KEY"), app_title=None )

With the new release, app_title is set to the value "langchain" by default if no value is provided and it seems to create a problem. I didn't have a deeper look about the reason. You may however use the workaround for now :)

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

With the new release, app_title is set to the value "langchain" by default if no value is provided and it seems to create a problem. I didn't have a deeper look about the reason. You may however use the workaround for now :)

Other Dependencies

anthropic: 0.86.0 groq: 0.37.1 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.1.3 openai: 2.30.0 openrouter: 0.8.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.33.0 requests-toolbelt: 1.0.0 rich: 14.3.3 sqlalchemy: 2.0.48 tenacity: 9.1.4 tiktoken: 0.12.0 tokenizers: 0.22.2 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36340: fix(openrouter): support both old and new SDK param names for x_title

Description (problem / solution / changelog)

Fixes #36339

_build_client() was hardcoding x_title as the kwarg name, but openrouter SDK >=0.8.0 renamed it to x_open_router_title (and added x_open_router_categories). Anyone on the newer SDK gets TypeError: __init__() got an unexpected keyword argument 'x_title'.

This uses inspect.signature to check which param names the installed SDK actually accepts, then passes the right one. Same approach for app_categories -- if the SDK has x_open_router_categories natively, we skip the httpx header workaround.

Tests added for both old-style (x_title) and new-style (x_open_router_title, x_open_router_categories) SDK signatures using fake SDK classes patched in.

make test, make lint, and make format all pass.

Disclosure: AI agents were used to assist with this contribution.

Twitter: @ LinkedIn: https://linkedin.com/in/

Changed files

  • libs/partners/openrouter/langchain_openrouter/chat_models.py (modified, +29/-17)
  • libs/partners/openrouter/tests/unit_tests/test_chat_models.py (modified, +70/-0)

PR #36341: fix(openrouter): handle renamed SDK params for x_title and categories

Description (problem / solution / changelog)

Fixes #36339

OpenRouter SDK >=0.8.0 renamed x_title to x_open_router_title and added a native x_open_router_categories param. The old x_title kwarg now throws TypeError: OpenRouter.__init__() got an unexpected keyword argument 'x_title'.

This uses inspect.signature to check which params the installed SDK version accepts, then picks the right kwarg name at runtime. Both old (<0.8.0) and new (>=0.8.0) SDKs work without pinning a specific version.

Three new unit tests cover both paths using fake SDK classes patched via unittest.mock.patch.

How I verified: make test from libs/partners/openrouter — 217 passed.

Note: This PR was developed with AI assistance.

  • I've read and followed the contributing guidelines
  • make format, make lint and make test pass
  • This PR links to an approved issue
  • This PR touches only one package
  • uv.lock is not modified

Changed files

  • libs/partners/openrouter/langchain_openrouter/chat_models.py (modified, +29/-17)
  • libs/partners/openrouter/tests/unit_tests/test_chat_models.py (modified, +70/-0)

PR #36344: fix(openrouter): update x_title to x_open_router_title for SDK 0.8.0 compatibility

Description (problem / solution / changelog)

Fixes #36339. The openrouter Python SDK changed the parameter name from x_title to x_open_router_title in version 0.8.0. This PR updates the ChatOpenRouter class to use the new parameter name.

Changed files

  • libs/partners/openrouter/langchain_openrouter/chat_models.py (modified, +1/-1)
  • libs/partners/openrouter/tests/unit_tests/test_chat_models.py (modified, +4/-4)

PR #36347: fix(openrouter): pass attribution headers via httpx default_headers

Description (problem / solution / changelog)

Fixes #36339


The openrouter SDK v0.8.0 renamed x_title to x_open_router_title, breaking ChatOpenRouter instantiation with the default app_title.

Rather than chasing SDK parameter renames across versions, all three attribution headers are now injected via httpx default_headers — version-agnostic and consistent with how app_categories was already handled.

Changes

  • Pass HTTP-Referer, X-Title, and X-OpenRouter-Categories as httpx client default headers in _build_client instead of SDK constructor kwargs (http_referer, x_title), making the integration compatible across openrouter>=0.7.11,<1.0.0
  • Move _build_client() inside the try/except ImportError in validate_environment so a version-mismatch ImportError from openrouter.utils gets the friendly install message instead of a raw traceback
  • Add warnings.warn in _wrap_messages_for_sdk for two previously silent fallbacks: failed openrouter.components import (file blocks sent as raw dicts) and unknown message roles passed through to the API
  • Clarify max_retries docstring to explain the ~150s-per-unit backoff mapping; drop stale (v0.6.0) version reference in _wrap_messages_for_sdk

Changed files

  • libs/partners/openrouter/langchain_openrouter/chat_models.py (modified, +20/-14)
  • libs/partners/openrouter/tests/unit_tests/test_chat_models.py (modified, +62/-19)
  • libs/partners/openrouter/uv.lock (modified, +1/-1)

Code Example

llm = ChatOpenRouter(model="<model>")

---

llm = ChatOpenRouter(model="<model>")
Traceback (most recent call last):
  File "<python-input-10>", line 1, in <module>
    llm = ChatOpenRouter(model="<model>")
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_core\load\serializable.py", line 118, in __init__
    super().__init__(*args, **kwargs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pydantic\main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 398, in validate_environment
    self.client = self._build_client()
                  ~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 377, in _build_client
    return openrouter.OpenRouter(**client_kwargs)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: OpenRouter.__init__() got an unexpected keyword argument 'x_title'
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

llm = ChatOpenRouter(model="<model>")

Error Message and Stack Trace (if applicable)

llm = ChatOpenRouter(model="<model>")
Traceback (most recent call last):
  File "<python-input-10>", line 1, in <module>
    llm = ChatOpenRouter(model="<model>")
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_core\load\serializable.py", line 118, in __init__
    super().__init__(*args, **kwargs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pydantic\main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 398, in validate_environment
    self.client = self._build_client()
                  ~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\<user>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\langchain_openrouter\chat_models.py", line 377, in _build_client
    return openrouter.OpenRouter(**client_kwargs)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: OpenRouter.__init__() got an unexpected keyword argument 'x_title'

Description

Since the last release of langchain-openrouter, I get the error bellow, linked to the x_title parameter if app_title is not provided when initializing ChatOpenRouter().

I could fix it by setting explicitly app_title=None at initialization, i.e. ChatOpenRouter( model=os.getenv("OPENROUTER_LLM_MODEL"), api_key=os.getenv("OPENROUTER_API_KEY"), app_title=None )

With the new release, app_title is set to the value "langchain" by default if no value is provided and it seems to create a problem. I didn't have a deeper look about the reason. You may however use the workaround for now :)

System Info

Get the error on Linux and Windows:

System Information

OS: Linux OS Version: #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 Python Version: 3.11.15 (main, Mar 16 2026, 23:07:56) [GCC 14.2.0]

Package Information

langchain_core: 1.2.23 langchain: 1.2.13 langsmith: 0.7.22 langchain_anthropic: 1.4.0 langchain_classic: 1.0.3 langchain_groq: 1.1.2 langchain_mistralai: 1.1.2 langchain_openai: 1.1.12 langchain_openrouter: 0.2.0 langchain_text_splitters: 1.1.1 langgraph_sdk: 0.3.12

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

anthropic: 0.86.0 groq: 0.37.1 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.1.3 openai: 2.30.0 openrouter: 0.8.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.33.0 requests-toolbelt: 1.0.0 rich: 14.3.3 sqlalchemy: 2.0.48 tenacity: 9.1.4 tiktoken: 0.12.0 tokenizers: 0.22.2 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

System Information

OS: Windows OS Version: 10.0.26200 Python Version: 3.13.12 (tags/v3.13.12:1cbe481, Feb 3 2026, 18:22:25) [MSC v.1944 64 bit (AMD64)]

Package Information

langchain_core: 1.2.23 langchain: 1.2.10 langsmith: 0.7.1 langchain_anthropic: 1.3.3 langchain_groq: 1.1.2 langchain_mistralai: 1.1.1 langchain_openai: 1.1.9 langchain_openrouter: 0.2.0 langgraph_sdk: 0.3.5

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

anthropic: 0.79.0 groq: 0.37.1 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.0.8 openai: 2.8.1 openrouter: 0.8.0 orjson: 3.11.7 packaging: 25.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.2 tenacity: 9.1.4 tiktoken: 0.12.0 tokenizers: 0.22.1 typing-extensions: 4.15.0 uuid-utils: 0.14.0 xxhash: 3.6.0 zstandard: 0.25.

extent analysis

Fix Plan

To fix the issue, you need to explicitly set app_title to None when initializing ChatOpenRouter(). Here are the steps:

  • Update your code to include app_title=None in the ChatOpenRouter() initialization:
llm = ChatOpenRouter(
    model="<model>",
    app_title=None
)

Alternatively, you can also set app_title to an empty string or a custom title if needed.

Verification

To verify that the fix worked, run your code with the updated ChatOpenRouter() initialization and check that the error is resolved. You should be able to create an instance of ChatOpenRouter() without encountering the TypeError related to the x_title parameter.

Extra Tips

Note that the issue is caused by a change in the default value of app_title in the langchain-openrouter package. By explicitly setting app_title to None, you are overriding the default value and avoiding the error. If you encounter similar issues in the future, check the documentation and release notes for any changes to default values or parameter requirements.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix OpenRouter.__init__() got an unexpected keyword argument 'x_title' [4 pull requests, 4 comments, 4 participants]