Back to Discover

#llm cost

2 prompts found

Claude Extended Thinking Budget Planner: budget_tokens vs max_tokens, Tool Use with Thinking Blocks Passed Back, Streaming Thresholds, Caching Effects, and a Cost Test Plan
🤖 AI Tools

Claude Extended Thinking Budget Planner: budget_tokens vs max_tokens, Tool Use with Thinking Blocks Passed Back, Streaming Thresholds, Caching Effects, and a Cost Test Plan

Ppromptstudio·Oct 9, 2026
No rating

Plan how to turn on extended thinking in the Claude API for a real feature: choose a budget_tokens and max_tokens pair per task, keep thinking blocks intact across tool calls, know which parameters stop working, decide when to stream, and test cost and quality before rollout.

Act as an LLM platform engineer who adds extended thinking to Claude API features in production, sets thinking budgets per task from test data, and keeps tool use, caching, and billing behavior correct. Inputs: - The feature and its task types (for example contract clause analysis, multi step data question answering, code review), with current model and settings: [FeatureAndTasks] - Current request shape: system prompt size, typical input tokens, max_tokens, temperature, tool definitions, and tool_choice: [CurrentRequest] - Whether the feature uses tool calls in a loop and how the conversation history is stored: [ToolLoop] - Latency and cost limits per request and per month: [Limits] - Whether prompt caching is enabled and where the cache breakpoints are: [CachingSetup] - Output format: [Format] Generate: 1. A task by task decision on whether extended thinking is worth enabling for FeatureAndTasks, with the reason. 2. A budget table per task: starting budget_tokens, max_tokens, and why, keeping budget_tokens at the documented minimum or above and below max_tokens unless interleaved thinking applies [confirm in Anthropic docs]. 3. Parameter conflicts in CurrentRequest that change when thinking is on: temperature and top_k changes, forced tool_choice, and assistant prefill, with the fix for each [confirm in Anthropic docs]. 4. A tool loop plan from ToolLoop: pass the thinking blocks, including their signatures, back unchanged in the assistant turn that holds the tool_use, and whether interleaved thinking between tool calls is needed. 5. A streaming rule: when max_tokens is large enough that streaming should be used, and how the UI handles thinking deltas. 6. A caching note from CachingSetup: what changing the thinking budget does to cached prefixes and where to keep breakpoints. 7. A billing note: thinking tokens are billed as output tokens, and on newer models the returned thinking may be a summary while billing covers the full thinking [confirm per model]. 8. A cost and quality test plan against Limits: a fixed eval set, two or three budgets per task, and the metrics to log (usage.output_tokens, latency, pass rate). Constraints: - Do not invent prices, model names, or limits; mark them [confirm in Anthropic docs]. - Never suggest editing or removing thinking blocks mid tool loop. - Plain engineer tone. No em dashes.

Gemini API Context Caching Planner: Implicit vs Explicit Caching on Gemini 2.5 Models, google-genai caches.create with TTL, Minimum Cacheable Tokens, Stable Prefix Prompt Layout, Storage vs Input Cost Math, and Cache Hit Monitoring
🤖 AI Tools

Gemini API Context Caching Planner: Implicit vs Explicit Caching on Gemini 2.5 Models, google-genai caches.create with TTL, Minimum Cacheable Tokens, Stable Prefix Prompt Layout, Storage vs Input Cost Math, and Cache Hit Monitoring

Ppromptstudio·Oct 7, 2026
No rating

Decide whether and how to cache a large repeated context in the Gemini API: compare implicit caching with explicit caches, lay out prompts so the stable part comes first, create and refresh a cache with the google-genai SDK and a TTL that matches your traffic, check the cost against storage charges using the rates you paste, and confirm hits in usage metadata.

Act as a backend engineer who runs production apps on the Gemini API, has cut monthly token bills by caching large shared contexts, and has debugged the error you get when a request sends a system instruction alongside a cached context. Inputs: - The workload: requests per day, hours when traffic arrives, shared context size in tokens, and typical question size: [Workload] - What repeats across requests (system instruction, manuals, codebase, a long video or PDF) and how often it changes: [SharedContext] - Model and SDK in use: [ModelChoice] - Rates copied from the current Gemini pricing page for input, cached input, and cache storage: [PricingNotes] - Current prompt structure or code snippet: [CurrentCode] - Output format: [Format] Generate: 1. An implicit versus explicit decision: implicit caching is on by default for Gemini 2.5 models and gives a discount only when a request shares a prefix with a recent one, with no guarantee; explicit caching stores the context for a TTL you pay storage for, and gives a predictable discount. Pick one for this Workload and say why. 2. Prompt layout rules for either mode: put the large stable content first and the per request question last, keep the stable part byte identical, and send similar requests close together in time. 3. A minimum size check: explicit caches need a minimum number of input tokens that differs by model; tell the user to measure with client.models.count_tokens and compare against the current minimum for ModelChoice from the docs. 4. Python code with the google-genai SDK: client.caches.create with model, a CreateCachedContentConfig holding display_name, system_instruction, contents, and ttl; then client.models.generate_content with GenerateContentConfig(cached_content=cache.name). Put system_instruction and tools in the cache, not in the request, because the request cannot set them when it uses cached content. 5. TTL and refresh: choose a TTL from the traffic hours in Workload, extend it with client.caches.update when traffic continues, and delete it with client.caches.delete when the day ends. 6. Versioning: caches are not edited in place; create a new cache when SharedContext changes, and put the content version in display_name. 7. Cost math using only PricingNotes: daily cost without caching, with explicit caching (cached tokens at the cached rate plus storage tokens times hours), and the break even request count. 8. Monitoring: log usage_metadata.cached_content_token_count and prompt_token_count per request, alert when the cached share drops, and recreate the cache on a not found error after expiry. Constraints: - Never invent prices or token minimums; use PricingNotes and mark anything else "confirm in the current Gemini docs". - The cache model must match the request model exactly. No em dashes.