API / enable-x-search-image-understanding

API

Enable image understanding on X Search

Enable image understanding on X Search

Set enable_image_understanding on the x_search tool so Grok can inspect images attached to X posts when answering. Base X Search setup: Search X posts with the Grok API. For video on the same tool, see Enable video understanding on X Search.

xAI SDK

import os

from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import x_search

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.6",
    tools=[
        x_search(enable_image_understanding=True),
    ],
)

chat.append(user("Find X posts with images about AI and describe what the images show."))
response = chat.sample()
print(response.content)

OpenAI Responses

curl https://api.x.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
  "model": "grok-4.6",
  "input": [
    {
      "role": "user",
      "content": "Find X posts with images about AI and describe what the images show."
    }
  ],
  "tools": [
    {
      "type": "x_search",
      "enable_image_understanding": true
    }
  ]
}'

Vercel AI SDK

import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: xai.responses('grok-4.6'),
  prompt: 'Find X posts with images about AI and describe what the images show.',
  tools: {
    x_search: xai.tools.xSearch({
      enableImageUnderstanding: true,
    }),
  },
});

console.log(text);

Pitfalls

  • This flag lives on x_search. Web Search has its own enable_image_understanding for images found while browsing pages.
  • Enabling image understanding on Web Search also enables it for X Search when both tools are on the same request.
  • Tool calls bill tokens plus invocations. One question can fire several searches.
  • Console API credits are separate from SuperGrok's weekly pool on grok.com.