Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Ollama

Trace models served by Ollama with cetra from Python, with the OpenInference Ollama instrumentation.

Terminal window
pip install "cetra-sdk[ollama]" ollama
import ollama
import cetra
cetra.init(instrument=["ollama"])
response = ollama.chat(
model="llama3.1",
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response.message.content)
cetra.flush()
  • Each chat call is an llm span with the provider ollama.
  • Input and output token counts come from the response.
  • Cost comes from the built-in prices.
  • Only non-streaming chat is captured.
  • Through the OpenAI client on localhost, the provider stays openai: cetra cannot tell a local server from another.
  • Common Ollama models are in the built-in prices at 0; add a custom model price for others.
  • The fixtures were captured with ollama 0.6.3 and openinference-instrumentation-ollama 0.1.20.
  • If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.