how do i change this endpoint to use a grok api ke...
# ask-ai
w
how do i change this endpoint to use a grok api key instead? async def entrypoint(ctx: agents.JobContext): session = AgentSession( llm=openai.realtime.RealtimeModel.with_azure( voice="alloy", azure_deployment=os.getenv("AZURE_OPENAI_DEPLOYMENT"), azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"), api_key=os.getenv("AZURE_OPENAI_KEY"), api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
t
Thanks for reaching out, Marius. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to switch that Azure OpenAI realtime setup to use a Grok (xAI) API key. Below are the minimal code and environment changes to do that. Replace the Azure call with the xAI realtime model and ensure the xAI plugin is installed: 1) Code change
Copy code
from livekit.plugins import xai

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=xai.realtime.RealtimeModel(
            voice="ara"  # optional: "ara", "sabina", "jose", "daniel", etc.
        ),
    )
2) Set the Grok (xAI) API key in env
Copy code
XAI_API_KEY=your_grok_api_key_here
Load it with your existing dotenv or env loader. 3) Install the plugin (if not already)
Copy code
uv add "livekit-agents[xai]~=1.3"
Notes: • Remove the
with_azure(...)
call and the Azure-specific env vars (
AZURE_OPENAI_*
). • Authentication uses
XAI_API_KEY
, not Azure keys. • If you want, I can show how to pass additional realtime options (turn detection, TTS settings, or custom voice). Which would you like next? Sources: xAI Grok Voice Agent API plugin | LiveKit docs | xAI and LiveKit | LiveKit docs
Thanks for the details — you hit that warning because the installed livekit-agents package (1.3.5) doesn’t expose an
xai
extra the way you attempted to add it. Quick checklist and steps to resolve: 1. Confirm your environment: • Which Python package manager are you using (`uv`/pdm/poetry/pip`)? • Run and share:
uv show livekit-agents
(or
pip show livekit-agents
) to confirm the installed version. 1. Install the xAI plugin correctly: • If you’re using
uv
, run:
Copy code
uv add "livekit-agents[xai]~=1.3"
• If you use `pip`:
Copy code
pip install "livekit-agents[xai]~=1.3"
This will pull the xai extra that provides the
livekit.plugins.xai
module. 1. If the extra still isn’t available: • Upgrade livekit-agents to the latest 1.3.x that includes the extra:
Copy code
uv add "livekit-agents~=1.3.5"
# or
pip install --upgrade "livekit-agents~=1.3"
• Then re-run the
uv add "livekit-agents[xai]~=1.3"
install. 1. Env & code reminders: • Ensure
XAI_API_KEY
is set in your environment or .env. • Replace
openai.realtime.RealtimeModel.with_azure(...)
with
xai.realtime.RealtimeModel(...)
in code. If you run the install command and still see the warning, paste the output of
uv show livekit-agents
(or
pip show livekit-agents
) and I’ll tell you the exact next step. Which package manager did you run
uv sync
with? Sources: xAI and LiveKit | LiveKit docs | xAI LLM plugin guide | LiveKit docs
Thanks — since you have livekit-agents 1.3.5 installed, do this minimal change to use Grok (xAI): 1) Install the OpenAI extra (this provides xAI support for 1.3.5)
Copy code
uv add "livekit-agents[openai]~=1.3"
# or with pip
pip install "livekit-agents[openai]~=1.3"
2) Set your Grok API key
Copy code
export XAI_API_KEY=your_grok_api_key_here
# or add to .env and load it with dotenv
3) Update your code to use the OpenAI plugin’s xAI helper:
Copy code
from livekit.plugins import openai

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=openai.LLM.with_x_ai(
            model="grok-4-1-fast-non-reasoning",   # or other Grok model
            api_key=os.getenv("XAI_API_KEY"),
        ),
    )
Notes: • Keep your current livekit-agents 1.3.5; the
xai
extra isn’t exposed there, but the
openai
extra supports
with_x_ai()
for Grok. • If you prefer using
livekit.plugins.xai
directly, upgrade to a livekit-agents release that includes the
xai
extra and then install
livekit-agents[xai]~=1.3
. Want me to provide the exact upgrade command for switching to the
xai
extra? Sources: xAI LLM plugin guide | LiveKit docs
w
is this correct: async def entrypoint(ctx: agents.JobContext): session = AgentSession( llm=openai.LLM.with_x_ai( model="grok-4-1-fast-non-reasoning", ), ) When I call the phone number I get no answer
t
You're close — but we need to check two things: the model/plugin choice and your telephony wiring. I’ll confirm the code and then give focused troubleshooting steps for the "no answer" phone call. Acknowledging your snippet • Your snippet using
openai.LLM.with_x_ai(...)
can be correct only if: ◦ You installed the OpenAI plugin extra (
livekit-agents[openai]
) for your livekit-agents version. ◦ You set
XAI_API_KEY
with your Grok key. ◦ You use a supported Grok model name (e.g.,
grok-2-public
or
grok-beta
), not an unsupported model string. Correct minimal example (OpenAI plugin path)
Copy code
from livekit.plugins import openai
from livekit.agents import AgentSession

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=openai.LLM.with_x_ai(
            model="grok-2-public",
            api_key=os.getenv("XAI_API_KEY"),
        ),
    )
If you intend real-time voice (low-latency speech), use the xai realtime plugin instead:
Copy code
from livekit.plugins import xai

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=xai.realtime.RealtimeModel(
            model="grok-beta",
            voice="ara",
        ),
    )
That requires
livekit-agents[xai]
and
XAI_API_KEY
set. Troubleshooting why the phone call gets no answer Please confirm or check each item below and tell me the results so I can narrow this quickly: 1. Agent process status • Is your agent running and started in dev mode (e.g.,
python agent.py dev
)? Check the agent logs for connection/registration messages. 1. Dispatch rule & agent name • Does your dispatch rule in Telephony point to the exact agent name your code registers? (Agent name must match the dispatch rule.) 1. Telephony configuration • Is the phone number associated with the dispatch rule that routes to your agent? Verify in LiveKit Cloud → Telephony → Configuration. 1. Plugin & API key • Which package did you install? Share output of
uv show livekit-agents
or
pip show livekit-agents
. • Confirm
XAI_API_KEY
is set and accessible to the running process. 1. Model choice • Which model did you specify? Use
grok-2-public
or
grok-beta
for supported flows. If using realtime voice, use
xai.realtime.RealtimeModel
. 1. Logs/errors when calling • Do you see any errors in agent logs when the call arrives (webhook/telephony logs)? Paste any error lines you see. Next step • Tell me: which plugin path you prefer (OpenAI plugin with
with_x_ai()
or xai realtime), the livekit-agents version you have, and paste any relevant log lines. I’ll provide the exact code snippet and the next fix based on that. Sources: xAI Grok Voice Agent API plugin | LiveKit docs | xAI LLM plugin guide | LiveKit docs | SIP troubleshooting guide | LiveKit docs | Simple Call Answering Agent | LiveKit docs
w
i have specified XAI_API_KEY in .env
t
Thanks — glad you confirmed
XAI_API_KEY
is set. Next, let’s narrow down why the call isn’t answered. Please provide these quick checks and answers: 1. Which plugin path are you using in code? ◦
openai.LLM.with_x_ai(...)
or
xai.realtime.RealtimeModel(...)
? 1. livekit-agents install & version (paste output): ◦ Run
uv show livekit-agents
or
pip show livekit-agents
. 1. How are you running the agent? ◦ Command you run (e.g.,
python agent.py dev
,
uv run
, etc.). 1. Agent name vs dispatch rule: ◦ Does your agent register a name? Share the
agent_name
in your code or the decorator. ◦ Confirm the Telephony dispatch rule points to that exact name. 1. Model string you set in code (exact value). 2. Any relevant logs when a call comes in (agent logs, telephony logs, or errors). Paste the most recent lines. With those details I’ll give the exact corrected snippet and the likely fix (routing, plugin mismatch, or runtime/env issue).
w
this is my entire entrypoint: async def entrypoint(ctx: agents.JobContext): session = AgentSession( llm=openai.LLM.with_x_ai( model="grok-4-1-fast-non-reasoning", ), )
t
Thanks — I can see your full entrypoint. Two immediate issues to fix so the call can be answered: 1) Model + plugin mismatch •
grok-4-1-fast-non-reasoning
is not a documented Grok model for LiveKit. Use a supported model name. • If you’re using the OpenAI plugin path, use this minimal, correct form:
Copy code
from livekit.plugins import openai
from livekit.agents import AgentSession
import os

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=openai.LLM.with_x_ai(
            model="grok-2-public",            # use a supported model
            api_key=os.getenv("XAI_API_KEY"), # ensure this is set
        ),
    )
• If you want realtime voice (low-latency), instead use the xai realtime plugin:
Copy code
from livekit.plugins import xai

async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=xai.realtime.RealtimeModel(
            model="grok-beta",
            voice="ara",
        ),
    )
2) Telephony routing & runtime checks (most common cause of “no answer”) Please confirm these quickly: • livekit-agents package/version: run
uv show livekit-agents
or
pip show livekit-agents
and paste output. • Which plugin you installed:
livekit-agents[openai]
or
livekit-agents[xai]
? • How you run the agent (exact command — e.g.,
python agent.py dev
). • Agent registration name / decorator (does your agent set
agent_name
?), and that the Telephony dispatch rule points to that exact name. • Any agent logs when a call arrives (paste the last 10–20 lines). Give me those answers and I’ll provide the exact code you should run and the single next step to fix the no-answer behavior.