LLM呼び出しを追跡・監視する
リクエストごとのトークン数、レイテンシー、コストを記録します。
「LLM呼び出しを追跡・監視する」はCoddyKit上の無料MLOps Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMLOps Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MLOps Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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! 🎉
よくある質問
「LLM呼び出しを追跡・監視する」レッスンは無料ですか?
はい。「LLM呼び出しを追跡・監視する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MLOps Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MLOps Academyコースには全4レッスンが含まれています。
「LLM呼び出しを追跡・監視する」で何を学びますか?
リクエストごとのトークン数、レイテンシー、コストを記録します。 ブラウザで直接実行するハンズオンコードでMLOps Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
MLOps Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMLOps Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「LLM呼び出しを追跡・監視する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMLOps Academyレッスンでコードを書いて実行できますか?
はい。すべてのMLOps Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- LLMOpsと従来のMLOpsの違い
- プロンプトをバージョン管理して出力を評価する
- LLM呼び出しを追跡・監視する
- ガードレールとRAG評価