Skip to main content

xAI (Grok)

xAI's Grok models via the OpenAI-compatible API.

Install

pip install synapsekit[openai]

Usage

from synapsekit.llm.xai import XaiLLM
from synapsekit import LLMConfig

config = LLMConfig(
model="grok-2",
api_key="xai-...",
provider="xai",
)

llm = XaiLLM(config)

# Streaming
async for token in llm.stream("Explain the trolley problem"):
print(token, end="")

# Generate
response = await llm.generate("What is entropy?")

Available models

ModelNotes
grok-betaOriginal Grok
grok-2Latest generation
grok-2-miniFaster, lower cost

Function calling

from synapsekit import AgentExecutor, AgentConfig, CalculatorTool

config = AgentConfig(
model="grok-2",
api_key="xai-...",
provider="xai",
tools=[CalculatorTool()],
)
executor = AgentExecutor(config)
result = await executor.run("What is 15% of 284?")