Bring Your Own Model
For privacy, cost control, or specialized models, you can run LLMs locally or on your own servers. The OpenAIClient works with any endpoint that implements the OpenAI chat completions API.
A localhost base URL (like the Ollama, vLLM, and LM Studio examples below) only
works when you run the crew locally (python server.py + smallestai agent-crew chat).
A deployed crew runs in the cloud and cannot reach localhost on your machine.
For a deployed agent, point base_url at a host the cloud can reach: a public
inference endpoint, or your local server exposed through a tunnel. For Ollama over a
tunnel, rewrite the Host header or Ollama returns 403:
ngrok http 11434 --host-header=localhost:11434, then set
base_url="https://<id>.ngrok-free.app/v1".
Tunnels are for development only. If the local process behind the tunnel
goes down (Ollama exit, laptop sleep), the tunnel returns ERR_NGROK_8012
and the agent surfaces it as a fatal agent_error and hangs up mid-call.
Move to a hosted OpenAI-compatible endpoint before shipping.
Do not point base_url at Anthropic’s OpenAI-compatible endpoint
(https://api.anthropic.com/v1/) for a crew agent. It truncates
streaming replies and drops tool-call turns, which surfaces as the
agent going silent mid-conversation. If you want Claude for a crew,
route it through a gateway that stabilizes the stream (LiteLLM,
OpenRouter, Portkey), use a real OpenAI-backed model, or use the
platform model. Anthropic’s native SDK is unaffected. Only their
OpenAI-compat URL has this issue.
Complete Example
Here’s a full agent using a local Ollama model:
Requirements
Your model server must implement the OpenAI Chat Completions API:
Custom Endpoints
Connect to any custom model server:
Ollama
Ollama is the easiest way to run models locally. It handles model downloads and serving automatically.
Setup
Usage
vLLM
vLLM is a high-performance inference server for production workloads.
Setup
Usage
LM Studio
LM Studio provides a desktop UI for running models locally.
- Download from lmstudio.ai
- Load a model
- Start the local server (Settings → Local Server)
Deterministic tool calls with tool_choice
Crew OpenAIClient.chat() forwards extra kwargs to the underlying request, so any OpenAI-compatible tool_choice value works. Passing tool_choice="required" on a specific turn forces the model to emit a tool call rather than a free-text answer. Useful when the model has already said “let me transfer you” out loud but does not actually invoke the transfer tool.
Set tool_choice="required" only for the specific transfer or handoff turn, not on every turn. Forcing tools on normal conversational turns will cause the model to invent tool calls when the user is just chatting.
Troubleshooting
Tips
Use local LLMs for development, Cloud/Managed LLM providers for production
Ollama is great for local development. For production, consider vLLM or a cloud provider for reliability.
Set up a fallback LLM
Local models can fail. Configure a cloud fallback (e.g., OpenAI) to catch errors and keep the conversation going.
Check tool calling support
Not all local models support function calling. Test your tools or use a model known to support them.

