Musterby Elitery
Integrations

xAI Grok

Trace xAI Grok calls in Muster via the OpenAI-compatible API.

xAI serves Grok models behind an OpenAI-compatible endpoint. Trace them in Muster by pointing the Muster OpenAI wrapper at xAI's base URL.

Setup

%pip install langfuse openai --upgrade
import os

os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["GROK_API_KEY"] = "..."
from langfuse.openai import OpenAI

client = OpenAI(
    base_url="https://api.x.ai/v1",
    api_key=os.environ["GROK_API_KEY"],
)

response = client.chat.completions.create(
    model="grok-2-latest",
    messages=[{"role": "user", "content": "Hello, Grok!"}],
)
print(response.choices[0].message.content)

See also

On this page