Thank you for clarifying your setup and sharing your exact code and error.
Based on the available documentation, there is no explicit listing or format for enabling xAI agent tools such as x_search via the OpenRouter API, nor confirmation that arbitrary function/tool definitions are supported for the x-ai/grok-4.1-fast:free model on OpenRouter. The model details for xAI Grok 4 Fast do not document support for custom tools or OpenAI-style function calling, nor do they mention explicit support for agents/APIs like x_search through the OpenRouter interface.
Quoting the documentation:
- "Grok 4 Fast is xAI's latest multimodal model... Reasoning can be enabled using the
reasoning enabled parameter in the API. Learn more in our docs"
- There is no mention of agent tool or function-calling API compatibility for xAI models on OpenRouter xAI | OpenRouter.
Currently, it appears that support for x_search or similar tool calls is only guaranteed on xAI's own API, and not through the OpenRouter API. The error message 'Invalid input: expected object, received undefined' suggests a schema or payload incompatibility, or that the internal mapping to the xAI API has changed or is not implemented.
To summarize:
- There is no documentation indicating support for the xAI agent tool API/
x_search through OpenRouter.
- Tool/function-calling shown in the OpenAI SDK format may not be compatible with xAI models via OpenRouter.
- If you require agent/tool access for xAI models (such as
x_search), you should use the native xAI API where this is confirmed to work.
For the latest or to request this feature, contact the OpenRouter support team or reach out to the mods on Discord and share your...