はじめの
NTTテクノクロス株式会社の渡邉です。
表題の通りなのですが、この仕様を知らずに誤りを伝えたことがあり、反省を込めて整理します。
アプリケーション推論プロファイルとは?
Amazon Bedrockで提供されているClaude, LlamaとかDeepSeekなどの基盤モデルにはコスト配分タグを付けられません。そのため、標準的にAPIを使うと「利用者毎の費用分析」が困難です。
before
Client → AWS IAM → Bedrock(Foundation Model)
そこでBedrockでは「アプリケーション推論プロファイル」というリソース経由で基盤モデルを呼び出すことができます。
このプロファイルへコスト配分タグを紐づけることで、間接的に利用者(AWS IAM)毎の費用を追跡できるのです。
after
Client → AWS IAM → Bedrock(application inference profiles) → Bedrock(Foundation Model)
↑これにタグをつける
アプリケーション推論プロファイルはClaude Codeで使えるのか?
例えばClineでは、Enter the Application Inference Profile ARN
とあり、アプリケーション推論プロファイルに対応していることがわかります。
Claude Codeについては把握できていなかったのですが、Bedrock周りのドキュメントを見ると、どうやら使えそうです。
# Amazon Bedrock (推論プロファイルARNを使用)
ANTHROPIC_MODEL='arn:aws:bedrock:us-east-2:your-account-id:application-inference-profile/your-model-id'
ANTHROPIC_SMALL_FAST_MODEL='arn:aws:bedrock:us-east-2:your-account-id:application-inference-profile/your-small-model-id'
検証
マネジメントコンソールでは作れないので、アプリケーション推論プロファイルはCLIで作ります。
accountid=`aws sts get-caller-identity \
--query Account \
--output text`
aws bedrock create-inference-profile \
--inference-profile-name claude4sonnet-watany \
--model-source copyFrom=arn:aws:bedrock:us-west-2:${accountid}:inference-profile/us.anthropic.claude-sonnet-4-20250514-v1:0 \
--description "for watany"
Claude Codeを設定しましょう。
npm install -g @anthropic-ai/claude-code
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL='arn:aws:bedrock:us-east-2:123456789012:application-inference-profile/your-model-id'
# 今回はSmallモデル用のプロファイルは未作成のため省略
# ANTHROPIC_SMALL_FAST_MODEL='arn:aws:bedrock:us-east-2:your-account-id:application-inference-profile/your-small-model-id'
試してみた結果です。
# 前略
claude
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /workspaces/bedrock-temp-credential │
╰───────────────────────────────────────────────────╯
Tips for getting started:
1. Run /init to create a CLAUDE.md file with instructions for Claude
2. Use Claude to help with file analysis, editing, bash commands and git
3. Be as specific as you would with another engineer for the best results
4. ✔ Run /terminal-setup to set up terminal integration
> hello
● Hello! I'm here to help you with software engineering tasks. What would you like me to work on?
> /cost
⎿ Total cost: $0.0512
Total duration (API): 5.7s
Total duration (wall): 16.7s
Total code changes: 0 lines added, 0 lines removed
Token usage by model:
claude-3-5-haiku: 157 input, 17 output, 0 cache read, 0 cache write
claude-sonnet: 4 input, 26 output, 0 cache read, 13.5k cache write
> /model
⎿ Set model to arn:aws:bedrock:us-west-2:123456789012:application-inference-profile/nqb0wmzhvnkh
Total cost: $0.0518
Total duration (API): 9.1s
Total duration (wall): 48.8s
Total code changes: 0 lines added, 0 lines removed
Token usage by model:
claude-3-5-haiku: 581 input, 63 output, 0 cache read, 0 cache write
claude-sonnet: 4 input, 26 output, 0 cache read, 13.5k cache write
このように/model
コマンドから、アプリケーション推論プロファイルの設定の成功を確認できました。
Appendix.
Bedrock&アプリケーション推論プロファイルであっても、ローカルに/cost
の仕様トークン数は記録される様子なので、費用カウントはローカルでもある程度できそうです。企業で利用する際は「利用者側での確認」と「アカウント側の確認」を両立させることで、適切なトークンコストで扱えるでしょう。
余談ですが、ccusageというツールを使うと簡易に確認できて便利です。
/workspaces/bedrock-temp-credential (appprofile) $ npx ccusage
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
WARN Fetching latest model pricing from LiteLLM... ccusage 6:00:47 AM
ℹ Loaded pricing for 1100 models ccusage 6:00:47 AM
╭──────────────────────────────────────────╮
│ │
│ Claude Code Token Usage Report - Daily │
│ │
╰──────────────────────────────────────────╯
┌──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬────────────┐
│ Date │ Models │ Input │ Output │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼────────────┤
│ 2025-06-12 │ sonnet-4 │ 4 │ 1 │ 13,505 │ 0 │ 13,510 │ $0.05 │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼────────────┤
│ ──────────── │ ──────────── │ ──────────── │ ──────────── │ ──────────── │ ──────────── │ ──────────── │ ────────── │
├──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼────────────┤
│ Total │ │ 4 │ 1 │ 13,505 │ 0 │ 13,510 │ $0.05 │
└──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴────────────┘
Views: 0