-
-
Notifications
You must be signed in to change notification settings - Fork 68.9k
fix(web-search): Grok provider returns 'No response' due to response format mismatch #13520
Copy link
Copy link
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.