Claude認定 対策ノート

講座 › 分野5 モデルの選択と最適化

5.4 コストとトークンの管理

配点 2.8%Cost and Token Management

使う前に数え、使った後に記録する。繰り返す先頭部分はキャッシュ、急がない大量処理はバッチで費用を下げる。

未読

送る前に数える

図解:送る前に数える

トークンの数え上げ(token counting)を使うと、Claudeに送る前にメッセージのトークン数を数えられます。流量の上限と費用の管理、どのモデルに送るかの判断、プロンプトを目標の長さに収めるのに使います。

出典:Token counting
Count the tokens in a message before you send it to Claude. Use token counts to manage rate limits and costs, make model routing decisions
https://platform.claude.com/docs/en/build-with-claude/token-counting.m…(取得 2026-11-17)

使った量を追跡する

図解:使った量を追跡する

Agent SDKは、やり取りごとの詳しいトークンの使用量を返します。ただし、SDKが示す費用の値は、手元の価格表から計算した見積もりで、正式な請求のデータではありません。正確な費用の管理には、請求側の情報と突き合わせます。

出典:Agent SDK cost tracking
The Claude Agent SDK provides detailed token usage information for each interaction with Claude.
https://code.claude.com/docs/en/agent-sdk/cost-tracking.md(取得 2026-11-17)
出典:Agent SDK cost tracking
fields are client-side estimates, not authoritative billing data
https://code.claude.com/docs/en/agent-sdk/cost-tracking.md(取得 2026-11-17)

キャッシュとチェックポイント

図解:キャッシュとチェックポイント

プロンプトキャッシュは、cache_control を付けた位置までの先頭部分を再利用します。区切り(ブレークポイント)は最大4つで、自動のキャッシュも1枠を使います。キャッシュの書き込みは通常の入力より高く(5分のもので1.25倍)、読み出しはずっと安くなります。何度も同じ先頭部分を送るほど得になります。

出典:Prompt caching
the automatic cache breakpoint uses one of the 4 available breakpoint slots
https://platform.claude.com/docs/en/build-with-claude/prompt-caching.m…(取得 2026-11-17)
出典:Prompt caching
Cache write tokens with a 5-minute TTL are 1.25 times the base input tokens price.
https://platform.claude.com/docs/en/build-with-claude/prompt-caching.m…(取得 2026-11-17)

費用のモデルを作る

図解:費用のモデルを作る

費用は、モデルごとの入力と出力のトークン単価に、キャッシュの書き込み・読み出しや、バッチの割引(半額)を組み合わせて見積もります。高速モードは割増の料金です。Claude Codeでは、/clear で関係のない履歴を切ると、毎回のメッセージで払う分を減らせます。

出典:Batch processing
cutting costs by 50 percent and increasing throughput
https://platform.claude.com/docs/en/build-with-claude/batch-processing…(取得 2026-11-17)
出典:Fast mode
Fast mode delivers up to 2.5x higher output tokens per second at premium pricing.
https://platform.claude.com/docs/en/build-with-claude/fast-mode.md(取得 2026-11-17)
出典:Claude Code best practices
it means the next task doesn't keep paying for the previous one's history
https://code.claude.com/docs/en/best-practices.md(取得 2026-11-17)
試験のポイント