Skip to content

xAI (Grok)

The xAI plugin provides access to Grok models.

<dependency>
<groupId>com.google.genkit</groupId>
<artifactId>genkit-plugin-xai</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Terminal window
export XAI_API_KEY=your-api-key
import com.google.genkit.plugins.xai.XAIPlugin;
Genkit genkit = Genkit.builder()
.plugin(XAIPlugin.create())
.build();
ModelResponse response = genkit.generate(
GenerateOptions.builder()
.model("xai/grok-4.3")
.prompt("Tell me about AI")
.build());
Model Context Window
xai/grok-4.3 Up to 2M tokens
xai/grok-4.20-0309-reasoning Up to 2M tokens
xai/grok-4.20-0309-non-reasoning Up to 2M tokens
xai/grok-4.20-multi-agent-0309 Up to 2M tokens
xai/grok-build-0.1 256K tokens (agentic coding)
  • Text generation, streaming, tool calling, RAG

See the xai sample.