rapid-painting-51133
03/26/2026, 4:51 PMtall-airline-16756
03/26/2026, 4:51 PMtall-airline-16756
03/26/2026, 4:52 PMllm argument (quickest).
• Create an LLM instance from the inference module to pass extra configuration.
• Use provider plugin LLM classes (for OpenAI-compatible providers and vendors).
• Use the LLM instance directly (streaming chat) or call .collect() to await a full response.
• For custom behavior, override llm_node in your agent class.
Examples
1) Quick AgentSession with model id (Python)
from livekit.agents import AgentSession
session = AgentSession(
llm="openai/gpt-4.1-mini"
)
(Typescript equivalent)
const session = new AgentSession({
llm: "openai/gpt-4.1-mini"
});
2) AgentSession with extra LLM config (Python)
from livekit.agents import AgentSession, inference
session = AgentSession(
llm=inference.LLM(
model="openai/gpt-4.1-mini",
extra_kwargs={"max_completion_tokens": 1000}
)
)
3) Plugin-based provider (OpenAI plugin example — Python)
from livekit.plugins import openai
from livekit.agents import AgentSession
session = AgentSession(
llm=openai.LLM(model="gpt-4o-mini")
)
4) OpenAI-compatible providers via helper (Groq example)
from livekit.plugins import openai
session = AgentSession(
llm=openai.LLM.with_groq(model="llama3-8b-8192")
)
5) Use an LLM instance directly (streaming chat — Python)
llm = openai.responses.LLM(model="gpt-4o-mini")
chat_ctx = ChatContext()
chat_ctx.add_message(role="user", content="Hello!")
async with llm.chat(chat_ctx=chat_ctx) as stream:
async for chunk in stream:
print("Received chunk:", chunk.delta)
6) Awaiting a full response (collect)
response = await my_llm.chat(chat_ctx=chat_ctx).collect()
print(response.text)
Custom LLM logic
• If you need custom inference behavior inside an agent pipeline, override the llm_node method in your agent class to control how the LLM is called and how responses are handled.
If you’d like, tell me:
• Which language you’re using (Python or TypeScript),
• Which provider/model you plan to call (example: OpenAI, Groq, Together AI), and
• Whether you want streaming or a single completed response.
I’ll give a tailored code snippet and next steps based on that.
Sources: Large language models (LLM) overview | LiveKit Documentation | OpenAI LLM models | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation, with interactive elements