prompt-caching-strategy
できること
このツールは、AIに送る指示の整理方法を工夫することで、コストを抑えつつAIの応答を速くするのに役立ちます。指示の中で繰り返し使われる部分を常に同じ内容にしておくことで、AIが以前の回答を再利用できるようにします。
使う場面
- ✓AIに、よく似た依頼を何度も送るとき。
- ✓AIの応答を速くしたいとき。
- ✓AIサービスの利用料金を下げたいとき。
スキルのリンク
https://github.com/affaan-m/ECC/blob/main/skills/prompt-caching-strategy/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“AIがキャッシュを使ってくれて、支払う料金が減るように、プロンプトをどう整理すればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このツールは、指示のうち変わらない部分(ルールや例など)と、毎回変わる部分(今回の質問など)を分けることを提案します。こうすることで、AIは変わらない部分を認識しやすくなり、再利用しやすくなります。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Prompt Caching Strategy
Arrange reusable prompt content to improve cache reuse, then measure input cost and latency. Savings depend on model, platform, cache eligibility, writes, retention, reuse and output volume. Runtime cache hits and savings for this skill are unmeasured; the examples below validate arithmetic without provider calls.
When to Activate
Use for repeated API requests that share authorized instructions, tools or reference material. First identify the exact provider endpoint, model, service tier and caching mode. Consult its current documentation before selecting rates, minimum prefix length or retention. Caching does not reduce context-window use.
How It Works
Preserve a stable prefix
Keep reusable instructions, tool schemas and examples stable; place changing questions, timestamps and retrieved results after that content where the API allows. Respect the provider's serialization order: Claude uses tools, system, then messages. Matching prefixes need identical content, including tool schemas and relevant request settings. A changed prefix can prevent reuse from that point. A dynamic suffix may itself be cached later if reused unchanged.
Reusable prefix: approved tools, instructions, stable examples/reference
Changing suffix: current question, fresh retrieval results, request metadata
Choose only relevant context. Padding prompts or broadening access just to meet an eligibility threshold needs its own cost and quality justification.
Preserve user and workspace boundaries
Authorize content access before cache lookup or reuse. Scope application-managed cache handles and accounting keys to the approved user, workspace, provider account, model and content revision. Share only material explicitly approved for that scope. A cache key is a routing/accounting hint, not an authorization gate or a sandbox. Provider cache isolation does not replace application access checks. Invalidate application references when permissions or content change; follow provider retention/deletion controls. Avoid logging private prompt contents. Context selection, capabilities, sandbox enforcement and evidence remain independent of cache optimization.
Provider Requirements and Usage Evidence
The linked documentation is authoritative; endpoint and SDK versions can expose different usage field names. Record that version alongside counters.
| Provider | Requirements to verify | Counters to record |
|---|---|---|
| OpenAI | Model-specific automatic/explicit modes, minimum length, retention and write/read prices; earlier and newer models differ | Responses usage.input_tokens_details.cached_tokens and, when present, cache_write_tokens; input and output totals. Chat Completions uses prompt_tokens_details.cached_tokens |
| Claude | Supported platform, model minimum, cache_control support and TTL; cache writes may cost more than ordinary input |
input_tokens, cache_creation_input_tokens, cache_read_input_tokens, output_tokens; split writes by TTL when rates differ |
| Gemini | Model minimum and API: Interactions supports implicit caching; explicit cache objects require GenerateContent | Interactions usage.total_cached_tokens; GenerateContent usage_metadata cache/input/output counters plus explicit-cache token count and retained duration |
Use OpenAI's prompt caching guide and pricing for the selected model. For Chat Completions, check the usage schema. Derive ordinary input from the total minus cached reads and any separately reported writes; do not count the same tokens twice.
Use Claude's prompt caching guide
for current model/platform limits and TTL rates. Its input_tokens counts
ordinary input separately from cache reads and writes. A short prefix can produce
zero cache counters even when marked for caching. Do not assume every Claude
model or hosted platform uses the same minimum or read price.
Use Gemini's caching guide, GenerateContent caching guide and pricing. Explicit-cache
…
よくある質問
「キャッシュ」とは何ですか?
キャッシュは、AIがすでに処理した質問への回答を保存しておく一時的な記憶領域のようなものです。同じ質問が来たときは、すべてを計算し直すのではなく、保存してある回答を使います。
これはどのAIでも使えますか?
OpenAIやClaudeなど、一部の特定のAIで使えます。設定方法は各サービスのドキュメントで確認してください。
キャッシュを使うと、コンテキストウィンドウのサイズは小さくなりますか?
いいえ。キャッシュがAIのコンテキストウィンドウの使用量を減らすわけではありません。情報を再利用することで、処理を速く、安くするものです。
詳細
作者による元の説明
Optimize LLM prompt caching hit rate to reduce API costs and improve latency. Analyzes prompt structure, identifies cacheable vs non-cacheable content, and recommends restructuring to maximize cache reuse. TRIGGER when: user says "prompt cache", "cache hit rate", "reduce LLM cost", "optimize token usage", "cheaper LLM calls", or asks about prompt caching strategies for OpenAI/Anthropic/other provi
repo: affaan-m/ECC
人気
- GitHubのスター
- 280k
- ランキング
- #386
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
accessibility
280kエージェントが誰にとっても使いやすいインターフェースを作れるように手助けします。目が見えない方や身体の動きに制限のある方など、障害のある人にとってもWebサイトやアプリが正しく動くようにします。
agent-architecture-audit
280kエージェントがすべて正しく動いているかを確認できるようにします。AIシステムの問題を見つけて修正し、期待どおりに動くようにします。
agent-eval
280kエージェントが異なるAIコーディングツールを比較できるようにします。特定のタスクにおいて、どれがより速く、安く、信頼性が高いかを測定します。
agent-harness-construction
280kエージェントがタスクの進め方をよりよく理解できるようにします。エージェントが使うツールや指示を最適化し、成功する可能性を高めます。
似ているスキル
writing-skills
311k新しいスキルを書き、それぞれをまず試すようエージェントに教えます。そのスキルが実際にエージェントの動作を変えることを確認します。
writing-for-agents
310kスキル、AGENTS.md、CLAUDE.mdを含め、AIエージェントのための明確な指示の書き方を説明し、エージェントが予測可能に動くようにします。
dspy
260k入力と出力を宣言することで、プロンプトを手で一つずつ書かずにAIプログラムを作り、例のデータからプロンプトを調整するのをエージェントが支援します。