Tracciare e monitorare le chiamate LLM
Acquisisca token, latenza e costo per richiesta.
Tracciare e monitorare le chiamate LLM è una lezione MLOps Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento MLOps Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso MLOps Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
You Cannot Fix What You Cannot See
An LLM app feels like a black box until you log what it does. Tracing records each call so you can debug, cost, and improve it later. 🔍
Capture the Request
For every call, log the final prompt, the model name, and key parameters. This request record lets you reproduce any answer exactly.
log.info({"model": "gpt-4o", "prompt": prompt, "temperature": 0.2})Capture the Response
Save the generated text alongside the request. Together the input and output form one trace you can replay, score, or share with a teammate.
Record Token Usage
Each response reports tokens in and out. Logging tokens per call is how you attribute cost and spot prompts that quietly grew too large.
usage = response.usage
log.info({"in": usage.input_tokens, "out": usage.output_tokens})Turn Tokens Into Cost
Multiply token counts by the price per token to get spend. Tracking cost per request keeps a runaway feature from surprising you on the bill.
cost = inp / 1e6 * 2.50 + out / 1e6 * 10.00Measure Latency
Time each call from send to final token. Watching latency per request reveals slow prompts and tells you when streaming would help users.
start = time.perf_counter()
response = client.responses.create(...)
latency = time.perf_counter() - startSpans Build a Trace
A real request may chain retrieval, the LLM, and a tool. Each step is a span, and nesting them into one trace shows where time and tokens go.
Tools Built for LLMs
Platforms like LangSmith, Langfuse, and Phoenix capture traces with one wrapper. A purpose-built observability tool beats parsing raw logs by hand.
from langfuse.openai import openai
response = openai.responses.create(model="gpt-4o", input=prompt)Tag Traces With Metadata
Attach a user id, prompt version, and feature name to each trace. This metadata lets you slice metrics and find which segment is misbehaving.
Sample What You Cannot Store
At high volume, logging every full payload is costly. Sampling a fraction of traces keeps insight while controlling storage and privacy.
Dashboards and Alerts
Roll traces into dashboards for cost, latency, and error rate, then alert on spikes. Now production problems reach you before users complain.
Quick Check
Your monthly LLM bill jumped with no traffic change. Which logged value explains it fastest?
Recap
You can now trace LLM calls end to end: request, response, tokens, cost, latency, and spans, then watch them on dashboards. Eyes wide open! 🎉
Domande Frequenti
La lezione «Tracciare e monitorare le chiamate LLM» è gratuita?
Sì — il testo completo di «Tracciare e monitorare le chiamate LLM» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso MLOps Academy, passa a CoddyKit PRO. Il corso MLOps Academy include 4 lezioni in totale.
Cosa imparerò in «Tracciare e monitorare le chiamate LLM»?
Acquisisca token, latenza e costo per richiesta. Eserciti MLOps Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare MLOps Academy?
Non è richiesta alcuna esperienza precedente. MLOps Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.
Quanto tempo richiede la lezione «Tracciare e monitorare le chiamate LLM»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione MLOps Academy?
Sì. Ogni lezione MLOps Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Come LLMOps differisce dal MLOps classico
- Versionare i prompt e valutare gli output
- Tracciare e monitorare le chiamate LLM
- Guardrail e valutazione RAG