ModelCall. Pick a class that implements it, give it to your framework’s adapter, and the library fills the prompt, streams the answer and records the tokens. The model sees the same final prompt whichever class you pick.
Use any OpenAI-compatible model
OpenAIModelCall sends each request to any OpenAI-compatible chat endpoint. Give it to the adapter for your framework.
- The library fills the prompt’s
{{placeholders}}fromstate, then sends it. - Pass
base_url=andapi_key=to reach another OpenAI-compatible endpoint. - It needs the
openaipackage, which comes with theslngextra and with Pipecat.
UnmuteAgent, give the call to the agent’s spec instead: AgentSpec(PROMPT, model=model). Build it per call: the agent closes it when the call ends.
Use your own framework LLM
On LiveKit,LiveKitModel wraps any LLM plugin. The library fills the prompt, and the plugin keeps its own client, settings and retries.
AgentSpec as its model, or to a FallbackModelCall. On Pipecat, pass a native LLM service, like OpenAILLMService, to UnmuteFlows as it is. UnmuteFlows fills its prompts. See LiveKit and Pipecat.
Use the Context Router
RouterModelCall sends the prompt unfilled to the SLNG Context Router, which fills it and picks the model. See Use the Context Router.
Fall back to another model
FallbackModelCall tries several calls in order. It is a ModelCall too, so the adapter takes it as it is.
- It moves to the next call when one fails before it answers. It never moves on once the caller has part of the answer, so no sentence is said twice.
- Errors every model would give, like 400, 401 or 422, stop the chain at once.
- A rate limit with a short
Retry-Afterwaits on the same model, then fails over.
Write your own ModelCall
Any class with an asyncstream(request) method is a ModelCall. This one answers from the last user message:
ModelCallLLM(Echo()) on LiveKit or ModelCallLLMService(Echo()) on Pipecat.
- Call
fill_messageswithrequest.variables, as above, unless a router fills the prompt for you. - Yield
TextDeltaandToolCallevents. Yield aUsagelast when you know the token counts. - Raise the error of a failed request.
FallbackModelCallreads its status and code from it.
Read a whole answer
For a side request, like a summary, read the whole answer at once withcollect:
Where to go next
Model call reference
ModelRequest, events, placeholders, every FallbackModelCall argument and Gemini.
SLNG and the Context Router
RouterModelCall, SLNG speech and your own router config.
Hooks
Change or wrap a model request with your own code.
Realtime models
Models that hear and speak over one connection.