Tracing Ollama models with self-hosted Langfuse: the method and what it captures
The supported method for tracing local Ollama models in a self-hosted Langfuse is to point the Langfuse OpenAI client at Ollama's OpenAI-compatible endpoint, ` The same approach works through the Langfuse JS/TS SDK and the LangChain and LlamaIndex integrations, so the choice depends on the language and framework your team already uses rather than on the model runtime. Ollama's local API needs no authentication, so the application only needs to set the base URL for Ollama and the keys and host for your Langfuse instance. Confirm the exact configuration keys against the Langfuse Ollama integration page before you write the code, because the client setup is the part of this method most likely to change between SDK versions.
Once the client is wrapped, each call to a local model is recorded as a generation. Expect the trace to hold the request input, the model response, the model name as reported by Ollama, and token usage where the endpoint returns it. Those fields make it possible to compare latency and output across models and prompts, and to see which application or user generated a call when you add user and session attributes. Verify the capture with a few test calls before you rely on it: open the trace in your self-hosted Langfuse and check that the model name, input and output match what you sent, and that token counts appear. If any field is missing, confirm it with the Ollama version you run, since Ollama ships frequent releases and its OpenAI compatibility layer can change.
Cost is the part that depends on your configuration. Ollama runs models on your own hardware, so there is no per-token charge from Ollama itself, and Langfuse will not calculate a spend figure for a local model unless you define a price for it. Token counts are captured as usage, but the cost view stays empty or misleading until you add a model definition with the prices you choose, which for self-hosted models is an internal accounting decision. Agree with finance or the platform owner what a local token should be priced at, record that definition in Langfuse, and note that it reflects your hardware and power costs rather than a vendor invoice.
What you need before connecting Ollama to Langfuse
Tracing a local Ollama model takes four pieces working together: a self-hosted Langfuse instance with project keys, an Ollama runtime with the model already pulled, the Langfuse OpenAI client in the application, and a network path between the app host and the Langfuse host. Confirm each one before you write any instrumentation code, so a missing key or blocked port does not look like a tracing bug.
Self-hosted Langfuse instance and keys
Langfuse must be reachable at a host you control, and the project must have a public and secret key pair created in its settings. The application uses these keys to send traces, so the public key and secret key belong in your secret store, not in source files. Confirm the Langfuse version you plan to run against the current releases page before you pin it, because the upgrade path and SDK minimums depend on the version. Check the host URL and keys with a test trace before you instrument the application.
Langfuse releasesOllama runtime with the model pulled
Ollama is MIT licensed and runs on macOS, Windows, Linux and Docker, so the runtime can sit on a laptop, a workstation or a container host. The model must already be downloaded to the machine where Ollama runs, because the tracing client does not pull models for you. Record the exact model tag you will use, since that tag is what appears on each trace and drives your cost mapping later.
Ollama repositoryOllama API exposure and access
By default Ollama binds to 127.0.0.1 on port 11434, and its local API does not require authentication. That is acceptable for a single developer machine but not for a shared host. If the app host and the Ollama host differ, you must change the bind address with the OLLAMA_HOST environment variable and place the endpoint behind a proxy with access controls, such as Nginx, because anyone who can reach the port can call the models.
Ollama FAQLangfuse OpenAI client in the application
The application needs the Langfuse OpenAI client, which wraps the OpenAI SDK and sends each call to your Langfuse host. Point its base URL at Ollama's OpenAI-compatible endpoint, which listens on port 11434 under the /v1 path. Install the client in the same environment as the application and confirm the library version against the Langfuse integration documentation before you deploy.
Langfuse Ollama docsNetwork paths between hosts
Two separate connections must work: the application host must reach the Langfuse host over HTTPS, and the application host must reach the Ollama endpoint on port 11434. Many failures come from one of these paths being blocked by a firewall, a container network or a proxy rule. Test each path from the application host with a simple request before debugging traces, and keep the Langfuse host reachable only from the networks that need it.
How to configure the Langfuse OpenAI client for Ollama
This sequence connects a self-hosted Langfuse instance to a local Ollama server through the Langfuse OpenAI client, so each completion produces a trace with the model name and token usage. The result is a verified trace in your own Langfuse project, created by a test call you run yourself.
Confirm the self-hosted Langfuse instance is running
Your platform or operations team confirms that the self-hosted Langfuse web application is reachable from the machine where you will run the test, and that you can sign in to the UI. Record the base host URL your SDK will use. The step is done when the Langfuse UI loads over the internal address you plan to use and you can open an organization and project. If the instance is not yet deployed, complete the deployment first, because every later step depends on that host.
Create project API keys in Langfuse
In the Langfuse project settings, create a new API key pair for the project that will receive the test traces. Store the public key and secret key in your secrets manager or local environment file, not in source control. The step is done when both keys are saved and the project shows the key pair in its settings list. Use a separate project for experiments if you want to keep local model traces apart from production data.
Install the Langfuse OpenAI client and Ollama
In a Python or JavaScript environment, install the Langfuse OpenAI drop-in client for your language and confirm Ollama is installed and running on the host. Pull at least one model you intend to test with the Ollama command line. The step is done when the Langfuse client package imports without error and Ollama lists the model in its local model list. Check the Langfuse Ollama integration page for the current package names and versions.
Point the client at Ollama's OpenAI-compatible endpoint
Set the client base URL to Ollama's OpenAI-compatible path, which is for a server on the same machine. Set the API key to a placeholder such as ollama, because the local endpoint does not check keys. Set the Langfuse host, public key and secret key as environment variables so the client sends traces to your self-hosted instance and not to Langfuse Cloud. The step is done when the configuration loads without errors and the Langfuse host value points to your own domain. If Ollama must listen on another interface, set OLLAMA_HOST on the Ollama server (default 127.0.0.1:11434) and point the base URL at that address, keeping the endpoint restricted to trusted networks.
Run a test chat completion
Send one short chat completion through the Langfuse OpenAI client to a model you pulled in Ollama, using the model name exactly as Ollama lists it. Keep the prompt harmless and short, and do not send real customer data during the first test. The step is done when the call returns a response in your terminal or application log. If the call fails with a connection error, confirm that the Ollama service is listening on the address you configured. If it fails with a model error, confirm the model name matches the local list.
Flush the client and confirm the trace in Langfuse
Call the client flush method if your language requires it so buffered events are sent before the script exits. Open the Langfuse project in the UI, go to the traces view, and find the new trace. The step is done when the trace shows the Ollama model name you called, the input and output, and token usage counts for the prompt and completion. If the trace is missing, check the host value, the key pair and the project the keys belong to.
Check token usage and model name against the model list
Open the generation observation inside the trace and compare the recorded model name with the model you pulled. Confirm the token counts are present and plausible for the prompt length. Note that local models have no per-token provider price, so cost fields are empty unless you define model pricing in Langfuse for your local model names. The step is done when the model name matches, the token counts are populated, and you have recorded whether cost is blank or set. Confirm with your cost tracking owner how local model pricing should be defined before reporting spend.
How token counts and model pricing work for local models
Local Ollama models cost nothing per token in Langfuse unless you define a price for them. Ollama's pricing page states that running models on your own hardware is always unlimited, so the spend you pay for a local model is the hardware, power and operations your team already carries, not a per-token charge. Paid Ollama plans cover cloud models, which are a separate cost and a separate model name. Langfuse computes cost only when it has a price for the model name on the trace. A call to a local model such as llama3.2 therefore shows token counts but an empty cost field until you add a model definition with input and output prices that you choose. Decide before rollout whether those prices are internal chargeback rates, a notional cost per million tokens based on your hardware, or zero, and document which one you used so dashboards are not read as vendor invoices.
Token counts come from whatever Ollama returns through its OpenAI-compatible endpoint at not from a Langfuse calculation. The Langfuse OpenAI client reads the usage` object in the response, so a missing or zero prompt or completion count shows up as missing usage in the UI and in the Metrics API. Confirm the exact fields your Ollama version returns for streaming and non-streaming calls, and for each model you plan to use, before you trust any figure. Also confirm the model name recorded on the generation matches the name in your Langfuse model definition, because a mismatch silently drops cost.
Run one test trace per model and check the generation in the Langfuse UI: prompt tokens, completion tokens, total tokens and the cost field. If a count is absent, fix the client or the model name before building dashboards, since spend reports built on missing usage will undercount quietly. Keep the test trace and the model definition under change control, so a later Ollama upgrade that alters the usage fields is caught by the same check.
How a traced Ollama request flows through the stack
The trace starts in the application, which calls Ollama's OpenAI-compatible /v1 endpoint through the Langfuse OpenAI client. Ollama answers on the same host by default, or through a proxied internal address if you expose it. The Langfuse client then sends the trace event to the self-hosted Langfuse Web container, which hands processing to the Worker, and the data lands in PostgreSQL, ClickHouse and blob storage. Check each trust boundary: local Ollama needs no authentication, so the path between the app host and Ollama host is the one to lock down.
Request and trace paths across the app, Ollama and Langfuse hosts.
Where the Ollama endpoint runs and how it changes the setup
On a laptop, Ollama usually runs on the same machine as the application and the Langfuse client. Ollama binds to 127.0.0.1 on port 11434 by default, so the endpoint stays on the local machine and needs no extra configuration. This is the simplest environment for checking that the Langfuse OpenAI client reaches Ollama's OpenAI-compatible endpoint and that traces arrive in your self-hosted Langfuse.
- Base URL: ` for the OpenAI-compatible endpoint.
- OLLAMA_HOST change: none needed when the application runs on the same machine as Ollama.
- Main risk: a developer sets
OLLAMA_HOSTto0.0.0.0to test from another device and forgets to revert it, which exposes the local API to the network without authentication. - Langfuse placement: a self-hosted Langfuse on the same laptop is a test setup, since the documented Docker Compose path runs on a single VM without high availability.
- Model storage: models sit in the default Ollama model directory, so disk use grows on the laptop and can be moved with
OLLAMA_MODELS.
Before sharing the base URL with a teammate, confirm which address and port Ollama listens on using your operating system's network tools.
A team often runs one Ollama host with more compute and points several applications at it. Ollama does not provide built-in authentication for remote access, so the server should sit behind a reverse proxy such as Nginx, as the Ollama FAQ describes. The proxy then controls who can reach the endpoint, while Ollama itself listens only on an address the proxy can reach.
- Base URL: an internal HTTPS name served by the proxy, for example ` (illustrative hostname).
- OLLAMA_HOST change: bind Ollama to a loopback or private address and port, such as
127.0.0.1:11434, so clients cannot bypass the proxy. - Proxy controls: TLS, client authentication, network allow lists or an identity-aware gateway. Confirm each control against your proxy's documentation.
- Main risk: a proxy route that forwards to the unauthenticated Ollama API, letting any reachable client run models and use the host's resources. Set
OLLAMA_NO_CLOUD=1if the server must stay local-only. - Shared queueing:
OLLAMA_NUM_PARALLELdefaults to 1 per model andOLLAMA_MAX_QUEUEdefaults to 512 queued requests, so heavy shared use shows up as trace latency.
From a machine outside the proxy's allowed network, send an unauthenticated request and confirm it is refused.
A containerized application has its own network namespace, so localhost inside the container resolves to the container, not to the Ollama host. The application needs the host's address as seen from the container network, and Ollama must listen on an interface that the container can reach. The exact host address and name resolution depend on your container runtime and orchestration, so confirm them on your platform before configuring the client.
- Base URL:
http://<host-address>:11434/v1, where the host address is the one your runtime provides to containers (confirm for your runtime). - OLLAMA_HOST change: bind Ollama to the bridge or host interface that the container uses, and keep the binding as narrow as the container network allows.
- Langfuse reachability: the Langfuse host in the container configuration must also resolve from inside the container, which in Compose usually means the service name on the shared network.
- Main risk: widening the binding to every interface to make the container work, or a misconfigured address that fails in a way that looks like a model error.
- Kubernetes: service objects and network policies control egress from application pods, so the policy must allow traffic to the Ollama endpoint.
From inside the container, request the model list from the OpenAI-compatible endpoint before you wire the Langfuse client into the application.
Which Ollama and Langfuse fields map to each other
This table compares what Ollama returns for a local model call with the Langfuse trace, observation and generation fields that store it. Read the middle column for what the OpenAI-compatible client captures on its own and the last column for what your application must add, then confirm exact field names against the Langfuse Ollama documentation for the version you run.
| Data item | Where it lands in Langfuse | Set by | Notes |
|---|---|---|---|
| Model name | Generation model field | Client | Use the exact Ollama model tag, such as the name you pulled locally, so pricing lookups can match |
| Input messages | Generation input | Client | Chat messages sent to the /v1 endpoint are captured as the prompt; check redaction settings before sending sensitive text |
| Output messages | Generation output | Client | Completion text returned by Ollama; streaming responses depend on client wrapper support |
| Token usage | Generation usage (input and output tokens) | Client | Ollama reports token counts through the OpenAI-compatible response; confirm they appear for your model and version |
| Model pricing and cost | Generation cost fields | Application or Langfuse model config | Local models have no vendor price, so define a custom model price or leave cost unset and report tokens only |
| Latency | Observation start and end times | Client | Derived from call timing around the request; a slow model load can inflate the first request |
| User identifier | Trace user ID | Application | Pass a stable, pseudonymous ID per user if you need per-user reporting |
| Session identifier | Trace session ID | Application | Group related turns of one conversation so they appear together in the session view |
| Environment or application name | Trace metadata or environment tag | Application | Set one value per deployment, such as dev or prod, so local tests do not mix with production data |
Security settings for Ollama traces in your infrastructure
A self-hosted trace pipeline is only as private as its weakest link. The Ollama runtime, the path from applications to Langfuse, and the content of each trace all need deliberate settings. The cards below cover what to lock down, what to confirm, and where prompt content needs a decision before it reaches storage.
Keep Ollama bound to loopback
Ollama binds to 127.0.0.1 on port 11434 by default, and its local API does not require authentication. Leave that default in place unless a reverse proxy with access control sits in front of it. If you change the bind address with OLLAMA_HOST, confirm which hosts can reach the port and test it from a machine outside the allowed network. Any client that reaches the port can send inference requests without credentials.
Turn off cloud features
Local inference and cloud inference are different paths. Direct cloud calls to ollama.com require an API key sent as a Bearer token. Set OLLAMA_NO_CLOUD=1 or the equivalent in the server configuration file so that the runtime does not use cloud features, then check that the traces you receive come from local models only. Record the setting in your deployment configuration so that a later change is visible in review.
Protect Langfuse project keys as secrets
Each application that sends traces to Langfuse uses a public and secret key pair from a Langfuse project. Store them in your secrets manager or environment injection, not in source control or shared notebooks. Scope keys to the project that should receive the traces, and plan a rotation step for when someone leaves the team or a key appears in logs. Confirm how your Langfuse instance handles key creation and access under your current role setup.
Decide what prompts and completions store
Traces usually contain full prompts, completions and any personal data users typed into them. Decide per application whether to capture full content, metadata only, or a reduced form before the data reaches Langfuse. Test with a sample prompt that contains a fake identifier and check where it appears in the trace. Write the decision down so that developers adding new applications follow the same rule.
License key docsConfirm masking and retention need an Enterprise key
Server-side data masking and data retention policies in self-hosted Langfuse are listed among features that need an Enterprise license key. If your review requires masking that is enforced on the server rather than in your application code, plan for that license or mask in the application before sending. Confirm the current feature list against the license key documentation before you rely on it in a security review.
License key docsOllama runs locally without exposing prompts
Ollama states that when it runs locally it does not see your prompts or data. That statement covers the runtime, not your trace store. Prompts still leave the Ollama process when your application sends traces to Langfuse, so the data path that matters is application to Langfuse, and the Langfuse databases and blob storage in your infrastructure. Document both paths in your data flow diagram for the review.
Why traces from Ollama are missing or incomplete
This table lists the failures teams hit most often when Ollama calls should appear in self-hosted Langfuse, with the cause and fix for each. Check the rows in order: connectivity and configuration problems stop all traces, while cost and token gaps only affect how complete a trace looks.
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection refused from the app | Ollama binds to 127.0.0.1 on port 11434 by default, so a container or remote host cannot reach it | Set OLLAMA_HOST to an address the calling host can reach, or expose Ollama through a reverse proxy you control, then test from the app host |
| 404 or unknown route errors | Base URL missing the /v1 path, so the OpenAI client calls the wrong route | Use as the base URL for the Langfuse OpenAI client, and confirm the route with a single test request |
| Traces appear without cost | No price exists in Langfuse for the local model name, so cost cannot be calculated | Add a custom model definition with the exact model name Ollama reports, and set prices to zero or your own internal rate |
| Token counts missing on streamed responses | Streaming responses did not return usage data to the client wrapper, so counts were not recorded | Confirm the Langfuse wrapper version and streaming options, then compare one streamed and one non-streamed call in the trace view |
| Traces land in the wrong project | The public and secret keys belong to a different project or to another Langfuse host | Copy keys from the target project settings, confirm the host URL, and compare the project ID shown in the trace link |
| Langfuse not reachable from the app host | Network rules, DNS or the wrong host URL block the connection to your self-hosted Langfuse | Test the Langfuse host from the app host with a simple HTTP request, then check proxy settings, firewall rules and certificate trust |
| Requests queued or slow, traces delayed | OLLAMA_NUM_PARALLEL defaults to 1 per model, and OLLAMA_MAX_QUEUE limits how many requests wait | Raise OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE only after checking memory and hardware, and watch latency in the trace timestamps |
Questions teams ask before connecting Ollama to Langfuse
Does the open source version of Langfuse cost anything to trace Ollama?
The MIT-licensed open source version includes core tracing, prompt management and evaluations without license limits, so connecting Ollama to it does not require an Enterprise license key. Langfuse states that all core features and APIs are available in that version without limits. Enterprise features such as project-level RBAC roles, audit logs, data retention policies and SCIM provisioning need an Enterprise license key and a custom-priced Self-Hosted Enterprise plan. Your costs are the infrastructure you run for Langfuse (its web and worker containers, PostgreSQL, ClickHouse, Redis or Valkey and blob storage) and the people who set it up. Ask any provider to separate those infrastructure and labor costs in the quote, and confirm which Enterprise features your team actually needs before you buy a plan.
Do local Ollama models have usage fees?
Running models on your own hardware through Ollama is unlimited according to Ollama's pricing page, so local inference carries no per-token fee from Ollama. Fees apply only to the paid cloud plans: Pro at $20 per month ($200 per year), Max at $100 per month, Team at $500 per month and Enterprise at custom pricing, as listed on Ollama's pricing page. Those plans cover cloud model use, not your own hardware. If your applications route some requests to cloud models or to ollama.com, those requests are billed under the cloud plan and should be tracked separately in Langfuse. Check the current pricing page before budgeting, because plan terms can change.
How long does a basic Ollama to Langfuse connection take to verify?
A single application pointed at one Ollama host and one Langfuse project can usually be verified within a short working session once Langfuse and Ollama are both running and reachable. The steps are to set the Langfuse keys and host, point the Langfuse OpenAI client at Ollama's OpenAI-compatible endpoint at send one test request and confirm that the trace, input, output and token counts appear in the Langfuse UI. Duration grows with the number of applications, the number of Ollama hosts, the framework in use and whether a reverse proxy sits in front of Ollama. We do not publish a fixed duration, so ask for a timeline based on your written scope and environment.
What does my team need to provide before the work starts?
You need a running self-hosted Langfuse instance with a project and API keys, at least one Ollama host with the models you plan to trace pulled, and access to the application code that calls the model. You also need network access from the applications to Langfuse and from the applications to Ollama, plus a named owner for the Langfuse deployment. Typical inputs include:
- The Langfuse host URL and project keys for each environment
- The Ollama host addresses, the models in use and where they are stored
- Repository access and a list of applications or services that call Ollama
- Decisions on who may view traces, since prompts and outputs will be stored in Langfuse
Can one in-house engineer connect Ollama to Langfuse alone?
A single engineer who already runs Langfuse and has access to the application code can usually connect one application on their own, because the change is a client import and a base URL setting. The harder part is the surrounding work: deciding where Langfuse runs, keeping its data stores healthy, and agreeing on who can see prompt and response data. Those tasks often need an operations owner and a security reviewer. If the Langfuse instance does not exist yet, or several teams will send traces, plan for more people. A partner can take on that scope under a written agreement if your team lacks the capacity.
Does Ollama need authentication when Langfuse connects to it?
The local Ollama API at localhost:11434 does not require authentication, and Ollama binds to 127.0.0.1 by default, so an application on the same machine can call it without a key. Once you change the bind address with the OLLAMA_HOST environment variable or expose Ollama through a proxy such as Nginx, anyone who can reach that address can use the models. Put authentication, network restrictions and TLS in front of any shared Ollama host. Direct calls to ollama.com/api and ollama.com/v1 instead require an API key sent as a Bearer token. Confirm the current authentication behavior in Ollama's API documentation for your version.
How does effort change with proxies, multiple applications and custom pricing?
Effort rises in three main ways. A proxy in front of Ollama adds routing, authentication and TLS work, and it must allow the trace path to reach Langfuse. Each additional application adds a code change, testing and a check that user and session attributes are captured consistently. Custom pricing for models you host yourself, or an Enterprise plan with model access controls and cost budgets, adds configuration and a commercial review. Each of these drivers changes the scope, so ask any provider for a fixed-scope quote that lists the hosts, applications, proxies and pricing setup it covers.
What should we check after the first trace appears?
Confirm that the trace shows the expected model name, input and output, latency, and token counts for each request. Then check that the model pricing you configure in Langfuse matches the model in use, because local models have no vendor price and cost figures depend on what you enter. Also confirm that traces from each environment land in the right project, that prompt and response data is visible only to the roles you intend, and that the Ollama host and Langfuse instance are still reachable after a restart. Record these checks so the next application can follow the same steps.
When a dedicated engineering pass on the Ollama trace setup pays off
A dedicated engineering pass pays off once the trace setup stops being one developer's laptop script and becomes shared infrastructure. The clearest signals are several applications and hosts sending traces to one self-hosted Langfuse, Ollama servers shared by multiple teams and placed behind a proxy such as Nginx (the Ollama FAQ describes exposing the server this way, and binding it away from 127.0.0.1 through OLLAMA_HOST changes who can reach it), and a need to show auditors where each trace was produced. At that point the work is less about one OpenAI client call and more about endpoint routing, credential handling per application, and whether the proxy layer preserves the requests the SDK sends.
Governance is the second trigger. Prompts stored in Langfuse, and the traces that contain them, may hold personal or confidential data, so the team needs decisions about who can edit prompts, which environments see which traces and how long data is kept. Several of these controls, including project-level RBAC roles, data retention policies and audit logs, need an Enterprise license key on self-hosted Langfuse, so confirm that licensing question before the design is fixed. Pricing for private models is the third trigger: Ollama models run on your hardware carry no per-token vendor price, so cost tracking depends on custom model prices you define in Langfuse. Someone must own those prices, their units and their updates when a model is replaced.
Before a scoping call, prepare a short inventory: each application and host that will send traces, the Ollama versions and hosts in use, the proxy or gateway in front of them, the SSO provider you expect to use, the data classes that will appear in prompts and completions, and your retention expectations. Name who approves prompt changes and who owns model pricing. Ask the partner to state in writing what the scope covers and what it leaves to your team. Nothing here guarantees a particular outcome; it gives the scoping conversation enough detail to produce a fixed-scope quote.
How DeployOpen works on this
DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure. For Ollama and Langfuse tracing, we start from the models your teams run, the hosts they run on, and the Langfuse instance that will receive the traces, then build and hand over a tracing setup your engineers can operate.
How we scope
- Inventory which Ollama hosts, models and applications will send traces, and where each one runs.
- Confirm the self-hosted Langfuse instance, its host address and the project and key structure for each team.
- Agree in writing which token counts, model pricing entries and user or session attributes are in scope.
How we build
- Point the Langfuse OpenAI client at the Ollama OpenAI-compatible endpoint, starting from the local address and port 11434.
- Check that token usage and cost fields appear correctly for each local model, and set custom model prices where needed.
- Test Ollama's bind address, reverse proxy and network path so traces reach Langfuse without exposing the runtime.
How we hand over
- Document the client configuration, environment variables, key rotation steps and the model pricing mapping.
- Deliver a verification checklist showing traces, token counts and costs for each supported model and application.
- Walk your engineers through the setup so they can add new models and applications on their own.
How we support
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
- Ongoing support is available as a retainer for Langfuse upgrades, Ollama version changes and new models.
- Ask for a quote built from the written scope, since DeployOpen does not publish a price list.

