Raw HTTP / non-OTel clients

Record spans for LLM clients that are not auto-instrumented, using trackLlmCall and a raw tracer.

When your LLM client isn't one Trodo auto-instruments and you can't wrap it as a function, record the call after the fact. This covers raw fetch/httpx to a self-hosted endpoint (Ollama, vLLM) or any provider Trodo doesn't yet support.

When to use it

Use this only when manual spans don't fit, for example you already made the HTTP call and just want it on the run. For supported providers, prefer Frameworks; for your own functions, prefer the llm helper.

Record an LLM call you already made

trackLlmCall adds an LLM span to the current run from a response you already have. It must run inside a wrapAgent (or joinRun) callback; outside a run it's a no-op.

const resp = await fetch('http://ollama.internal/api/chat', {
  method: 'POST',
  body: JSON.stringify({ model: 'llama3.1:70b', messages }),
}).then((r) => r.json());

await trodo.trackLlmCall({
  model: resp.model,
  provider: 'ollama',
  inputTokens: resp.prompt_eval_count,
  outputTokens: resp.eval_count,
  prompt: messages,
  completion: resp,
  metadata: { endpoint: '/api/chat' },
});
resp = httpx.post(url, json=body).json()

trodo.track_llm_call(
    model='gemini-2.5-flash',
    provider='google',
    input_tokens=resp['usageMetadata']['promptTokenCount'],
    output_tokens=resp['usageMetadata']['candidatesTokenCount'],
    prompt=body,
    completion=resp,
)

Cost is computed server-side from (provider, model). Pass cost explicitly to override the pricing table (negotiated rates, self-hosted zero-cost). See Pricing.

For full control, get a raw OpenTelemetry tracer. The Trodo span processor is already subscribed, so any span you start is captured.

const tracer = trodo.getTracer('my.module');

tracer.startActiveSpan('custom', (span) => {
  span.setAttribute('gen_ai.system', 'my-llm');
  span.end();
});
tracer = trodo.get_tracer('my.module')

with tracer.start_as_current_span('custom') as span:
    span.set_attribute('gen_ai.system', 'my-llm')

Next

On this page