LLM usage and cost
Spitfire reads the model calls your services make from the OpenTelemetry gen_ai.* spans they send: how many calls, how many tokens, what they cost, how fast the model answers and how often the provider refuses. It ties them to load testing: during a run you see the cost per 1,000 requests for each load step and the step where the model calls broke, and from the run you can work out what a month at a given traffic would cost. Menu: APM → Services → LLM usage & cost. APM must be on (APM).
What it reads
The OpenTelemetry GenAI conventions, with both the older and the newer attribute names:
| What | Attributes |
|---|---|
| Provider | gen_ai.provider.name, older gen_ai.system |
| Model | gen_ai.response.model, otherwise gen_ai.request.model |
| Operation | gen_ai.operation.name (chat, text_completion, embeddings, generate_content, execute_tool, invoke_agent) |
| Tokens | gen_ai.usage.input_tokens / gen_ai.usage.output_tokens, older gen_ai.usage.prompt_tokens / gen_ai.usage.completion_tokens |
| Tool, agent | gen_ai.tool.name, gen_ai.agent.name |
| Refusal | HTTP status 429, or an exception type that names a rate limit, too many requests, throttling or a quota |
The llm.* names of the OpenLLMetry and OpenInference instrumentations are read too. A model call is every operation other than a tool run (execute_tool) and an agent run (invoke_agent, create_agent); tool and agent rows count their runs, their tokens are already in the model calls they make.
Send model calls from Python (OpenAI)
The steps make a small example in ~/spitfire-llm-demo that sends one call; in your own service only steps 1 and 3 change (install the package into the service's environment, put the variables in its environment). Python 3.10 or later. https://<spitfire> and the key sfotlp_… come from Get the key.
Create the folder and the environment, and install the packages:
mkdir -p "$HOME/spitfire-llm-demo" python3 -m venv "$HOME/spitfire-llm-demo/.venv" "$HOME/spitfire-llm-demo/.venv/bin/pip" install openai opentelemetry-distro==0.66b2 opentelemetry-exporter-otlp-proto-http==1.45.2 opentelemetry-instrumentation-openai-v2==2.4b0Create the example application:
cat > "$HOME/spitfire-llm-demo/app.py" <<'EOF' from openai import OpenAI client = OpenAI() r = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "Say hello in five words."}], ) print(r.choices[0].message.content) EOFCreate the variables file (write your address and key in place of
<spitfire>andsfotlp_…):cat > "$HOME/spitfire-llm-demo/otel.env" <<'EOF' OTEL_SERVICE_NAME=llm-demo OTEL_RESOURCE_ATTRIBUTES=deployment.environment=dev OTEL_EXPORTER_OTLP_ENDPOINT=https://<spitfire>/otlp OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_EXPORTER_OTLP_HEADERS=authorization=sfotlp_… OTEL_TRACES_EXPORTER=otlp OTEL_LOGS_EXPORTER=otlp OTEL_METRICS_EXPORTER=none EOF chmod 600 "$HOME/spitfire-llm-demo/otel.env"Give the OpenAI key (it is not echoed and stays out of the shell history), then run the example:
read -rs OPENAI_API_KEY && export OPENAI_API_KEY set -a && . "$HOME/spitfire-llm-demo/otel.env" && set +a "$HOME/spitfire-llm-demo/.venv/bin/opentelemetry-instrument" "$HOME/spitfire-llm-demo/.venv/bin/python" "$HOME/spitfire-llm-demo/app.py"Open APM → Services → LLM usage & cost. Within a minute the call shows under the service
llm-demowith the modelgpt-4o-mini.
The prompts and answers are not sent by this instrumentation unless you set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true; Spitfire does not store them in any case (Prompts and answers).
Send model calls from Python (LangChain)
Python 3.11 or later. In a LangChain application use only the LangChain instrumentation: if the OpenAI instrumentation is in the same environment too, every call is counted twice.
Create the folder and the environment, and install the packages:
mkdir -p "$HOME/spitfire-llm-langchain" python3 -m venv "$HOME/spitfire-llm-langchain/.venv" "$HOME/spitfire-llm-langchain/.venv/bin/pip" install langchain-openai opentelemetry-distro==0.66b2 opentelemetry-exporter-otlp-proto-http==1.45.2 opentelemetry-instrumentation-langchain==0.63.1Create the example application:
cat > "$HOME/spitfire-llm-langchain/app.py" <<'EOF' from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-4o-mini") print(llm.invoke("Say hello in five words.").content) EOFCreate the variables file.
TRACELOOP_TRACE_CONTENT=falsestops this instrumentation from sending the prompts and answers, which it sends by default; Spitfire would drop them anyway, this keeps them off the network:cat > "$HOME/spitfire-llm-langchain/otel.env" <<'EOF' OTEL_SERVICE_NAME=llm-langchain OTEL_RESOURCE_ATTRIBUTES=deployment.environment=dev OTEL_EXPORTER_OTLP_ENDPOINT=https://<spitfire>/otlp OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_EXPORTER_OTLP_HEADERS=authorization=sfotlp_… OTEL_TRACES_EXPORTER=otlp OTEL_LOGS_EXPORTER=otlp OTEL_METRICS_EXPORTER=none TRACELOOP_TRACE_CONTENT=false EOF chmod 600 "$HOME/spitfire-llm-langchain/otel.env"Run it:
read -rs OPENAI_API_KEY && export OPENAI_API_KEY set -a && . "$HOME/spitfire-llm-langchain/otel.env" && set +a "$HOME/spitfire-llm-langchain/.venv/bin/opentelemetry-instrument" "$HOME/spitfire-llm-langchain/.venv/bin/python" "$HOME/spitfire-llm-langchain/app.py"The call shows under the service
llm-langchain.
Send model calls from Node.js
Node.js 18 or later. The automatic instrumentation package already contains the OpenAI instrumentation and turns it on by default.
Create the folder and install the packages:
mkdir -p "$HOME/spitfire-llm-node" npm --prefix "$HOME/spitfire-llm-node" install openai @opentelemetry/api @opentelemetry/auto-instrumentations-node@0.83.1Create the example application. It waits 8 seconds at the end so the span is sent before it exits:
cat > "$HOME/spitfire-llm-node/app.js" <<'EOF' const OpenAI = require('openai'); const client = new OpenAI(); client.chat.completions .create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: 'Say hello in five words.' }] }) .then((r) => console.log(r.choices[0].message.content)) .finally(() => setTimeout(() => {}, 8000)); EOFCreate the variables file:
cat > "$HOME/spitfire-llm-node/otel.env" <<'EOF' OTEL_SERVICE_NAME=llm-node OTEL_RESOURCE_ATTRIBUTES=deployment.environment=dev OTEL_EXPORTER_OTLP_ENDPOINT=https://<spitfire>/otlp OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_EXPORTER_OTLP_HEADERS=authorization=sfotlp_… OTEL_TRACES_EXPORTER=otlp OTEL_LOGS_EXPORTER=otlp OTEL_METRICS_EXPORTER=none EOF chmod 600 "$HOME/spitfire-llm-node/otel.env"Run it:
read -rs OPENAI_API_KEY && export OPENAI_API_KEY set -a && . "$HOME/spitfire-llm-node/otel.env" && set +a cd "$HOME/spitfire-llm-node" && node --require @opentelemetry/auto-instrumentations-node/register app.jsThe call shows under the service
llm-node.
For a service that already sends traces with the Node.js guide, nothing changes: the OpenAI calls show on this screen by themselves.
The screen
- Pick the range and, if needed, the environment. The service, provider and model boxes narrow the whole page; they stay in the address, so a shared link opens the same view.
- The tiles: the estimated cost (and per call), the model calls (and per minute), the tokens in and out, p95 (and p50), the failed calls and the refused ones (
429). - The four charts share one time axis: cost, tokens in and out, p95, failures and refusals.
- Where it goes switches between models, services, tools and agents; select a model or a service row to narrow the page to it.
- Single calls lists the costliest, the slowest and the failed calls; Trace opens the call inside its trace.
A model without a price has a dash in the cost column and a note above the charts with its tokens; add its price in the price list.
The screen reads a per-minute summary, not every span, so long ranges stay fast; the summary is deleted with the APM retention like the spans (Retention).
During a load test
When the tested services send model calls, the run's Backend tab gets the card LLM usage & cost during the run. Nothing needs to be set up: the calls in the run's time window, per load step.
| Column | Meaning |
|---|---|
| Requests/s | the test's measured requests a second in that step |
| Model calls, Tokens in / out, Cost | the model calls of the step |
| Per 1,000 requests | the step's model cost divided by the test's requests in the step, × 1,000 |
| p95, Errors, 429 | the model calls' p95, error share and refusals |
The red row is the step where the model calls broke: the first step with a 429 refusal, or (with at least 5 calls) errors at 5% or more, or p95 more than twice the first step's. The line above the table says which and by how much.
Runs with several services in the same time window add up their model calls. Run the test against a staging environment if production traffic would mix in.
What a month would cost
- In the run's Backend tab type the requests a minute you expect, or press Peak of the run or Last step that held.
- Spitfire counts a 30-day month from the run's model calls per request and tokens and cost per call, and shows the p95 of the load step nearest that traffic.
- A red line means the model calls broke at this traffic during the run; a yellow one that the traffic is above what the run reached (the p95 shown is then the highest step's, the real one can be worse).
The same box on the LLM usage & cost screen counts from model calls a minute and the period's per-call figures.
Price list
Costs are counted from the price list at the bottom of the screen, in USD per million tokens, input and output. The built-in prices are estimates from the providers' public list prices of November 2026; your contract or region may differ.
- Admins press Add price, or Edit on a row.
- Write the model name as the service reports it (e.g.
gpt-4o-mini). It also matches the dated versions (gpt-4o-mini-2024-07-18); the longest match wins. - Write the input and output prices, Save.
An own price replaces the estimate for this workspace; Remove brings the estimate back. Costs are counted when the page is read, so a new price also applies to past calls. The run card and the alerts use the same list.
Alerts
Press Add alert on the screen (admins). Pick the service (or all services), the environment, what to watch and the window:
| Watches | Unit |
|---|---|
| LLM cost | USD in the window |
| LLM tokens | tokens in and out in the window |
| LLM call p95 | ms; only from the Minimum calls in the window |
| LLM call error rate | %; only from the Minimum calls in the window |
| LLM calls refused (rate limit) | refusals in the window |
The window is 15 minutes to 24 hours. The alert goes to the channels you pick and shows in APM → Alerts like the others (APM alerts).
Prompts and answers
Spitfire never stores what the model was asked and answered: the messages, prompts and completions (gen_ai.input.messages, gen_ai.output.messages, the older gen_ai.prompt / gen_ai.completion, the llm.* equivalents), system instructions and tool arguments and results. When a service sends them, they are dropped on arrival, before anything is written, whatever the APM capture setting (capture and masking) says. A log record that carried only such content keeps the line [LLM content not stored].
What stays: the provider, the model, the tokens, the duration, the errors and refusals, the tool and agent names. That is everything this screen, the run card and the alerts need.
The content is often personal data, so it is better not to send it at all: leave OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT unset, set TRACELOOP_TRACE_CONTENT=false.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| The screen says there are no model calls | The service sends no gen_ai.* spans. Check that the instrumentation package is installed in the service's own environment and the service shows on APM → Services. |
| Calls but no cost | The model has no price: add it in the price list. |
| Every call counted twice | Two instrumentations on the same calls (e.g. LangChain and OpenAI). Keep one. |
| No card in the run's Backend tab | The tested services made no model calls in the run's window, or APM is off. |