Model providers

Using xAI Grok with OpenClaw

3 min read

Browse more in Model providers.

All model providers guides →

This guide shows you how to wire xAI Grok models into OpenClaw using the bundled `xai` provider. You configure your xAI API key once, pick a Grok model like `xai/grok-4`, and optionally enable Grok-backed web search and video generation.

By the end, your OpenClaw agents will call Grok for chat, search, and video through a single, consistent config.

Prerequisites

  • An xAI account with access to Grok models and permission to create API keys.
  • An xAI API key created in the xAI console.
  • An existing OpenClaw installation with access to the `openclaw` CLI.

Steps

  1. 1

    Create an xAI API key

    Start by creating an API key in the xAI console so OpenClaw can talk to the Grok APIs. You will use this key both for core Grok chat models and for Grok-backed tools like web search and code execution.

  2. 2

    Set your XAI_API_KEY for OpenClaw

    Expose your xAI key to OpenClaw by setting `XAI_API_KEY` or running the onboarding command. The CLI flow is useful when you do not want to manage environment variables manually and keeps auth consistent with other providers.

    bash
    openclaw onboard --auth-choice xai-api-key
  3. 3

    Configure your agent to use a Grok model

    Tell OpenClaw which Grok model to use by default so your agents route traffic through the bundled `xai` provider. Using a fully qualified model id like `xai/grok-4` keeps things explicit and lets you swap to other Grok variants later without touching code.

    json
    {
      agents: { defaults: { model: { primary: "xai/grok-4" } } },
    }
  4. 4

    Enable Grok-backed web search

    If you want your agents to call Grok’s web search, set the web search provider to `grok`. The bundled `grok` web-search provider automatically uses `XAI_API_KEY`, so you do not need a separate key for search.

    bash
    openclaw config set tools.web.search.provider grok
  5. 5

    Set xAI as the default video generation provider

    Use the bundled `xai` plugin for video generation through the shared `video_generate` tool. This config makes `xai/grok-imagine-video` the default video model for text-to-video, image-to-video, and remote edit flows.

    json
    {
      agents: {
        defaults: {
          videoGenerationModel: {
            primary: "xai/grok-imagine-video",
          },
        },
      },
    }

Configuration

OptionDescriptionExample
XAI_API_KEYAPI key used by the bundled xAI provider for Grok models, web_search, x_search, and remote code_execution.xai-sk-live-1234567890abcdef
plugins.entries.xai.config.webSearch.apiKeyOptional xAI API key specifically for Grok-backed web_search; the bundled xAI model provider reuses this as a fallback.xai-sk-search-abcdef1234567890
plugins.entries.xai.config.codeExecutionConfiguration block for remote xAI sandbox code_execution behavior.{ sandbox: "default" }
agents.defaults.models["xai/<model>"].params.fastModeWhen true, rewrites Grok model ids to their corresponding fast variants for lower latency and image-capable refs.true
agents.defaults.models["xai/<model>"].params.tool_streamControls xAI native tool streaming; defaults to true and can be set to false to disable tool_stream.false

Troubleshooting

Grok calls fail and OpenClaw does not reach xAI after onboarding

OpenClaw uses `XAI_API_KEY` for the bundled xAI transport. If you ran `openclaw onboard --auth-choice xai-api-key` in a different environment or shell, the key may not be available where your agent runs; rerun the command in the correct environment or set `XAI_API_KEY` explicitly.

bash
openclaw onboard --auth-choice xai-api-key

Web search tools do not use Grok even though xAI is configured

The bundled Grok web-search provider only activates when you set the provider to `grok`. provider` points at `grok`, which then uses `XAI_API_KEY` under the hood.

bash
openclaw config set tools.web.search.provider grok

Video generation fails when sending local video buffers

The xAI video generation path does not accept local video buffers. Use remote `http(s)` URLs for video-reference or edit inputs so the shared `video_generate` tool can call `xai/grok-imagine-video` successfully.

A Grok multi-agent experimental model id does not work with the xAI provider

20-multi-agent-experimental-beta-0304` is not supported on the normal xAI provider path because it requires a different upstream API surface. 20-beta-latest-reasoning` instead.

Frequently asked questions

Powered by Mem0

Add persistent memory to OpenClaw

Official Mem0 plugin for OpenClaw keeps context across chats and tools. Smaller prompts, lower cost, better continuity for your agents.

More in Model providers