client.beta.messages.create( max_tokens=1024, messages=[ { "role": "user", "content": [ { "type": "text", "text": TEMPLATE_1.replace("{WHOLE_DOCUMENT}", md_contents), "cache_control": {"type": "ephemeral"}, }, { "type": "text", "text": TEMPLATE_2.replace( "{CHUNK_CONTENT}", document.page_content ), }, ], } ], model=model, ) from anthropic import Anthropic client = Anthropic( api_key=api_key, default_headers={ "anthropic-beta": "prompt-caching-2024-07-31" }, ) プロンプトキャッシュを使えば 1ドキュメント$1.66 87%割安!!