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-3")
.prompt("Tell me about AI")
.build());
ModelContext Window
xai/grok-4Up to 2M tokens
xai/grok-4-1-fast131K tokens
xai/grok-3131K tokens
xai/grok-3-mini131K tokens
  • Text generation, streaming, tool calling, RAG

See the xai sample.