Skip to content

fix(web-search): Grok provider returns 'No response' due to response format mismatch #13520

@higginsvott

Description

@higginsvott

Problem

The Grok web_search provider returns "No response" even though the xAI API returns valid data.

Root Cause

The xAI /v1/responses API returns data in a different format than expected:

Expected (current code):

{
  "output_text": "...",
  "citations": [...]
}

Actual xAI response:

{
  "output": [
    {
      "type": "message",
      "content": [
        {
          "type": "output_text",
          "text": "Hello! How's it going?",
          "annotations": [
            {"type": "url_citation", "url": "...", "start_index": 0, "end_index": 10}
          ]
        }
      ]
    }
  ]
}

Fix

Update runGrokSearch in src/agents/tools/web-search.ts to handle both formats:

const data = (await res.json()) as GrokSearchResponse;

// Extract text from the new response format
let content = data.output_text ?? "";
let citations: string[] = data.citations ?? [];
let inlineCitations = data.inline_citations;

// Handle the new xAI /v1/responses format
if (!content && data.output?.length) {
  const message = data.output.find((o) => o.type === "message");
  if (message?.content?.length) {
    const textContent = message.content.find((c) => c.type === "output_text");
    if (textContent?.text) {
      content = textContent.text;
    }
    // Extract citations from annotations
    if (textContent?.annotations?.length && !citations.length) {
      const urlCitations = textContent.annotations
        .filter((a) => a.type === "url_citation" && a.url)
        .map((a) => a.url as string);
      citations = [...new Set(urlCitations)];
    }
  }
}

if (!content) {
  content = "No response";
}

Tested

  • Direct curl to xAI API works and returns expected format
  • With this fix applied locally, responses parse correctly

Environment

  • OpenClaw: 2026.2.9
  • xAI API: /v1/responses endpoint
  • Model: grok-4-1-fast

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions