> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Shubhamsaboo/awesome-llm-apps/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM Optimization Tools

> Reduce LLM API costs by 30-90% with token optimization and context compression techniques

## Overview

LLM API costs are directly tied to token count. These optimization tools help you reduce token usage while maintaining accuracy, enabling cost-effective AI applications at scale.

<CardGroup cols={2}>
  <Card title="TOON Format" icon="compress" href="#toonify-token-optimization">
    63.9% average token reduction for structured data
  </Card>

  <Card title="Headroom" icon="layer-group" href="#headroom-context-optimization">
    47-92% token savings through intelligent compression
  </Card>
</CardGroup>

## Why Optimize?

<Tabs>
  <Tab title="Cost Savings">
    ### Impact on API Costs

    Based on GPT-4 pricing (\$0.03/1K input tokens):

    | Usage Volume  | Standard Cost | With Optimization (60% reduction) | Savings         |
    | ------------- | ------------- | --------------------------------- | --------------- |
    | 1,000 calls   | \$2.55        | \$1.02                            | **\$1.53**      |
    | 100,000 calls | \$255.00      | \$102.00                          | **\$153.00**    |
    | 1M calls      | \$2,550.00    | \$1,020.00                        | **\$1,530.00**  |
    | 10M calls     | \$25,500.00   | \$10,200.00                       | **\$15,300.00** |
  </Tab>

  <Tab title="Performance">
    ### Speed & Efficiency Benefits

    * **Faster Processing**: Fewer tokens = shorter generation time
    * **Reduced Latency**: Smaller payloads transmit faster
    * **Better Throughput**: Process more requests per second
    * **Context Window**: Fit more information in limited windows
  </Tab>

  <Tab title="Scale">
    ### Production at Scale

    For a production app with 100K daily requests:

    * **Monthly savings**: \$4,590
    * **Yearly savings**: \$55,080
    * **3-year savings**: \$165,240

    Optimization pays for itself immediately at scale.
  </Tab>
</Tabs>

***

## Toonify Token Optimization

<Tip>Reduce token usage by 30-73% using TOON (Token-Oriented Object Notation) format</Tip>

### What is TOON?

TOON is a compact serialization format designed specifically for LLM token efficiency. It achieves CSV-like compression while maintaining structure and readability.

### Key Benefits

<CardGroup cols={2}>
  <Card title="63.9% Average Reduction" icon="chart-line">
    Verified across 50 real-world datasets
  </Card>

  <Card title="73.4% for Tabular Data" icon="table">
    Optimal for structured, uniform data
  </Card>

  <Card title="Human Readable" icon="eye">
    Still easy to understand and debug
  </Card>

  <Card title="<1ms Overhead" icon="bolt">
    Negligible conversion time
  </Card>
</CardGroup>

### Format Comparison

<CodeGroup>
  ```json JSON (247 bytes, 85 tokens) theme={null}
  {
    "products": [
      {"id": 101, "name": "Laptop Pro", "price": 1299},
      {"id": 102, "name": "Magic Mouse", "price": 79},
      {"id": 103, "name": "USB-C Cable", "price": 19}
    ]
  }
  ```

  ```toon TOON (98 bytes, 39 tokens - 60% reduction) theme={null}
  products[3]{id,name,price}:
    101,Laptop Pro,1299
    102,Magic Mouse,79
    103,USB-C Cable,19
  ```
</CodeGroup>

<Info>
  **Token Savings**: 85 → 39 tokens (54.1% reduction)

  **Cost Impact**: $2.55/1K requests → $1.17/1K requests
</Info>

### Implementation

<Steps>
  <Step title="Install Toonify">
    ```bash theme={null}
    pip install toonify
    ```
  </Step>

  <Step title="Convert Data to TOON">
    ```python theme={null}
    from toon import encode, decode
    import json

    # Your structured data
    data = {
        "products": [
            {"id": 1, "name": "Laptop", "price": 1299, "stock": 45},
            {"id": 2, "name": "Mouse", "price": 79, "stock": 120},
        ]
    }

    # Convert to TOON format
    toon_str = encode(data)
    print(f"JSON: {len(json.dumps(data))} bytes")
    print(f"TOON: {len(toon_str)} bytes")
    ```
  </Step>

  <Step title="Send to LLM">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI()

    # Use TOON format in prompt
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{
            "role": "user",
            "content": f"Analyze this product data:\n\n{toon_str}"
        }]
    )

    print(response.choices[0].message.content)
    ```
  </Step>

  <Step title="Decode if Needed">
    ```python theme={null}
    # Convert back to Python objects
    original_data = decode(toon_str)
    assert original_data == data  # Roundtrip verification
    ```
  </Step>
</Steps>

### Real-World Example

<Accordion title="E-commerce Product Analysis">
  ```python theme={null}
  from toon import encode
  from openai import OpenAI
  import json

  client = OpenAI()

  # Sample product catalog (could be 100s of products)
  products = [
      {"id": 1, "name": "Laptop Pro", "price": 1299, "stock": 45, "category": "Electronics"},
      {"id": 2, "name": "Magic Mouse", "price": 79, "stock": 120, "category": "Accessories"},
      {"id": 3, "name": "USB-C Hub", "price": 49, "stock": 200, "category": "Accessories"},
      {"id": 4, "name": "4K Monitor", "price": 599, "stock": 30, "category": "Electronics"},
      {"id": 5, "name": "Keyboard", "price": 129, "stock": 85, "category": "Accessories"},
      # ... potentially hundreds more
  ]

  # Measure token reduction
  json_str = json.dumps(products)
  toon_str = encode(products)

  print(f"JSON size: {len(json_str)} bytes")
  print(f"TOON size: {len(toon_str)} bytes")
  print(f"Reduction: {((len(json_str) - len(toon_str)) / len(json_str) * 100):.1f}%")

  # Send optimized data to LLM
  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[{
          "role": "user",
          "content": f"""
          Analyze this product catalog and provide:
          1. Total inventory value
          2. Low stock items (< 50 units)
          3. Average price by category
          
          Data:
          {toon_str}
          """
      }]
  )

  print(response.choices[0].message.content)
  ```

  **Results:**

  * JSON: 487 bytes, \~165 tokens
  * TOON: 186 bytes, \~68 tokens
  * **Reduction: 58.8% tokens, 61.8% bytes**
</Accordion>

### Best Use Cases

<AccordionGroup>
  <Accordion title="Tabular Data" icon="table">
    **Optimal for:**

    * Product catalogs
    * CSV exports
    * Database query results
    * API response data
    * Survey results
    * Analytics data

    **Token savings: 60-73%**
  </Accordion>

  <Accordion title="Structured JSON" icon="code">
    **Good for:**

    * Configuration files
    * Uniform object arrays
    * API payloads
    * Log data

    **Token savings: 50-65%**
  </Accordion>

  <Accordion title="When NOT to Use" icon="triangle-exclamation">
    **Avoid TOON for:**

    * Highly nested data (greater than 3 levels)
    * Irregular/heterogeneous structures
    * Small payloads (less than 100 bytes)
    * Binary data
    * When JSON compatibility is critical
  </Accordion>
</AccordionGroup>

### Interactive Demo

<Accordion title="Streamlit App Code">
  ```python theme={null}
  import streamlit as st
  import json
  from toon import encode, decode
  import tiktoken

  st.title("🎯 Toonify Token Optimizer")

  # Token counter
  enc = tiktoken.encoding_for_model("gpt-4")

  def count_tokens(text):
      return len(enc.encode(text))

  # Input data
  data_input = st.text_area(
      "Paste your JSON data",
      value=json.dumps({
          "products": [
              {"id": 1, "name": "Laptop", "price": 1299},
              {"id": 2, "name": "Mouse", "price": 79},
          ]
      }, indent=2),
      height=200
  )

  if data_input:
      try:
          # Parse JSON
          data = json.loads(data_input)
          
          # Convert to TOON
          toon_str = encode(data)
          
          # Calculate metrics
          json_tokens = count_tokens(data_input)
          toon_tokens = count_tokens(toon_str)
          reduction = ((json_tokens - toon_tokens) / json_tokens) * 100
          
          # Display results
          col1, col2 = st.columns(2)
          
          with col1:
              st.subheader("JSON Format")
              st.code(data_input, language="json")
              st.metric("Tokens", json_tokens)
              st.metric("Bytes", len(data_input))
          
          with col2:
              st.subheader("TOON Format")
              st.code(toon_str, language="text")
              st.metric("Tokens", toon_tokens)
              st.metric("Bytes", len(toon_str))
          
          # Savings
          st.success(f"Token Reduction: {reduction:.1f}%")
          
          # Cost calculator
          st.subheader("Cost Savings Calculator")
          requests = st.number_input("Number of API requests", value=1000, step=1000)
          
          gpt4_cost_per_1k = 0.03
          json_cost = (json_tokens / 1000) * gpt4_cost_per_1k * requests
          toon_cost = (toon_tokens / 1000) * gpt4_cost_per_1k * requests
          savings = json_cost - toon_cost
          
          st.write(f"**JSON cost**: ${json_cost:.2f}")
          st.write(f"**TOON cost**: ${toon_cost:.2f}")
          st.write(f"**💰 Savings**: ${savings:.2f}")
          
      except Exception as e:
          st.error(f"Error: {e}")
  ```

  Run with: `streamlit run toonify_app.py`
</Accordion>

### Performance Benchmarks

<Tabs>
  <Tab title="Token Reduction">
    | Dataset Type    | Avg Reduction | Best Case | Worst Case |
    | --------------- | ------------- | --------- | ---------- |
    | Tabular         | 68.5%         | 73.4%     | 62.1%      |
    | Structured JSON | 61.2%         | 67.8%     | 54.3%      |
    | Nested JSON     | 48.7%         | 56.2%     | 41.5%      |
    | Mixed           | 55.4%         | 63.9%     | 47.8%      |
  </Tab>

  <Tab title="Conversion Speed">
    | Operation | Time (avg) | Time (p99) |
    | --------- | ---------- | ---------- |
    | Encode    | 0.42ms     | 1.2ms      |
    | Decode    | 0.38ms     | 1.0ms      |
    | Roundtrip | 0.85ms     | 2.1ms      |
  </Tab>

  <Tab title="Scale Test">
    **Test: 1000 product catalog**

    * JSON: 125KB, 42,500 tokens
    * TOON: 48KB, 16,800 tokens
    * **Reduction: 60.5% tokens, 61.6% size**
    * Encoding time: 3.2ms
    * **Monthly savings**: \$2,142 (at 100K requests/day)
  </Tab>
</Tabs>

***

## Headroom Context Optimization

<Tip>Reduce token usage by 47-92% through intelligent context compression for AI agents</Tip>

### What is Headroom?

Headroom is a context optimization layer that compresses tool outputs and conversation history while preserving accuracy. Unlike simple truncation, it uses statistical analysis to keep what matters.

### Key Benefits

<CardGroup cols={2}>
  <Card title="47-92% Token Reduction" icon="percent">
    Verified across production workloads
  </Card>

  <Card title="Zero Code Changes" icon="plug">
    Transparent proxy integration
  </Card>

  <Card title="Reversible Compression" icon="rotate">
    LLM can retrieve original data via CCR
  </Card>

  <Card title="Provider Caching" icon="database">
    Optimizes for OpenAI/Anthropic caching
  </Card>
</CardGroup>

### Core Features

<Tabs>
  <Tab title="SmartCrusher">
    ### Statistical Compression

    Keeps:

    * First N items (context)
    * Last N items (recency)
    * Anomalies (statistical outliers)
    * Query-relevant matches

    Removes:

    * Repetitive boilerplate
    * Redundant middle sections
    * Low-information content

    ```python theme={null}
    from headroom import SmartCrusher

    crusher = SmartCrusher(
        keep_first=2,
        keep_last=2,
        keep_anomalies=True,
        compression_ratio=0.3
    )

    # Compress tool output
    compressed = crusher.compress(tool_output)
    ```
  </Tab>

  <Tab title="CacheAligner">
    ### Prefix Optimization

    Stabilizes message prefixes for better provider-side caching:

    ```python theme={null}
    from headroom import CacheAligner

    aligner = CacheAligner(provider="anthropic")

    # Optimize for cache hits
    optimized_messages = aligner.align(messages)
    ```

    **Cache hit rate improvement:**

    * OpenAI: 35% → 78%
    * Anthropic: 42% → 85%
  </Tab>

  <Tab title="CCR System">
    ### Compress-Cache-Retrieve

    Reversible compression:

    1. **Compress**: Reduce tokens
    2. **Cache**: Store original
    3. **Retrieve**: LLM requests if needed

    ```python theme={null}
    from headroom import CCR

    ccr = CCR()

    # Compress with retrieval capability
    compressed, cache_id = ccr.compress(large_content)

    # LLM can request original
    if llm_needs_more_detail:
        original = ccr.retrieve(cache_id)
    ```
  </Tab>
</Tabs>

### Installation & Setup

<Steps>
  <Step title="Install Headroom">
    <CodeGroup>
      ```bash Basic theme={null}
      pip install headroom-ai
      ```

      ```bash With Integrations theme={null}
      # LangChain support
      pip install "headroom-ai[langchain]"

      # Agno support
      pip install "headroom-ai[agno]"

      # Code compression
      pip install "headroom-ai[code]"

      # All features
      pip install "headroom-ai[all]"
      ```
    </CodeGroup>
  </Step>

  <Step title="Choose Integration Method">
    <Tabs>
      <Tab title="Proxy (Zero Code)">
        ```bash theme={null}
        # Start proxy server
        headroom proxy --port 8787

        # Point existing tools at proxy
        export OPENAI_BASE_URL=http://localhost:8787/v1
        export ANTHROPIC_BASE_URL=http://localhost:8787

        # Use tools normally - compression is automatic
        ```
      </Tab>

      <Tab title="LangChain">
        ```python theme={null}
        from langchain_openai import ChatOpenAI
        from headroom.integrations import HeadroomChatModel

        # Wrap your model
        llm = HeadroomChatModel(ChatOpenAI(model="gpt-4o"))

        # Use normally
        response = llm.invoke("Analyze these logs")

        # Check savings
        print(f"Tokens saved: {llm.total_tokens_saved}")
        ```
      </Tab>

      <Tab title="Agno">
        ```python theme={null}
        from agno.agent import Agent
        from agno.models.openai import OpenAIChat
        from headroom.integrations.agno import HeadroomAgnoModel

        # Wrap model
        model = HeadroomAgnoModel(OpenAIChat(id="gpt-4o"))

        # Create agent
        agent = Agent(
            model=model,
            tools=[search_github, search_code, query_db]
        )

        # Run with automatic compression
        response = agent.run("Find memory leaks")
        print(f"Saved: {model.total_tokens_saved} tokens")
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

### Real-World Performance

<Warning>
  These are actual results from production API calls, not estimates.
</Warning>

<Tabs>
  <Tab title="Code Search">
    ### GitHub Code Search (100 results)

    **Scenario**: Search 100 code files for error handling patterns

    | Metric        | Before | After  | Savings    |
    | ------------- | ------ | ------ | ---------- |
    | Tokens        | 17,765 | 1,408  | **92%**    |
    | Cost (GPT-4)  | \$0.53 | \$0.04 | **\$0.49** |
    | Response Time | 8.2s   | 2.1s   | **74%**    |

    **Compression strategy:**

    * Keep first 2 and last 2 results
    * Extract only relevant code sections
    * Remove boilerplate imports/comments
    * Preserve error handling patterns
  </Tab>

  <Tab title="SRE Debugging">
    ### Incident Log Analysis

    **Scenario**: Debug production outage from 65K token log file

    | Metric          | Before | After  | Savings    |
    | --------------- | ------ | ------ | ---------- |
    | Tokens          | 65,694 | 5,118  | **92%**    |
    | Cost (GPT-4)    | \$1.97 | \$0.15 | **\$1.82** |
    | Time to insight | 12.4s  | 3.2s   | **74%**    |

    **What was preserved:**

    * All ERROR and FATAL entries
    * Anomalous log patterns
    * First/last entries for timeline
    * Stack traces

    **What was compressed:**

    * Repetitive INFO logs
    * Standard health checks
    * Redundant timestamps
  </Tab>

  <Tab title="Agent Workflow">
    ### Multi-Tool Agent

    **Scenario**: Agent using 5 tools (search, database, API, logs, docs)

    | Tool Call     | Tokens Before | Tokens After | Reduction |
    | ------------- | ------------- | ------------ | --------- |
    | GitHub search | 15,200        | 1,850        | 88%       |
    | DB query      | 8,400         | 1,200        | 86%       |
    | API response  | 12,600        | 2,100        | 83%       |
    | Log analysis  | 18,900        | 2,400        | 87%       |
    | Docs search   | 9,800         | 1,550        | 84%       |
    | **Total**     | **64,900**    | **9,100**    | **86%**   |

    **Monthly savings at 1K agent runs**: \$1,674
  </Tab>
</Tabs>

### Needle in Haystack Test

<Accordion title="Complete Test Results">
  **Setup:**

  * 100 production log entries
  * 1 critical FATAL error at position 67
  * Question: "What caused the outage? Error code? Fix?"

  **Baseline (no compression):**

  ```
  Tokens: 10,144
  Cost: $0.30
  Response time: 4.8s
  Answer: ✅ Correct (payment-gateway, PG-5523, increase max_connections)
  ```

  **With Headroom:**

  ```
  Tokens: 1,260 (87.6% reduction)
  Cost: $0.04 (86.7% savings)
  Response time: 1.2s (75% faster)
  Answer: ✅ Correct (same details)
  ```

  **What Headroom kept:**

  * Position 67: FATAL error (the needle)
  * Position 1-2: Context (timeline start)
  * Position 99-100: Most recent state
  * Position 45: Anomaly (connection spike)

  **What Headroom removed:**

  * 96 INFO/DEBUG entries
  * Repetitive health checks
  * Standard operational logs

  **Result: Same accuracy, 87.6% fewer tokens**
</Accordion>

### Configuration

<ParamField path="HeadroomChatModel" type="class">
  LangChain integration with compression

  <Expandable title="Parameters">
    <ParamField path="model" type="ChatModel" required>
      Underlying LangChain chat model
    </ParamField>

    <ParamField path="compression_ratio" type="float" default="0.3">
      Target compression (0.3 = keep 30% of tokens)
    </ParamField>

    <ParamField path="enable_ccr" type="bool" default="true">
      Enable Compress-Cache-Retrieve for reversibility
    </ParamField>

    <ParamField path="cache_alignment" type="bool" default="true">
      Optimize for provider-side caching
    </ParamField>
  </Expandable>
</ParamField>

### Best Use Cases

<AccordionGroup>
  <Accordion title="AI Agents with Tools" icon="robot">
    **Optimal for:**

    * Multi-tool workflows
    * Code search agents
    * Database query agents
    * API integration agents
    * Log analysis agents

    **Average savings: 75-90%**
  </Accordion>

  <Accordion title="Large Tool Outputs" icon="file">
    **Ideal for:**

    * Code search results (100+ files)
    * Database query results (1000+ rows)
    * API responses (large JSON)
    * Log files (10K+ lines)
    * Documentation searches

    **Average savings: 80-92%**
  </Accordion>

  <Accordion title="Conversation History" icon="comments">
    **Useful for:**

    * Long chat sessions
    * Multi-turn debugging
    * Context-heavy conversations
    * Memory-intensive agents

    **Average savings: 50-70%**
  </Accordion>
</AccordionGroup>

### Safety Guarantees

<CardGroup cols={2}>
  <Card title="Never Removes Human Content" icon="user">
    User and assistant messages are always preserved in full
  </Card>

  <Card title="Never Breaks Tool Pairing" icon="link">
    Tool calls and responses stay together
  </Card>

  <Card title="Parse Failures = No-op" icon="shield">
    Malformed content passes through unchanged
  </Card>

  <Card title="Reversible Compression" icon="undo">
    LLM can retrieve original data via CCR
  </Card>
</CardGroup>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Choose the Right Tool" icon="screwdriver-wrench">
    | Use Case                    | Tool     | Expected Savings |
    | --------------------------- | -------- | ---------------- |
    | Structured data (JSON, CSV) | TOON     | 60-73%           |
    | AI agent tool outputs       | Headroom | 75-92%           |
    | Large API responses         | Both     | 80-95%           |
    | Conversation history        | Headroom | 50-70%           |
    | Mixed/nested JSON           | TOON     | 45-60%           |
  </Accordion>

  <Accordion title="Measure Impact" icon="chart-line">
    ```python theme={null}
    import tiktoken

    enc = tiktoken.encoding_for_model("gpt-4")

    def measure_optimization(original, optimized):
        original_tokens = len(enc.encode(original))
        optimized_tokens = len(enc.encode(optimized))
        
        reduction = ((original_tokens - optimized_tokens) / original_tokens) * 100
        
        # Calculate cost savings (GPT-4 pricing)
        cost_per_1k = 0.03
        original_cost = (original_tokens / 1000) * cost_per_1k
        optimized_cost = (optimized_tokens / 1000) * cost_per_1k
        
        return {
            "original_tokens": original_tokens,
            "optimized_tokens": optimized_tokens,
            "reduction_percent": reduction,
            "cost_savings": original_cost - optimized_cost
        }
    ```
  </Accordion>

  <Accordion title="Monitor in Production" icon="monitor">
    ```python theme={null}
    from headroom.integrations import HeadroomChatModel
    import logging

    # Set up monitoring
    llm = HeadroomChatModel(base_model)

    # Log metrics
    def log_metrics():
        logging.info(f"Total tokens saved: {llm.total_tokens_saved}")
        logging.info(f"Total cost saved: ${llm.total_cost_saved:.2f}")
        logging.info(f"Compression ratio: {llm.avg_compression_ratio:.1%}")

    # Call after batch of requests
    log_metrics()
    ```
  </Accordion>

  <Accordion title="Combine Techniques" icon="layer-group">
    ```python theme={null}
    from toon import encode
    from headroom.integrations import HeadroomChatModel

    # Use both TOON and Headroom
    def optimized_agent_call(structured_data, tools):
        # 1. Convert structured data to TOON
        toon_data = encode(structured_data)
        
        # 2. Use Headroom for tool outputs
        llm = HeadroomChatModel(base_model)
        
        # 3. Combine for maximum savings
        response = llm.invoke(
            f"Analyze this data and search for patterns:\n{toon_data}"
        )
        
        return response

    # Result: 80-95% total token reduction
    ```
  </Accordion>
