#x_search of xai agents api is broken on openrouter

5 messages · Page 1 of 1 (latest)

fluid lichen
#
client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
)
tools = [
    {"type": "x_search"}
]

response = client.chat.completions.create(
        model="x-ai/grok-4.1-fast:free",
        messages=[
        {"role": "system", "content": "echo things"},
        {"role": "user", "content": "Hello world!"},
    ],
        tools=tools,
    )

this was working 2 days ago. now giving error:

openai.BadRequestError: Error code: 400 - {'error': {'message': '1.function: Invalid input: expected object, received undefined', 'code': 400, 'metadata': {'provider_name': 'xAI'}}, 'user_id': ''}

scarlet gazelleBOT
#

I'm an AI assistant - my answers may be incorrect and I cannot see screenshots. Please verify information with the OpenRouter docs.

To help debug this issue, I need more information:

  • Can you share the full API request payload (including the tools section) being sent to OpenRouter?
  • Are you using any additional parameters such as tool_choice or attempting to submit tool calls in the messages?
  • Have you changed the model identifier or any parameters compared to when it last worked?

These details are crucial to reproduce and diagnose the specific root cause. If you are trying to use function-calling (tools) with xAI models, please confirm if you were ever able to pass function parameters, as not all models support OpenAI function format or may require particular formatting. For current model support, you can double-check function/tool compatibility at OpenRouter Models.

-# This is an automated response powered by Answer HQ. Use !mute to stop the bot from responding.

The author you are looking for could not be found.

The author you are looking for could not be found.

fluid lichen
#

this is the exact openai sdk call. infre the api call by yourself. exactly this piece of code was working 2 days ago with no errors. now "x_search" tool which is xai internal agent tool, is not working on openrouter but work in xai api!!! fix it

scarlet gazelleBOT
#

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...

Grok 4 Fast is xAI's latest multimodal model with SOTA cost-efficiency and a 2M token context window. It comes in two flavors: non-reasoning and reasoning. Run Grok 4 Fast with API

The provider you are looking for could not be found.

#

... use case.

For current model capabilities and status, always double-check OpenRouter Models and the xAI provider info.

If you believe this is a new bug or a sudden regression, please collect:

  • Your full request payload
  • Time, region, and request ID if possible

…and share with the mods for escalation. If it's urgent, contact [email protected] or the Discord mods directly.
Documentation reference: xAI | OpenRouter

-# This is an automated response powered by Answer HQ. Use !mute to stop the bot from responding.

OpenRouter

Browse models on OpenRouter

The provider you are looking for could not be found.

Browse models provided by xAI