Claude AI - Tygart Media

Category: Claude AI

Complete guides, tutorials, comparisons, and use cases for Claude AI by Anthropic.

  • Claude Output Compression: Token Savings & Structured JSON

    Claude Output Compression: Token Savings & Structured JSON

    Last refreshed: May 15, 2026

    Most Claude cost analyses focus on input tokens — the knowledge you send in. The underappreciated lever is output compression. Claude is trained to be thorough. Left unconstrained, it produces full meals: preambles, recaps, hedges, transition sentences, closing summaries. All of those tokens cost money. All of them are often unnecessary. Output discipline — getting Claude to deliver concentrated slices instead of full meals — is often the highest-leverage cost reduction available without changing models or switching to async.

    This is part of the Claude on a Budget series. For input-side compression, see The Cold-Start Problem. For pricing mechanics, see Prompt Caching.

    The Default Verbosity Problem

    Workshop fuel gauge and metal tokens pouring into an API hopper, metaphor for pay-per-token pricing
    The default verbosity problem.

    Ask Claude to “summarize this document” without constraints and you will get: an opening sentence restating the task, a multi-paragraph summary, a bullet-point recap of the summary, and a closing note about what was not covered. The actual information density — insight per token — is low. You paid for 800 tokens of output and needed 150. Multiply across thousands of API calls and you have built a significant cost leak from default model behavior, not from bad prompts.

    The Output Compression Toolkit

    Cost control gates for production routing
    The output compression toolkit.

    1. Explicit word and token caps in the prompt. “Respond in 150 words or fewer” is the single most effective instruction for reducing output tokens. Claude respects tight limits. “Be concise” does not work reliably. “150 words maximum” does. For JSON outputs: “Respond with only valid JSON, no markdown fences, no explanation.” Every word of instruction about format is recovered 10x in output reduction across repeated calls.

    2. Structured output schemas. When you need structured data, define the exact JSON schema. Claude stops generating prose and fills fields. You get exactly what you specified and nothing more. The token reduction versus free-form responses is typically 40-70% for equivalent information content.

    # Free-form -- verbose, unpredictable length
    prompt_verbose = "Summarize the key points of this article and their implications."
    
    # Structured -- tight, predictable, cheaper
    prompt_structured = """Extract from this article:
    {"headline": "string", "key_points": ["string", "string", "string"], "sentiment": "positive|neutral|negative"}
    Respond with valid JSON only. No explanation."""

    3. Role-based compression priming. System prompt framing shapes output length. “You are a precise technical writer who values brevity. Never restate the task. Deliver the answer directly.” produces consistently shorter outputs than a neutral system prompt. This is prompt engineering for token economics, not just quality.

    4. Chained micro-tasks over monolithic requests. Instead of asking Claude to research, analyze, synthesize, and format in one prompt, chain smaller requests. Each call is scoped to one task with tight output constraints. Total tokens across the chain are often lower than a single unconstrained request, and intermediate outputs are cacheable — pairing naturally with the prompt caching strategy.

    The Notion Second Brain Application

    The operational implementation at Tygart Media runs this pattern at pipeline level. The Notion second brain eliminates the need for Claude to generate background context — it already exists in structured form. Extractions from Notion arrive as pre-formatted knowledge blocks. Claude’s task is synthesis over existing structured data, not open-ended research and explanation. Output prompts are scoped: “Given this structured data, write a 400-word section for [topic]. No preamble, no conclusion, begin directly with the first point.” The output is a concentrated slice — dense, usable, billable at a fraction of what free-form generation costs for equivalent value.

    Measuring Compression Effectiveness

    Desk with laptop, checklist notebook, and billing card ready before creating an Anthropic API key
    Measuring compression effectiveness.

    Track output_tokens in your API responses. Log them per prompt template. Identify your highest-output templates and run compression interventions — tighter word caps, structured formats, role priming. The target is information density: insight delivered per output token, not raw token count. A 500-token output with 3 actionable insights beats a 200-token output with 1. Compression discipline is about removing the scaffolding (preambles, hedges, recaps) while preserving the load-bearing structure (insight, data, instruction).

    max_tokens as a Hard Ceiling

    Set max_tokens conservatively in your API calls. This is your financial guardrail, not just a model parameter. For classification tasks: 50 tokens. For short summaries: 200 tokens. For structured JSON extraction: 500 tokens. For article drafts: 1,500-2,000 tokens. Leaving max_tokens at the model default (4,096-8,192) on every call is leaving a cost ceiling unjustifiably high. Claude will rarely hit the ceiling on constrained tasks, but it prevents runaway generation on edge-case inputs that can quietly inflate your bill.

    Next: Per-Model Content Shaping: Write Less, Get Cited More →

  • Anthropic Batch API: Save 50% on Async Claude Workloads

    Anthropic Batch API: Save 50% on Async Claude Workloads

    Last refreshed: May 15, 2026

    Every dollar you spend on Claude at full synchronous price is a dollar you’re overpaying for non-urgent work. Anthropic’s Message Batches API delivers a flat 50% discount on both input and output tokens — the same models, the same quality, half the price — with one constraint: results arrive asynchronously, typically within 24 hours.

    This is part of the Claude on a Budget series. If you’re routing models for real-time work, see Model Routing: Haiku vs Sonnet vs Opus. For cutting repeated context costs, see Prompt Caching.

    The Math First

    Workshop fuel gauge and metal tokens pouring into an API hopper, metaphor for pay-per-token pricing
    The math first — why batch pricing exists.

    Standard Sonnet 4.6 pricing: $3.00 input / $15.00 output per million tokens. Batch Sonnet 4.6: $1.50 input / $7.50 output. Run 1,000 article drafts synchronously and you’re spending full rate on every one. Run the same batch overnight and you cut the bill in half — no model quality change, no output degradation, just a different delivery mechanism.

    ModelSync InputSync OutputBatch InputBatch Output
    Haiku 4.5$1.00/M$5.00/M$0.50/M$2.50/M
    Sonnet 4.6$3.00/M$15.00/M$1.50/M$7.50/M
    Opus 4.7$5.00/M$25.00/M$2.50/M$12.50/M

    What Qualifies as Non-Urgent Work

    Side-by-side when to use a script versus an agent
    What qualifies as non-urgent work.

    The honest question is not “does this need to be fast?” — it’s “does this need to be synchronous?” Most content pipelines, data enrichment tasks, classification jobs, and bulk translation runs have no real-time dependency. The user is not waiting at a keyboard. The output feeds a queue. The 24-hour window is irrelevant. Candidates include: nightly article drafts, SEO metadata generation for large post archives, batch product description rewrites, email personalization at scale, sentiment tagging across historical data, bulk summarization of documents or transcripts.

    What does not qualify: customer-facing chat, real-time code completion, any workflow where a human is actively waiting for a response.

    The API Pattern

    import anthropic
    
    client = anthropic.Anthropic()
    
    # Build your batch — each request is a full message payload
    requests_list = [
        {
            "custom_id": f"article-{i}",
            "params": {
                "model": "claude-sonnet-4-6",
                "max_tokens": 2000,
                "messages": [
                    {"role": "user", "content": f"Write a 500-word expert summary of: {topic}"}
                ]
            }
        }
        for i, topic in enumerate(topics)
    ]
    
    # Submit the batch
    batch = client.messages.batches.create(requests=requests_list)
    print(f"Batch ID: {batch.id} | Status: {batch.processing_status}")
    
    # Poll until complete
    import time
    while True:
        status = client.messages.batches.retrieve(batch.id)
        if status.processing_status == "ended":
            break
        time.sleep(60)
    
    # Retrieve results
    for result in client.messages.batches.results(batch.id):
        custom_id = result.custom_id
        if result.result.type == "succeeded":
            text = result.result.message.content[0].text
            print(f"{custom_id}: {text[:100]}...")

    Combining Batch API With Prompt Caching

    Cost control gates for production routing
    Combining Batch API with prompt caching.

    These two discounts stack. If your batch requests share a large system prompt — a style guide, a knowledge base, a persona definition — mark that block with cache_control: {"type": "ephemeral"}. Anthropic caches it across all requests in the batch that hit the same prompt prefix. You pay input rate on the first hit and cache read rate (roughly 10% of input rate) on every subsequent hit. A 10,000-token system prompt shared across 500 batch requests: you pay full rate once, cache rate 499 times, and you are already on batch pricing for all output tokens. The compounding effect is significant.

    Structuring Your Pipeline Around Batch Windows

    The practical architecture: identify every Claude call in your current workflow that has no real-time dependency. Move those calls behind a queue. Set a nightly cron that drains the queue into a batch submission at 11 PM. Results are ready by morning. Your synchronous Claude budget drops to customer-facing interactions only — often 20-30% of total volume for content and data operations teams.

    Rate limits are separate for batch vs. synchronous traffic, so batch jobs do not compete with your real-time usage. That is a free operational benefit on top of the price cut.

    Error Handling at Scale

    Batch results include a result.type field: succeeded, errored, or canceled. Always iterate the full result set and collect errored custom_ids for resubmission. At scale — thousands of requests — you will see occasional errors. Build the retry loop into your pipeline from day one rather than discovering it when 3% of a 10,000-request batch silently fails.

    The Honest Tradeoff

    Batch API is a discipline, not a feature. It requires you to think about your Claude usage in terms of urgency tiers, not just prompt quality. Teams that adopt it consistently cut their Claude bills by 30-50% on total spend — not because every call moves to batch, but because the non-urgent majority does. Combined with model routing (Haiku for triage, Sonnet for batch drafts, Opus only for synchronous high-stakes reasoning), it is the highest-leverage cost lever available in the Anthropic stack today.

    Next: Prompt Caching: How to Cut Repeated Context Costs by Up to 90% →