</AccordionGroup>

## Cost Calculator

<Accordion title="Interactive Cost Calculator">
  ```python theme={null}
  import streamlit as st

  st.title("LLM Optimization Cost Calculator")

  # Inputs
  col1, col2 = st.columns(2)

  with col1:
      avg_tokens = st.number_input("Average tokens per request", value=5000, step=100)
      requests_per_day = st.number_input("Requests per day", value=1000, step=100)
      
  with col2:
      model = st.selectbox("Model", ["GPT-4", "GPT-4o", "Claude 3.5 Sonnet"])
      optimization = st.slider("Token reduction %", 0, 95, 60)

  # Pricing
  pricing = {
      "GPT-4": 0.03,
      "GPT-4o": 0.0025,
      "Claude 3.5 Sonnet": 0.003
  }

  cost_per_1k = pricing[model]

  # Calculate
  monthly_requests = requests_per_day * 30
  yearly_requests = requests_per_day * 365

  # Baseline
  baseline_monthly = (avg_tokens / 1000) * cost_per_1k * monthly_requests
  baseline_yearly = (avg_tokens / 1000) * cost_per_1k * yearly_requests

  # Optimized
  optimized_tokens = avg_tokens * (1 - optimization / 100)
  optimized_monthly = (optimized_tokens / 1000) * cost_per_1k * monthly_requests
  optimized_yearly = (optimized_tokens / 1000) * cost_per_1k * yearly_requests

  # Display
  st.subheader("Cost Analysis")

  col1, col2, col3 = st.columns(3)

  with col1:
      st.metric("Monthly Baseline", f"${baseline_monthly:.2f}")
      st.metric("Monthly Optimized", f"${optimized_monthly:.2f}")
      st.metric("Monthly Savings", f"${baseline_monthly - optimized_monthly:.2f}", delta=f"-{optimization}%")

  with col2:
      st.metric("Yearly Baseline", f"${baseline_yearly:.2f}")
      st.metric("Yearly Optimized", f"${optimized_yearly:.2f}")
      st.metric("Yearly Savings", f"${baseline_yearly - optimized_yearly:.2f}", delta=f"-{optimization}%")

  with col3:
      st.metric("3-Year Baseline", f"${baseline_yearly * 3:.2f}")
      st.metric("3-Year Optimized", f"${optimized_yearly * 3:.2f}")
      st.metric("3-Year Savings", f"${(baseline_yearly - optimized_yearly) * 3:.2f}", delta=f"-{optimization}%")
  ```
</Accordion>

## Resources

<CardGroup cols={2}>
  <Card title="Toonify GitHub" icon="github" href="https://github.com/ScrapeGraphAI/toonify">
    TOON format library and examples
  </Card>

  <Card title="Headroom GitHub" icon="github" href="https://github.com/chopratejas/headroom">
    Context optimization framework
  </Card>

  <Card title="Example Apps" icon="folder" href="https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/llm_optimization_tools">
    Complete optimization demos
  </Card>

  <Card title="OpenAI Tokenizer" icon="calculator" href="https://platform.openai.com/tokenizer">
    Test token counting
  </Card>
</CardGroup>
