Set up
Wrap an instance ofOllama from the ollama package. The SDK recognizes it automatically.
chat and generate are covered.
With the OpenAI client
Ollama also serves an API in OpenAI’s format. To call it with anOpenAI client, point the baseURL at Ollama and wrap it:
OpenAI client requires one, so pass any string. Calls through the OpenAI client are metered with the OpenAI recipe: they are reported under the openai.chat.completions.create and openai.responses.create event names, with the same metrics as OpenAI. See Ollama’s OpenAI compatibility docs.
What is reported
The responses of Ollama’s own API include the number of tokens each call processed. The wrapper reads them and reports them to Stigg as the metrics below. For details, see Ollama’s API docs.total_tokens includes the other two, so price the total or the parts, never both.
Other Ollama methods are not metered: embed measures a different kind of usage, and pull, push and create manage models rather than run them. Ollama’s webSearch and webFetch are billed by ollama.com but return no token counts, so they are not metered either.