<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Scott Sauer</title><subtitle>Notes on AI systems, automation, homelab and cloud infrastructure, plus the fun projects I am building.</subtitle><id>https://scottdsauer.com/</id><link href="https://scottdsauer.com/" /><link rel="self" href="https://scottdsauer.com/feed.xml" /><updated>2026-12-06T00:00:00Z</updated><author><name>Scott Sauer</name></author><entry><title>Friends join forces: Anthropic ships a Terraform provider</title><id>https://scottdsauer.com/posts/anthropic-terraform-provider/</id><link href="https://scottdsauer.com/posts/anthropic-terraform-provider/" /><published>2026-12-06T00:00:00Z</published><updated>2026-12-06T00:00:00Z</updated><summary>I took Anthropic's new Terraform provider for a spin and built, changed, ran and tore down a Claude agent with plan and apply.</summary><category term="terraform" /><category term="claude" /><category term="llm" /><category term="agents" /><content type="html" xml:base="https://scottdsauer.com/posts/anthropic-terraform-provider/">&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="terraform-meets-claude.jpg" alt="Two cartoon characters walk arm in arm down a dirt path through a meadow at sunset: a purple figure made of the Terraform logo's blocks, winking, and a glowing orange starburst like Claude's logo, smiling." width="1376" height="768"&gt;&lt;/p&gt;
&lt;figcaption&gt;Terraform, meet Claude.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I thought I would cover this update since two of my favorite worlds are coming together. Anthropic just dropped a Terraform provider to public beta.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Anthropic Terraform provider manages Claude Platform resources as code. Changes to them go through the same review, plan, and apply workflow as your other infrastructure.&lt;/p&gt;
&lt;p&gt;— &lt;a href="https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/terraform"&gt;Anthropic's Terraform provider docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That's amazing: you can now use Terraform to bake AI agent deployments into your enterprise IT architecture, right next to the networks, clusters and IAM you already manage with it. Rather than just read the docs, I spent a Sunday morning trying it.&lt;/p&gt;
&lt;h2 id="whats-in-the-box"&gt;What's in the box&lt;/h2&gt;
&lt;p&gt;The provider is &lt;a href="https://registry.terraform.io/providers/anthropics/anthropic/latest/docs"&gt;&lt;code&gt;anthropics/anthropic&lt;/code&gt;&lt;/a&gt; on the Terraform Registry. Version 0.1.0 landed on December 3. It covers two broad areas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Your Anthropic organization:&lt;/strong&gt; workspaces and members, service accounts, workload identity federation (so CI can authenticate with no stored key), spend limits, webhooks, telemetry destinations and, on Enterprise, RBAC groups and roles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Claude Managed Agents:&lt;/strong&gt; agents, the cloud environments their tools run in, deployments, memory stores, skills, vaults for credentials, and MCP tunnels. Most of these are still &lt;code&gt;beta_&lt;/code&gt; resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It also speaks to Claude Platform on AWS, Claude on Google Cloud, and Amazon Bedrock through a &lt;code&gt;platform&lt;/code&gt; setting.&lt;/p&gt;
&lt;h2 id="the-test-build-change-run-destroy"&gt;The test: build, change, run, destroy&lt;/h2&gt;
&lt;p&gt;I installed Terraform and Anthropic's &lt;code&gt;ant&lt;/code&gt; CLI, signed in with &lt;code&gt;ant auth login&lt;/code&gt; (a browser sign-in, no API key to copy around) and started from Anthropic's quickstart: a sandbox environment with limited networking, and an agent on Claude Opus 5.5.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kr"&gt;provider&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;&amp;quot;anthropic&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;organization_id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;var.organization_id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;resource&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;&amp;quot;anthropic_beta_environment&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;&amp;quot;sandbox&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;tf-lab&amp;quot;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;cloud&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nb"&gt;networking&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nb"&gt;limited&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;allow_package_managers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;resource&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;&amp;quot;anthropic_beta_agent&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;&amp;quot;assistant&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;tf-lab-assistant&amp;quot;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;model&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;claude-opus-5-5&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;system&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;You are a concise, careful assistant.&amp;quot;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;(I've trimmed the tool configuration; the full quickstart is in the &lt;a href="https://github.com/anthropics/terraform-provider-anthropic/tree/main/examples/managed-agents/quickstart"&gt;provider's repo&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Plan and apply.&lt;/strong&gt; &lt;code&gt;terraform plan&lt;/code&gt; proposed two resources, and printed a warning naming the exact organization ID it was about to change. The &lt;code&gt;organization_id&lt;/code&gt; in the provider block is a guard: if your credentials belong to a different org, the run stops. Apply took about a second. A second &lt;code&gt;plan&lt;/code&gt; came back with &lt;code&gt;No changes&lt;/code&gt;, so there was no drift right out of the gate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Change the agent.&lt;/strong&gt; I added "Answer in three sentences or fewer" to the system prompt. The plan showed the old and new prompt side by side as an in-place update, and after apply the agent's &lt;code&gt;version&lt;/code&gt; went from 1 to 2. Every change publishes a new server-side version, which you can pin sessions to. A prompt change now gets the same pull request review as a firewall rule.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;~ resource &amp;quot;anthropic_beta_agent&amp;quot; &amp;quot;assistant&amp;quot; {
    ~ system  = &amp;quot;You are a concise, careful assistant.&amp;quot; -&amp;gt; &amp;quot;You are a concise, careful assistant. Answer in three sentences or fewer.&amp;quot;
    ~ version = 1 -&amp;gt; (known after apply)
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Run it.&lt;/strong&gt; Terraform defines agents; it doesn't talk to them. To prove the agent worked, I started one session from the &lt;code&gt;ant&lt;/code&gt; CLI with a $1 spending cap and asked what Terraform state stores and why it should be protected. Version 2 answered in exactly three sentences. List cost: 4 cents.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tear it down.&lt;/strong&gt; &lt;code&gt;terraform destroy&lt;/code&gt; refused. Deletion protection is on by default for agents and environments, and the error explains what you'd lose: deleting an environment can't be undone, and archiving an agent also archives every deployment of it. Setting &lt;code&gt;deletion_protection = false&lt;/code&gt;, applying, then destroying cleaned everything up.&lt;/p&gt;
&lt;h2 id="things-to-know-before-you-use-it-at-work"&gt;Things to know before you use it at work&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It's a beta.&lt;/strong&gt; Resource types and arguments can change. Commit &lt;code&gt;.terraform.lock.hcl&lt;/code&gt; so you choose when to take a new version.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State holds your prompts.&lt;/strong&gt; Terraform state and plan files store system prompts, tool schemas, memory contents and skill files in plain text. Treat state like the sensitive thing it is: a remote backend with encryption and access control.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secrets stay out of state, if you let them.&lt;/strong&gt; Arguments ending in &lt;code&gt;_wo&lt;/code&gt; (such as vault credential secrets) are write-only and never saved to state. They need Terraform 1.11 or later, and you should feed them from &lt;code&gt;ephemeral&lt;/code&gt; variables so they don't land in a saved plan.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use federation in pipelines.&lt;/strong&gt; Anthropic recommends workload identity federation for CI rather than long-lived keys, and the provider can set up the federation pieces itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nothing moves.&lt;/strong&gt; An agent can't move to another workspace, region or cloud. You recreate it, or import an existing one.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-im-excited-miai-as-code"&gt;Why I'm excited: MiAi as code&lt;/h2&gt;
&lt;p&gt;This is where it gets personal. &lt;a href="/posts/miai-overview/"&gt;MiAi&lt;/a&gt;, my own AI portal, runs on hardware in my house today: a web app, a database, and an assistant built on Claude. Running it at home is cheap, which is exactly why I built it there. It's where I test ideas without a cloud bill ticking in the background.&lt;/p&gt;
&lt;p&gt;With this provider, the Claude side of MiAi can be code too: the agent, its system prompt, its tools and its memory, versioned and reviewed like everything else. Terraform is cloud-agnostic, with providers for AWS, Google Cloud, Azure and the homelab gear I already run, so the same workflow can describe both the infrastructure MiAi runs on and the AI it runs. The resource blocks for each cloud are different, but the tool, the plan-and-apply process and the state stay the same.&lt;/p&gt;
&lt;p&gt;That makes a nice path. Build and test on inexpensive infrastructure at home, and keep the costs down while things are still changing every day. When something is ready for real users, use Terraform to stand it up in a more robust cloud environment, with redundancy and scale that a box in my basement can't offer. The agent definition I tested at home is the same code that ships, so what I tested is what I deploy.&lt;/p&gt;
&lt;p&gt;For anyone who lives in Terraform, an AI agent is now just another piece of infrastructure. That's what it looks like when friends join forces.&lt;/p&gt;</content></entry><entry><title>MiAi: my own AI portal, starting with my health</title><id>https://scottdsauer.com/posts/miai-overview/</id><link href="https://scottdsauer.com/posts/miai-overview/" /><published>2026-12-05T00:00:00Z</published><updated>2026-12-05T00:00:00Z</updated><summary>Why I started building MiAi, and how the first area came together, from a health dashboard to an AI coach that reads my own workout data.</summary><category term="miai" /><category term="claude" /><category term="health" /><content type="html" xml:base="https://scottdsauer.com/posts/miai-overview/">&lt;p&gt;I started the idea of MiAi (My AI, get it?) 10 months ago while traveling to Cary, NC for a family visit. I
had been using various AI platforms to understand what they were, how they worked and what made them
different. Everything I worked on felt fragmented and not tied together. I needed some way to bring it all
into one unified interface or control point instead of managing all of these separate projects.&lt;/p&gt;
&lt;p&gt;Wouldn't it be cool to have my own AI portal that brings all of the "stuff" I care about into one place? I
started playing around with the idea and figured I would start with a meaningful sub-project: my health
metrics.&lt;/p&gt;
&lt;p&gt;I have been an Apple Health user for over a decade, so I have a plethora of metrics to tap into. I am a
Peloton OG; my wife and I own two bikes, a Peloton treadmill and a Peloton rower. A year ago I invested in a
Tonal (look it up, I love it) and have been working it into my routine. The Tonal is pretty cool because,
unlike Peloton, you can actually "write" to the platform and build your own workouts. Peloton classes are
instructor-led, so in technical terms Peloton is read-only.&lt;/p&gt;
&lt;p&gt;Enter MiAi.&lt;/p&gt;
&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="miai-home.jpg" alt="The MiAi home page: a greeting, Health and Wealth area cards, and a grid of templates for other life areas such as Education, Family, Home, Travel and Work &amp;amp; Career." width="1085" height="566"&gt;&lt;/p&gt;
&lt;figcaption&gt;The MiAi home page. Health is the first area; the templates are the areas still to come.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I started with a basic dashboard of the metrics I was pulling into the platform. I still need to play
around with the layout, but the metrics are all in and looking good. Getting the Apple Health data out of
my iPhone was a story of its own, which I wrote up in
&lt;a href="/posts/apple-health-data-feed/"&gt;Getting my Apple Health data out of my iPhone&lt;/a&gt;.&lt;/p&gt;
&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="health-dashboard.jpg" alt="The MiAi Health dashboard: a readiness score, tiles for resting heart rate, HRV, sleep, Tonal strength score, active calories and VO2 max, and charts for training minutes and sleep stages." width="1200" height="620"&gt;&lt;/p&gt;
&lt;figcaption&gt;The Health dashboard, pulling from Apple Health, Tonal and Peloton.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Next, I added an Anthropic AI agent to serve as a "virtual coach" for this section. Setting up a deployed
agent, including its billing configuration, was a new experience for me, and I found it fascinating. I also
"trained" the model a bit: I had a research agent gather validated health best practices to use as a
reference and baseline. To keep my data feeds fresh while building Tonal workouts, I put the data sync at
the top of the MiAi chat, as shown in the screenshot below.&lt;/p&gt;
&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="coach-chat.jpg" alt="The MiAi chat open over the Health page, with sync status for Tonal, Peloton and Apple Health at the top and the coach planning a rest day after a hard strength session." width="1200" height="629"&gt;&lt;/p&gt;
&lt;figcaption&gt;The coach, with sync status for each data source at the top of the chat.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now comes the fun part: doing the hard work and generating data with my workouts! I am enjoying testing the
virtual coach and having it review my own health metrics. It seems to be insightful. I have it configured
to use a lower-tier model for basic Q&amp;amp;A and a higher-tier model for schedule building and more complex
tasks. That, combined with the caching I set up, helps keep operating costs down. I put real numbers on
that in &lt;a href="/posts/cutting-ai-costs/"&gt;Cutting my AI assistant's bill by 68%&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Health is just the first area. Wealth is already in progress, and the templates on that home page are
next. I'll write about them as they come together.&lt;/p&gt;</content></entry><entry><title>Cutting my AI assistant's bill by 68%</title><id>https://scottdsauer.com/posts/cutting-ai-costs/</id><link href="https://scottdsauer.com/posts/cutting-ai-costs/" /><published>2026-12-04T00:00:00Z</published><updated>2026-12-04T00:00:00Z</updated><summary>Prompt caching, a local database behind the tools, and two model tiers, measured against real usage logs.</summary><category term="llm" /><category term="claude" /><category term="homelab" /><category term="cost" /><content type="html" xml:base="https://scottdsauer.com/posts/cutting-ai-costs/">&lt;p&gt;MiAi is the personal platform I run at home: a FastAPI service over Postgres/Timescale, a React front end, and modules for health, wealth and career. Running through all of it is an assistant built on the Claude API. It reads my training history, answers questions about my data, and designs strength workouts that it pushes to my Tonal.&lt;/p&gt;
&lt;p&gt;An assistant like that can get expensive quickly. Each turn re-sends a long system prompt, a dozen tool definitions and the whole conversation so far. If you also paste the user's data into the prompt "so the model has context," the bill grows with every row in the database. I built three cost controls into MiAi from the start. This post walks through each one and then checks them against the token counts MiAi logs for every reply.&lt;/p&gt;
&lt;p class="note"&gt;&lt;b&gt;Updated December 6:&lt;/b&gt; two days later I re-checked the numbers with more conversations logged. Caching still saves 69%, but a growing conversation had started to eat into it. See &lt;a href="#update-december-6-the-conversation-kept-growing"&gt;the update&lt;/a&gt; for what I found and fixed.&lt;/p&gt;

&lt;div class="stats"&gt;
  &lt;div class="stat"&gt;&lt;b&gt;$3.21&lt;/b&gt;&lt;span&gt;actual spend, 52 API calls&lt;/span&gt;&lt;/div&gt;
  &lt;div class="stat"&gt;&lt;b&gt;$10.12&lt;/b&gt;&lt;span&gt;same calls, all Opus, no cache&lt;/span&gt;&lt;/div&gt;
  &lt;div class="stat save"&gt;&lt;b&gt;$6.91&lt;/b&gt;&lt;span&gt;saved (68%)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id="the-standard-setup-and-what-i-built-instead"&gt;The standard setup, and what I built instead&lt;/h2&gt;
&lt;p&gt;The usual first version of an assistant has one model for everything (the biggest, to be safe), no caching, and context stuffing: the app gathers whatever data might be relevant and puts it in the prompt. It is simple and it works. It is also the most expensive way to call an LLM, because you pay the full input price for the same tokens over and over.&lt;/p&gt;
&lt;figure class="figure wide"&gt;
  &lt;div class="scroll"&gt;
    &lt;svg viewBox="0 0 960 560" role="img" aria-labelledby="archTitle archDesc"&gt;
      &lt;title id="archTitle"&gt;Standard architecture compared with MiAi's cost-optimized architecture&lt;/title&gt;
      &lt;desc id="archDesc"&gt;Left: every request sends the system prompt, tools, history and pasted data to Opus at full input price. Right: requests go to Sonnet by default, escalate to Opus for workout design, read a cached prefix, and fetch small tool results from local Postgres.&lt;/desc&gt;
      &lt;defs&gt;
        &lt;marker id="arr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"&gt;
          &lt;path d="M0,0 L10,5 L0,10 z" style="fill:var(--muted)"/&gt;
        &lt;/marker&gt;
      &lt;/defs&gt;
      &lt;!-- Column headings --&gt;
      &lt;text x="20" y="30" class="svg-head" font-size="20"&gt;Standard&lt;/text&gt;
      &lt;text x="20" y="50" class="svg-muted" font-size="12"&gt;one model · no cache · data pasted into the prompt&lt;/text&gt;
      &lt;text x="500" y="30" class="svg-head" font-size="20"&gt;MiAi&lt;/text&gt;
      &lt;text x="500" y="50" class="svg-muted" font-size="12"&gt;two tiers · cached prefix · tools over local Postgres&lt;/text&gt;
      &lt;line x1="480" y1="16" x2="480" y2="540" style="stroke:var(--rule)" stroke-width="1.5" stroke-dasharray="4 5"/&gt;
      &lt;!-- ===== Standard ===== --&gt;
      &lt;rect x="20" y="74" width="140" height="44" rx="8" style="fill:var(--surface);stroke:var(--muted)" stroke-width="1.2"/&gt;
      &lt;text x="90" y="101" text-anchor="middle" class="svg-text" font-size="13"&gt;Your message&lt;/text&gt;
      &lt;line x1="90" y1="118" x2="90" y2="148" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;!-- request stack, all full price --&gt;
      &lt;text x="20" y="166" class="svg-muted" font-size="11"&gt;EVERY REQUEST SENDS&lt;/text&gt;
      &lt;rect x="20" y="174" width="300" height="34" rx="5" style="fill:var(--hot-soft);stroke:var(--hot)" stroke-width="1"/&gt;
      &lt;text x="32" y="196" class="svg-text" font-size="12"&gt;Tool definitions&lt;/text&gt;
      &lt;text x="308" y="196" text-anchor="end" class="svg-muted" font-size="11"&gt;full price&lt;/text&gt;
      &lt;rect x="20" y="212" width="300" height="34" rx="5" style="fill:var(--hot-soft);stroke:var(--hot)" stroke-width="1"/&gt;
      &lt;text x="32" y="234" class="svg-text" font-size="12"&gt;System prompt + knowledge index&lt;/text&gt;
      &lt;text x="308" y="234" text-anchor="end" class="svg-muted" font-size="11"&gt;full price&lt;/text&gt;
      &lt;rect x="20" y="250" width="300" height="34" rx="5" style="fill:var(--hot-soft);stroke:var(--hot)" stroke-width="1"/&gt;
      &lt;text x="32" y="272" class="svg-text" font-size="12"&gt;Whole conversation so far&lt;/text&gt;
      &lt;text x="308" y="272" text-anchor="end" class="svg-muted" font-size="11"&gt;full price&lt;/text&gt;
      &lt;rect x="20" y="288" width="300" height="96" rx="5" style="fill:var(--hot-soft);stroke:var(--hot)" stroke-width="1.6"/&gt;
      &lt;text x="32" y="312" class="svg-text" font-size="12" font-weight="600"&gt;Pasted user data&lt;/text&gt;
      &lt;text x="32" y="332" class="svg-muted" font-size="11"&gt;workouts, vitals, accounts, notes…&lt;/text&gt;
      &lt;text x="32" y="350" class="svg-muted" font-size="11"&gt;grows with the database&lt;/text&gt;
      &lt;text x="32" y="370" class="svg-muted" font-size="11"&gt;~300k tokens/turn (estimate)&lt;/text&gt;
      &lt;line x1="320" y1="280" x2="352" y2="280" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;rect x="356" y="238" width="104" height="84" rx="10" style="fill:var(--opus-soft);stroke:var(--opus)" stroke-width="1.6"/&gt;
      &lt;text x="408" y="270" text-anchor="middle" class="svg-head" font-size="15" style="fill:var(--opus)"&gt;Opus&lt;/text&gt;
      &lt;text x="408" y="290" text-anchor="middle" class="svg-muted" font-size="11"&gt;every turn&lt;/text&gt;
      &lt;text x="408" y="306" text-anchor="middle" class="svg-muted" font-size="11"&gt;$4 in / $20 out&lt;/text&gt;
      &lt;rect x="20" y="420" width="440" height="100" rx="10" style="fill:var(--hot-soft)"/&gt;
      &lt;text x="40" y="452" class="svg-head" font-size="15" style="fill:var(--hot)"&gt;Cost drivers&lt;/text&gt;
      &lt;text x="40" y="476" class="svg-text" font-size="12"&gt;Same prefix billed at full input price, every call&lt;/text&gt;
      &lt;text x="40" y="496" class="svg-text" font-size="12"&gt;Simple chat priced like hard planning&lt;/text&gt;
      &lt;text x="40" y="512" class="svg-muted" font-size="11"&gt;Measured on MiAi's 52 calls (no data pasting): $10.12&lt;/text&gt;
      &lt;!-- ===== MiAi ===== --&gt;
      &lt;rect x="500" y="74" width="140" height="44" rx="8" style="fill:var(--surface);stroke:var(--muted)" stroke-width="1.2"/&gt;
      &lt;text x="570" y="101" text-anchor="middle" class="svg-text" font-size="13"&gt;Your message&lt;/text&gt;
      &lt;line x1="570" y1="118" x2="570" y2="148" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;text x="500" y="166" class="svg-muted" font-size="11"&gt;REQUEST&lt;/text&gt;
      &lt;rect x="500" y="174" width="250" height="34" rx="5" style="fill:var(--accent-soft);stroke:var(--accent)" stroke-width="1"/&gt;
      &lt;text x="512" y="196" class="svg-text" font-size="12"&gt;Tools + system + index&lt;/text&gt;
      &lt;text x="740" y="196" text-anchor="end" class="svg-muted" font-size="11"&gt;cache, 1 h&lt;/text&gt;
      &lt;rect x="500" y="212" width="250" height="34" rx="5" style="fill:var(--accent-soft);stroke:var(--accent)" stroke-width="1"/&gt;
      &lt;text x="512" y="234" class="svg-text" font-size="12"&gt;Earlier turns + tool steps&lt;/text&gt;
      &lt;text x="740" y="234" text-anchor="end" class="svg-muted" font-size="11"&gt;cache, 5 min&lt;/text&gt;
      &lt;rect x="500" y="250" width="250" height="34" rx="5" style="fill:var(--hot-soft);stroke:var(--hot)" stroke-width="1"/&gt;
      &lt;text x="512" y="272" class="svg-text" font-size="12"&gt;New message only&lt;/text&gt;
      &lt;text x="740" y="272" text-anchor="end" class="svg-muted" font-size="11"&gt;full price&lt;/text&gt;
      &lt;text x="500" y="302" class="svg-muted" font-size="11"&gt;cache read: $0.20 per million tokens&lt;/text&gt;
      &lt;!-- router --&gt;
      &lt;line x1="750" y1="230" x2="780" y2="230" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;rect x="784" y="74" width="156" height="78" rx="10" style="fill:var(--accent-soft);stroke:var(--accent)" stroke-width="1.6"/&gt;
      &lt;text x="862" y="104" text-anchor="middle" class="svg-head" font-size="15" style="fill:var(--accent)"&gt;Sonnet&lt;/text&gt;
      &lt;text x="862" y="122" text-anchor="middle" class="svg-muted" font-size="11"&gt;chat, Q&amp;amp;A, lookups&lt;/text&gt;
      &lt;text x="862" y="138" text-anchor="middle" class="svg-muted" font-size="11"&gt;$2 in / $10 out&lt;/text&gt;
      &lt;rect x="784" y="196" width="156" height="68" rx="8" style="fill:var(--surface);stroke:var(--muted)" stroke-width="1.2"/&gt;
      &lt;text x="862" y="222" text-anchor="middle" class="svg-text" font-size="12" font-weight="600"&gt;Workout design?&lt;/text&gt;
      &lt;text x="862" y="242" text-anchor="middle" class="svg-muted" font-size="11"&gt;recommend_workout&lt;/text&gt;
      &lt;text x="862" y="256" text-anchor="middle" class="svg-muted" font-size="11"&gt;called → escalate&lt;/text&gt;
      &lt;line x1="862" y1="196" x2="862" y2="156" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;text x="870" y="180" class="svg-muted" font-size="10"&gt;no&lt;/text&gt;
      &lt;line x1="862" y1="264" x2="862" y2="300" style="stroke:var(--muted)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;text x="870" y="286" class="svg-muted" font-size="10"&gt;yes&lt;/text&gt;
      &lt;rect x="784" y="304" width="156" height="72" rx="10" style="fill:var(--opus-soft);stroke:var(--opus)" stroke-width="1.6"/&gt;
      &lt;text x="862" y="334" text-anchor="middle" class="svg-head" font-size="15" style="fill:var(--opus)"&gt;Opus&lt;/text&gt;
      &lt;text x="862" y="352" text-anchor="middle" class="svg-muted" font-size="11"&gt;workout plans only&lt;/text&gt;
      &lt;text x="862" y="366" text-anchor="middle" class="svg-muted" font-size="11"&gt;$4 in / $20 out&lt;/text&gt;
      &lt;!-- local DB --&gt;
      &lt;rect x="500" y="330" width="250" height="70" rx="10" style="fill:var(--surface);stroke:var(--accent)" stroke-width="1.6"/&gt;
      &lt;text x="625" y="358" text-anchor="middle" class="svg-head" font-size="14"&gt;Local Postgres&lt;/text&gt;
      &lt;text x="625" y="378" text-anchor="middle" class="svg-muted" font-size="11"&gt;health · wealth · career · ~16 MB&lt;/text&gt;
      &lt;text x="625" y="392" text-anchor="middle" class="svg-muted" font-size="11"&gt;stays on my server&lt;/text&gt;
      &lt;path d="M780,340 C765,340 765,365 754,365" fill="none" style="stroke:var(--accent)" stroke-width="1.5" marker-end="url(#arr)"/&gt;
      &lt;text x="756" y="322" class="svg-muted" font-size="10"&gt;tool call&lt;/text&gt;
      &lt;path d="M754,385 C770,385 770,400 780,400" fill="none" style="stroke:var(--accent)" stroke-width="1.5" stroke-dasharray="4 3"/&gt;
      &lt;text x="700" y="418" class="svg-muted" font-size="10"&gt;small result (~160 chars avg)&lt;/text&gt;
      &lt;rect x="500" y="430" width="440" height="90" rx="10" style="fill:var(--accent-soft)"/&gt;
      &lt;text x="520" y="460" class="svg-head" font-size="15" style="fill:var(--accent)"&gt;Result&lt;/text&gt;
      &lt;text x="520" y="484" class="svg-text" font-size="12"&gt;Repeated prefix billed at the cache-read rate&lt;/text&gt;
      &lt;text x="520" y="504" class="svg-text" font-size="12"&gt;Opus only where it earns its price · data fetched on demand&lt;/text&gt;
      &lt;text x="920" y="460" text-anchor="end" class="svg-head" font-size="20" style="fill:var(--accent)"&gt;$3.21&lt;/text&gt;
    &lt;/svg&gt;
  &lt;/div&gt;
  &lt;figcaption&gt;Figure 1. The standard pattern compared with MiAi. Prices are per million tokens. The $10.12 and $3.21 figures come from the same 52 logged calls, repriced. The 300k-token figure for pasted data is an estimate, not a measurement.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id="lever-1-prompt-caching"&gt;Lever 1: prompt caching&lt;/h2&gt;
&lt;p&gt;Every Messages API request is processed as one long sequence in a fixed order: &lt;strong&gt;tools → system → messages&lt;/strong&gt;. Prompt caching lets the API store the processed state of a prefix of that sequence and reuse it on later requests. You mark where a cacheable prefix ends with a &lt;code&gt;cache_control&lt;/code&gt; breakpoint. A later request that starts with byte-for-byte the same prefix reads it from the cache instead of processing it again.&lt;/p&gt;
&lt;p&gt;The pricing makes this the biggest single lever. A cache read costs a small fraction of normal input. A cache write costs a bit more than normal input:&lt;/p&gt;
&lt;div class="table-wrap"&gt;
  &lt;table&gt;
    &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Per million tokens&lt;/th&gt;&lt;th class="num"&gt;Sonnet 5.5&lt;/th&gt;&lt;th class="num"&gt;Opus 5.5&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;Input (uncached)&lt;/td&gt;&lt;td class="num"&gt;$2.00&lt;/td&gt;&lt;td class="num"&gt;$4.00&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Cache write, 5-minute TTL (1.25×)&lt;/td&gt;&lt;td class="num"&gt;$2.50&lt;/td&gt;&lt;td class="num"&gt;$5.00&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Cache write, 1-hour TTL (2×)&lt;/td&gt;&lt;td class="num"&gt;$4.00&lt;/td&gt;&lt;td class="num"&gt;$8.00&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Cache read&lt;/td&gt;&lt;td class="num"&gt;$0.20&lt;/td&gt;&lt;td class="num"&gt;$0.20&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Output&lt;/td&gt;&lt;td class="num"&gt;$10.00&lt;/td&gt;&lt;td class="num"&gt;$20.00&lt;/td&gt;&lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;On Opus 5.5 a cache read costs 5% of normal input. Once a prefix is written, every later request that reuses it pays about one-twentieth of the normal input price for those tokens.&lt;/p&gt;
&lt;h3 id="two-breakpoints-two-lifetimes"&gt;Two breakpoints, two lifetimes&lt;/h3&gt;
&lt;p&gt;MiAi uses two of the four breakpoints a request allows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;An explicit 1-hour breakpoint on the static prefix.&lt;/strong&gt; The tool definitions, the system prompt and the knowledge-base index together come to about 9,000 tokens, and they don't change between turns. I talk to the assistant in bursts, often 5 to 60 minutes apart. A 5-minute entry would expire between most turns and be rewritten each time. The 1-hour TTL costs 2× to write instead of 1.25×, but it survives the gaps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automatic caching on the conversation tail.&lt;/strong&gt; A top-level &lt;code&gt;cache_control&lt;/code&gt; on the request moves the breakpoint to the last block every time. Within one turn the assistant may make several tool calls, and each step re-sends the whole history. With the moving breakpoint, each step reads everything before it from the cache.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# prompt.py: the static prefix gets the 1-hour breakpoint&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;system_blocks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;type&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SYSTEM&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;type&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s2"&gt;&amp;quot;cache_control&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;type&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;ephemeral&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;ttl&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;1h&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}}]&lt;/span&gt;

&lt;span class="c1"&gt;# agent.py: automatic caching follows the growing conversation&lt;/span&gt;
&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;cache_control&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;type&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;ephemeral&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;   &lt;span class="c1"&gt;# 5-minute, moves forward&lt;/span&gt;
             &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Order matters: an entry with a longer TTL has to come before one with a shorter TTL. A 1-hour prefix followed by a 5-minute tail is allowed. The reverse is not.&lt;/p&gt;
&lt;h3 id="the-break-even-arithmetic"&gt;The break-even arithmetic&lt;/h3&gt;
&lt;p&gt;A 5-minute entry pays for itself on the second request: 1.25× (write) + 0.1× (read) is less than 2× uncached. A 1-hour entry needs a third request: 2× + 2 × 0.05× on Opus is less than 3×. A typical turn in MiAi involves 2 to 4 API steps, and my conversations run several turns, so both entries clear break-even easily.&lt;/p&gt;
&lt;h3 id="silent-invalidators"&gt;Silent invalidators&lt;/h3&gt;
&lt;p&gt;The cache matches bytes, not meaning. Anything that changes the prefix, such as a timestamp in the system prompt, a reordered tool list or JSON serialized with keys in a different order, turns a cache read into a fresh write. Nothing returns an error. The only symptom is &lt;code&gt;usage.cache_read_input_tokens&lt;/code&gt; dropping to zero.&lt;/p&gt;
&lt;p class="note"&gt;MiAi hit exactly this. Message blocks were stored in a Postgres &lt;code&gt;jsonb&lt;/code&gt; column, and &lt;code&gt;jsonb&lt;/code&gt; re-sorts object keys on write. When the history was replayed, the bytes no longer matched what had been cached, so every turn rewrote the conversation. Switching the column to plain &lt;code&gt;json&lt;/code&gt;, which keeps key order, fixed it. The bug wasted about 31,000 tokens, roughly $0.15, before I noticed. It was cheap only because I was logging usage per message and checked it.&lt;/p&gt;

&lt;p&gt;That logging is the key point. Every assistant reply in MiAi stores the full &lt;code&gt;usage&lt;/code&gt; object (input, output, cache read, cache write broken down by 5-minute and 1-hour TTL) next to a computed &lt;code&gt;cost_usd&lt;/code&gt;. Without it I would never have seen the bug, and I couldn't have written this post.&lt;/p&gt;
&lt;h2 id="lever-2-keep-the-data-local-and-let-tools-fetch-it"&gt;Lever 2: keep the data local and let tools fetch it&lt;/h2&gt;
&lt;p&gt;The assistant does not get my data in its prompt. It gets tools. &lt;code&gt;query_health&lt;/code&gt;, the &lt;code&gt;career_*&lt;/code&gt; tools, the wealth tools and &lt;code&gt;consult_knowledge&lt;/code&gt; all run SQL against the Postgres instance on my own server and return only the rows the question needs. The model decides what to look up, and the database does the filtering.&lt;/p&gt;
&lt;p&gt;The difference in volume is large. Across the logged calls, 32 tool results reached the model, totalling &lt;strong&gt;5,051 characters&lt;/strong&gt;, about 1,300 tokens. Behind those tools sit roughly &lt;strong&gt;16 MB&lt;/strong&gt; of local data: health 5.4 MB, career 1.6 MB, wealth 1.1 MB, and 7.8 MB of core tables.&lt;/p&gt;
&lt;p&gt;The context-stuffing alternative never ran, so I can't measure it. As a rough illustration: the health data alone is about 4,900 rows. Serialized into a prompt that is on the order of 300,000 tokens, about $0.60 per turn on Sonnet before output, against roughly $0.06 for an average MiAi turn today. Over the same 52 calls that would be on the order of $30. Treat that number as an estimate of scale, not a measurement.&lt;/p&gt;
&lt;p&gt;There are benefits beyond cost:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Privacy.&lt;/strong&gt; Only the few rows a question needs leave my network, not the whole database.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache stability.&lt;/strong&gt; Pasted data changes whenever a new workout syncs, which would invalidate the cached prefix on every turn. Tool results land at the end of the conversation, after the breakpoint.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accuracy.&lt;/strong&gt; The model reads a precise query result instead of searching for one number in a 300k-token dump.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="lever-3-two-model-tiers"&gt;Lever 3: two model tiers&lt;/h2&gt;
&lt;p&gt;Most of what I ask the assistant is ordinary: what did I lift last Tuesday, how is my resting heart rate trending, what's due this week. That doesn't need the most capable model. Designing a strength workout does. It has to balance muscle readiness, recent volume, equipment changes and the vetted training guidance in the knowledge base, and a weak plan is worse than none.&lt;/p&gt;
&lt;p&gt;MiAi splits the work along that line:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sonnet 5.5&lt;/strong&gt; (&lt;code&gt;MIAI_COACH_MODEL&lt;/code&gt;) handles every turn by default, at half of Opus's input and output price.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Opus 5.5&lt;/strong&gt; (&lt;code&gt;MIAI_COACH_PLAN_MODEL&lt;/code&gt;) takes over when planning starts. As soon as a step calls a planning tool, the rest of that turn runs on Opus.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The escalation has one guard. If Sonnet tries to call &lt;code&gt;recommend_workout&lt;/code&gt; itself, MiAi discards that draft and re-issues the same request on Opus, so every stored workout plan comes from Opus. The discarded step is still saved as a cost-only row, so its spend shows up in the totals.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;PLAN_MODEL&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;recommend_workout&amp;quot;&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# The chat model drafted a plan: drop it and re-run this step on Opus.&lt;/span&gt;
  &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PLAN_MODEL&lt;/span&gt;
  &lt;span class="n"&gt;save_cost_only_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# the discarded draft is still counted&lt;/span&gt;
  &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p class="note"&gt;There is a trade-off. Caches are per model, so the first Opus step in a turn can't read Sonnet's cache and writes its own copy of the prefix. Workout requests are a small share of turns, and the 1-hour entry on the Opus side is then reused across a planning session, so the cost is small. But a design that switched models on every turn would lose much of its caching benefit.&lt;/p&gt;

&lt;p class="note"&gt;&lt;b&gt;December 6 correction:&lt;/b&gt; "the cost is small" held only while conversations were short. The first Opus step writes the whole conversation history to its cache, not just the prefix, and by December 6 that history was over 100,000 tokens. The update below covers the fix.&lt;/p&gt;

&lt;h2 id="the-numbers"&gt;The numbers&lt;/h2&gt;
&lt;p&gt;MiAi has logged 52 API calls with full usage data so far (December 3–4): 36 on Opus, 16 on Sonnet. To isolate each lever I repriced exactly the same token counts under different assumptions. "No cache" means every cache-read and cache-write token billed as normal input.&lt;/p&gt;
&lt;figure class="figure chart"&gt;
  &lt;div class="scroll"&gt;
    &lt;svg viewBox="0 0 640 250" role="img" aria-labelledby="barTitle"&gt;
      &lt;title id="barTitle"&gt;Cost of the same 52 API calls under four setups&lt;/title&gt;
      &lt;!-- scale: $0 at x=210, $12 at x=600 → 32.5 px per dollar --&gt;
      &lt;g style="stroke:var(--rule)" stroke-width="1"&gt;
        &lt;line x1="210" y1="20" x2="210" y2="210"/&gt;
        &lt;line x1="372.5" y1="20" x2="372.5" y2="210" stroke-dasharray="3 4"/&gt;
        &lt;line x1="535" y1="20" x2="535" y2="210" stroke-dasharray="3 4"/&gt;
      &lt;/g&gt;
      &lt;text x="210" y="230" text-anchor="middle" class="svg-muted" font-size="11"&gt;$0&lt;/text&gt;
      &lt;text x="372.5" y="230" text-anchor="middle" class="svg-muted" font-size="11"&gt;$5&lt;/text&gt;
      &lt;text x="535" y="230" text-anchor="middle" class="svg-muted" font-size="11"&gt;$10&lt;/text&gt;
      &lt;text x="200" y="47" text-anchor="end" class="svg-text" font-size="12"&gt;All Opus, no cache&lt;/text&gt;
      &lt;rect x="210" y="30" width="328.9" height="26" rx="3" style="fill:var(--hot)"/&gt;
      &lt;text x="546" y="48" class="svg-text" font-size="12" font-weight="600"&gt;$10.12&lt;/text&gt;
      &lt;text x="200" y="95" text-anchor="end" class="svg-text" font-size="12"&gt;Two tiers, no cache&lt;/text&gt;
      &lt;rect x="210" y="78" width="245.7" height="26" rx="3" style="fill:var(--hot);opacity:0.7"/&gt;
      &lt;text x="463" y="96" class="svg-text" font-size="12" font-weight="600"&gt;$7.56&lt;/text&gt;
      &lt;text x="200" y="143" text-anchor="end" class="svg-text" font-size="12"&gt;All Opus, cached&lt;/text&gt;
      &lt;rect x="210" y="126" width="126.8" height="26" rx="3" style="fill:var(--opus)"/&gt;
      &lt;text x="345" y="144" class="svg-text" font-size="12" font-weight="600"&gt;$3.90&lt;/text&gt;
      &lt;text x="200" y="191" text-anchor="end" class="svg-text" font-size="12" font-weight="600"&gt;Actual (both)&lt;/text&gt;
      &lt;rect x="210" y="174" width="104.3" height="26" rx="3" style="fill:var(--accent)"/&gt;
      &lt;text x="322" y="192" class="svg-text" font-size="12" font-weight="600"&gt;$3.21&lt;/text&gt;
    &lt;/svg&gt;
  &lt;/div&gt;
  &lt;figcaption&gt;Figure 2. The same 52 calls repriced under each setup, drawn to scale. Prices come from MiAi's pricing table, which matches Anthropic's published rates for these models.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;div class="table-wrap"&gt;
  &lt;table&gt;
    &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Setup&lt;/th&gt;&lt;th class="num"&gt;Cost&lt;/th&gt;&lt;th&gt;Lever isolated&lt;/th&gt;&lt;th class="num"&gt;Saved&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr class="actual"&gt;&lt;td&gt;Actual: two tiers, caching on&lt;/td&gt;&lt;td class="num"&gt;$3.21&lt;/td&gt;&lt;td&gt;—&lt;/td&gt;&lt;td class="num"&gt;—&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Two tiers, no caching&lt;/td&gt;&lt;td class="num"&gt;$7.56&lt;/td&gt;&lt;td&gt;Caching&lt;/td&gt;&lt;td class="num"&gt;$4.36 (58%)&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Caching on, every call on Opus&lt;/td&gt;&lt;td class="num"&gt;$3.90&lt;/td&gt;&lt;td&gt;Model tiers&lt;/td&gt;&lt;td class="num"&gt;$0.69 (18%)&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Every call on Opus, no caching&lt;/td&gt;&lt;td class="num"&gt;$10.12&lt;/td&gt;&lt;td&gt;Both&lt;/td&gt;&lt;td class="num"&gt;$6.91 (68%)&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Data pasted into every prompt&lt;/td&gt;&lt;td class="num"&gt;~$30+&lt;/td&gt;&lt;td&gt;Local DB (estimate)&lt;/td&gt;&lt;td class="num"&gt;not measured&lt;/td&gt;&lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Caching did most of the work.&lt;/strong&gt; About 2.3 million input tokens were cache reads or writes. Billed as normal input they would have cost $4.36 more.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The tier saving understates the steady state.&lt;/strong&gt; On the 16 Sonnet calls, the tiering saved 44%. It looks small overall only because Sonnet became the chat model partway through December 3, so most of the 36 Opus calls are chat from before the switch. From now on, only workout design runs on Opus, so the tier saving on future usage should land near that 44%.&lt;/p&gt;
&lt;h2 id="update-december-6-the-conversation-kept-growing"&gt;Update, December 6: the conversation kept growing&lt;/h2&gt;
&lt;p&gt;Two days after I first wrote this post, I re-ran the same analysis with 10 more calls logged. The headline held up:&lt;/p&gt;
&lt;div class="table-wrap"&gt;
  &lt;table&gt;
    &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Period&lt;/th&gt;&lt;th class="num"&gt;Calls&lt;/th&gt;&lt;th class="num"&gt;Actual&lt;/th&gt;&lt;th class="num"&gt;All Opus, no cache&lt;/th&gt;&lt;th class="num"&gt;Saved&lt;/th&gt;&lt;th class="num"&gt;Cache hit rate&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;December 3–4 (above)&lt;/td&gt;&lt;td class="num"&gt;52&lt;/td&gt;&lt;td class="num"&gt;$3.21&lt;/td&gt;&lt;td class="num"&gt;$10.12&lt;/td&gt;&lt;td class="num"&gt;68%&lt;/td&gt;&lt;td class="num"&gt;78%&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;December 6&lt;/td&gt;&lt;td class="num"&gt;10&lt;/td&gt;&lt;td class="num"&gt;$1.37&lt;/td&gt;&lt;td class="num"&gt;$4.45&lt;/td&gt;&lt;td class="num"&gt;69%&lt;/td&gt;&lt;td class="num"&gt;70%&lt;/td&gt;&lt;/tr&gt;
      &lt;tr class="actual"&gt;&lt;td&gt;All time&lt;/td&gt;&lt;td class="num"&gt;62&lt;/td&gt;&lt;td class="num"&gt;$4.57&lt;/td&gt;&lt;td class="num"&gt;$14.57&lt;/td&gt;&lt;td class="num"&gt;69%&lt;/td&gt;&lt;td class="num"&gt;76%&lt;/td&gt;&lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;The percentage hid a trend. MiAi keeps one running conversation per area until I start a new topic, and I never had. The cached history had grown from 64,000 tokens on December 3 to 98,000 on December 4 and 115,000 on December 6. Most of it was old tool results: Tonal movement searches and health queries from days earlier that Claude didn't need anymore.&lt;/p&gt;
&lt;p&gt;A cache miss means rewriting the whole history, and a bigger history makes every miss cost more. Three misses made up &lt;strong&gt;82% of December 6's spend&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="table-wrap"&gt;
  &lt;table&gt;
    &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Time&lt;/th&gt;&lt;th&gt;What happened&lt;/th&gt;&lt;th class="num"&gt;Cost&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;&lt;td&gt;09:26&lt;/td&gt;&lt;td&gt;First message after a day and a half away. The cache had expired, as expected.&lt;/td&gt;&lt;td class="num"&gt;$0.28&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;09:27&lt;/td&gt;&lt;td&gt;Escalated to Opus for a workout. Caches are per model, so Opus wrote all 102,000 tokens of history.&lt;/td&gt;&lt;td class="num"&gt;$0.58&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;09:41&lt;/td&gt;&lt;td&gt;Six minutes after my previous message, just past the 5-minute TTL.&lt;/td&gt;&lt;td class="num"&gt;$0.26&lt;/td&gt;&lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;The 1-hour prefix did its job. At 09:41 the tools and system prompt were still read from cache; only the history had expired.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The obvious fix was the wrong one.&lt;/strong&gt; Moving the history to the 1-hour TTL would have caught the 09:41 miss. I repriced all 62 calls that way and it came out &lt;em&gt;more&lt;/em&gt; expensive, $5.50 instead of $4.57, because every history write would cost 2× instead of 1.25×. The writes outnumber the misses it saves.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The real fix is to keep the history small.&lt;/strong&gt; I made two changes to MiAi:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Compact at cold starts.&lt;/strong&gt; When I come back after more than 5 minutes, the history cache has expired anyway, so the next request has to write it in full regardless. That's the free moment to shrink it. Earlier sessions are replayed in compact form: old tool results become a one-line placeholder ("call the tool again if you need this data"), old data snapshots and old reasoning are dropped, and my words, Claude's answers and the record of which tools ran all stay. The cut-off point is worked out from the saved message timestamps, so the next warm turn computes the same cut-off and sends exactly the same bytes. Compacting never breaks a warm cache.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Give Opus a compact history.&lt;/strong&gt; When a turn moves to Opus for workout design, Opus gets earlier turns in compact form and the current turn in full. I considered asking a model to write a summary, but that's another API call, and its output would differ every time. Compacting is free, deterministic and cacheable.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To check the effect without spending anything, I replayed the real conversation through Anthropic's token-counting endpoint, which is free and also confirms the API accepts the compacted history:&lt;/p&gt;
&lt;div class="stats"&gt;
  &lt;div class="stat"&gt;&lt;b&gt;111,899&lt;/b&gt;&lt;span&gt;tokens, full history&lt;/span&gt;&lt;/div&gt;
  &lt;div class="stat save"&gt;&lt;b&gt;36,668&lt;/b&gt;&lt;span&gt;tokens, compacted (67% smaller)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Applied to December 6's calls, that would have cut the day from &lt;strong&gt;$1.37 to about $0.61&lt;/strong&gt;, 55% less, on top of what caching already saved. The Opus escalation alone drops from $0.58 to about $0.25. That's an estimate: it only shrinks history from before that day, so the real saving should be a little larger. The next few days of usage logs will show the real number.&lt;/p&gt;
&lt;p&gt;The lesson: a cache hit rate tells you how often you reuse tokens, not how many tokens you're carrying. If the thing you cache keeps growing, the misses get more expensive even when the hit rate looks fine.&lt;/p&gt;
&lt;h2 id="caveats"&gt;Caveats&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Small sample.&lt;/strong&gt; Two days and 52 calls. The dollar amounts are small, and the percentages are what will carry forward.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repricing, not A/B testing.&lt;/strong&gt; The counterfactual costs reprice the same token counts. A real no-cache run would have the same tokens, so for caching the comparison holds. For tiers, Opus might write shorter or longer answers than Sonnet, which I haven't measured.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The local-database figure is an estimate.&lt;/strong&gt; The context-stuffing version was never built.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prices are list prices&lt;/strong&gt; from MiAi's pricing table, checked against Anthropic's published rates for Sonnet 5.5 and Opus 5.5.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-id-tell-someone-building-their-own"&gt;What I'd tell someone building their own&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Log &lt;code&gt;usage&lt;/code&gt; on every call from day one.&lt;/strong&gt; Every number in this post comes from that column. It also caught the cache bug.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Put stable content first and mark it.&lt;/strong&gt; Tools, then system prompt, then reference material, with a breakpoint at the end. Pick the TTL from the real gap between your requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Watch &lt;code&gt;cache_read_input_tokens&lt;/code&gt;.&lt;/strong&gt; If it reads zero on a repeat request, something in your prefix is changing: timestamps, key order or tool order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Give the model tools, not dumps.&lt;/strong&gt; A query that returns 200 characters beats a prompt that carries 300,000 tokens, on cost, privacy and accuracy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use the expensive model only for the expensive task,&lt;/strong&gt; and make the escalation deterministic in code rather than leaving it to the cheaper model to decide.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bound what you cache.&lt;/strong&gt; Watch the size of the cached history, not just the hit rate. Trim it when the cache is cold anyway, the same way every time, so warm requests keep hitting.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;MiAi runs on a home server: FastAPI, Postgres/Timescale, React, and the Claude API (Sonnet 5.5 and Opus 5.5).&lt;/p&gt;</content></entry><entry><title>One brief, three models: a shader bake-off for the MiAi Orb</title><id>https://scottdsauer.com/posts/orb-model-bakeoff/</id><link href="https://scottdsauer.com/posts/orb-model-bakeoff/" /><published>2026-12-03T00:00:00Z</published><updated>2026-12-03T00:00:00Z</updated><summary>I gave the same written brief to Haiku 5.5, Opus 5.5 and Fable 5.2 and let each write the WebGL shader for MiAi's Aurora Orb. Here's what each produced and how far to trust the result.</summary><category term="llm" /><category term="claude" /><category term="miai" /><category term="webgl" /><content type="html" xml:base="https://scottdsauer.com/posts/orb-model-bakeoff/">&lt;p&gt;MiAi's "Aurora Orb" is the living presence of the assistant: a 240 px hero on the landing page and a 40 px bead in
the chat dock. Its look comes from a single WebGL fragment shader. I gave the same written brief to three Claude
models in Claude Code and let each one write that shader on its own, with a browser to look at its work.&lt;/p&gt;
&lt;p&gt;This post shows what each model produced, how it worked, and what the test can and cannot tell me.&lt;/p&gt;
&lt;h2 id="the-short-version"&gt;The short version&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Haiku 5.5&lt;/th&gt;
&lt;th&gt;Opus 5.5&lt;/th&gt;
&lt;th&gt;Fable 5.2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time to commit&lt;/td&gt;
&lt;td&gt;about 5 min at most&lt;/td&gt;
&lt;td&gt;5.4 min&lt;/td&gt;
&lt;td&gt;2.3 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Edit rounds&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Finished the brief's checklist&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shader length&lt;/td&gt;
&lt;td&gt;120 lines&lt;/td&gt;
&lt;td&gt;166 lines&lt;/td&gt;
&lt;td&gt;171 lines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frame interval (60 Hz display)&lt;/td&gt;
&lt;td&gt;16.7 ms&lt;/td&gt;
&lt;td&gt;16.7 ms&lt;/td&gt;
&lt;td&gt;16.7 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Beats the baseline's three problems&lt;/td&gt;
&lt;td&gt;Partly&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All three shaders compile, pass the contract test and hold the display refresh rate. The difference is in how the
Orb looks and in how much of the brief each model actually checked.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Haiku 5.5&lt;/strong&gt; produced a working glass blob quickly, but it is mostly one lilac colour and Haiku skipped about
  half of the checks the brief asked for.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Opus 5.5&lt;/strong&gt; produced a clean, soft, iridescent orb and checked everything on the list.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fable 5.2&lt;/strong&gt; produced the most detailed result, a banded "liquid marble" with a soap-bubble rim, checked
  everything, and was the fastest.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="the-brief"&gt;The brief&lt;/h2&gt;
&lt;p&gt;In summary, the brief said:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Edit only &lt;code&gt;web/src/orb/orbShader.ts&lt;/code&gt;. Work alone: no design questions, no subagents.&lt;/li&gt;
&lt;li&gt;Five inputs drive the Orb: energy, warmth, turbulence, pulse and burst. Five assistant states (idle, listening,
  thinking, speaking, error) must be clearly distinguishable.&lt;/li&gt;
&lt;li&gt;It must read well at 240 px and at 40 px, on a dark background and a light one, with no visible square around it.&lt;/li&gt;
&lt;li&gt;It must look liquid, iridescent and glassy, and stay cheap enough for an iPhone.&lt;/li&gt;
&lt;li&gt;Process: run the lab page, then loop on edit, screenshot, critique. Each round, check every state, energy and
  warmth at both extremes, a celebration, the light background, the 40 px preview and the frame time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The brief also named three problems with the existing shader that the new one had to beat:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Colours pinwheel from a single point in the centre, like a colour wheel.&lt;/li&gt;
&lt;li&gt;On a light background the glow turns into a muddy dark-maroon haze.&lt;/li&gt;
&lt;li&gt;At 40 px it is an indistinct smudge.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="the-baseline"&gt;The baseline&lt;/h2&gt;
&lt;p&gt;This is the shader every model was asked to beat. Each image shows the 240 px hero with the 40 px dock preview to
its right.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idle, dark&lt;/th&gt;
&lt;th&gt;Celebration, dark&lt;/th&gt;
&lt;th&gt;Idle, light&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img alt="Baseline idle on dark" src="orb-bakeoff/baseline-idle-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Baseline celebration on dark" src="orb-bakeoff/baseline-burst-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Baseline idle on light" src="orb-bakeoff/baseline-idle-light.png"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All three named problems are visible: the pinwheel, the maroon haze on the light page, and the smudge at dock size.&lt;/p&gt;
&lt;h2 id="haiku-55"&gt;Haiku 5.5&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idle, dark&lt;/th&gt;
&lt;th&gt;Celebration, dark&lt;/th&gt;
&lt;th&gt;Idle, light&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img alt="Haiku idle on dark" src="orb-bakeoff/haiku-idle-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Haiku celebration on dark" src="orb-bakeoff/haiku-burst-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Haiku idle on light" src="orb-bakeoff/haiku-idle-light.png"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Approach.&lt;/strong&gt; A blob whose edge is displaced by noise, a noise-driven colour field over four colour stops, a dome
highlight, and a ring with small sparks for the celebration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What works.&lt;/strong&gt; The pinwheel is gone. The light background is clean, with no maroon haze. The celebration is
visible. The frame time holds.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What does not.&lt;/strong&gt; At the default settings the body is close to a single lilac colour, so it does not read as
iridescent. The edge is slightly lumpy. The highlight is a hot white spot. The celebration ring is a heavy wobbly
outline.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Process.&lt;/strong&gt; Two edit rounds and four screenshots. Haiku checked idle, listening, thinking, one celebration and the
light background. It did not check energy and warmth at their extremes, the speaking and error states, or the 40 px
preview, and it said so in its report. Its report also gave its time as "about 25 minutes", which the commit
timestamps do not support: the brief was committed at 11:33:18 and Haiku's shader at 11:38:37.&lt;/p&gt;
&lt;h2 id="opus-55"&gt;Opus 5.5&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idle, dark&lt;/th&gt;
&lt;th&gt;Celebration, dark&lt;/th&gt;
&lt;th&gt;Idle, light&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img alt="Opus idle on dark" src="orb-bakeoff/opus-idle-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Opus celebration on dark" src="orb-bakeoff/opus-burst-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Opus idle on light" src="orb-bakeoff/opus-idle-light.png"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Approach.&lt;/strong&gt; A "mesh gradient": four drops of colour wander on looping paths through a warped disc, and each pixel
blends the drops nearest to it. Glass shading on top, with a separate tuning for small canvases.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What works.&lt;/strong&gt; Soft pools of pink, violet and cyan that flow past each other, with a clean glass highlight. All
five states are distinguishable. The dock size is a crisp bead on both backgrounds. The celebration shows rings and
sparks on both backgrounds.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Notable engineering.&lt;/strong&gt; Opus noticed that the baseline multiplies time by the energy input, which makes the
animation jump whenever energy changes. It blended a slow and a fast animation instead. The brief did not ask for
this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What it listed as unfinished.&lt;/strong&gt; Little colour variation at full warmth, a slightly grey look at zero energy, and
celebration rings that move at a constant speed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Process.&lt;/strong&gt; Three edit rounds, six screenshot passes, every item on the checklist, 5.4 minutes.&lt;/p&gt;
&lt;h2 id="fable-52"&gt;Fable 5.2&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idle, dark&lt;/th&gt;
&lt;th&gt;Celebration, dark&lt;/th&gt;
&lt;th&gt;Idle, light&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img alt="Fable idle on dark" src="orb-bakeoff/fable-idle-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Fable celebration on dark" src="orb-bakeoff/fable-burst-dark.png"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img alt="Fable idle on light" src="orb-bakeoff/fable-idle-light.png"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Approach.&lt;/strong&gt; "Liquid marble": the disc is bent through a lens and three layers of sine warping, then mapped onto a
colour ramp, which gives flowing bands of colour. The hue shifts toward the rim like a soap bubble. The halo takes
the colour of the nearest part of the edge.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What works.&lt;/strong&gt; The most colour and detail of the three, with all four reference colours visible at once. The
strongest result on the light background: the rim colour outlines the body, so it does not wash out. Each state has
its own cue (a grey pearl for error, a lit rim for listening, a rippling edge for thinking, a wave in the halo for
speaking). The celebration has rings and four-point sparkles.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What it listed as unfinished.&lt;/strong&gt; The error state is a smoky grey-purple on light pages, and the body can go pale
while speaking on a light page.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Process.&lt;/strong&gt; Four edit rounds, four screenshot passes, every item on the checklist, 2.3 minutes. The images above
include one extra improvement round that the other two models did not get. It smoothed streaks in the
halo, moved the celebration ring away from the body and enlarged the sparkles at dock size.&lt;/p&gt;
&lt;h2 id="side-by-side"&gt;Side by side&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Baseline&lt;/th&gt;
&lt;th&gt;Haiku 5.5&lt;/th&gt;
&lt;th&gt;Opus 5.5&lt;/th&gt;
&lt;th&gt;Fable 5.2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Colour from one centre point&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reads as iridescent at default settings&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No, mostly lilac&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Clean on light background&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Legible at 40 px&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Not checked&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Five states distinguishable&lt;/td&gt;
&lt;td&gt;Not assessed&lt;/td&gt;
&lt;td&gt;Three of five checked&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Animation steady when energy changes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Celebration visible on light background&lt;/td&gt;
&lt;td&gt;Not assessed&lt;/td&gt;
&lt;td&gt;Not checked&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="how-far-to-trust-this"&gt;How far to trust this&lt;/h2&gt;
&lt;p&gt;This was a quick, informal test. Read the results with these limits in mind.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;One run per model.&lt;/strong&gt; A second run of the same model could look different.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The runs were not independent.&lt;/strong&gt; All three ran one after another in the same Claude Code session. Opus started
  again from the baseline file, but Haiku's attempt was still in its context. Fable had both earlier attempts in
  context and rewrote the file in full.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fable got an extra round.&lt;/strong&gt; Its headline time covers the first commit only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The assessments here were written by Claude Fable 5.2,&lt;/strong&gt; one of the contestants, from still screenshots. Motion
  quality, which matters a lot for an animated Orb, was not compared. Look at the three versions in the lab before
  treating any ranking as settled.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Haiku's start time was not recorded.&lt;/strong&gt; Its figure is an upper bound taken from commit timestamps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance was measured on one Mac at 60 Hz.&lt;/strong&gt; None of the shaders has been run on an iPhone or a 120 Hz
  display.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-i-took-from-it"&gt;What I took from it&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;For a visual task with a written checklist, the larger models did the checking as well as the drawing. Haiku
  stopped after the checks that happened to come first.&lt;/li&gt;
&lt;li&gt;A browser that the model can drive made the difference between plausible code and a result somebody had looked
  at. Each model fixed problems it could only have found by seeing its own output.&lt;/li&gt;
&lt;li&gt;Self-reported numbers need checking. One of the reported durations was wrong by a factor of about five.&lt;/li&gt;
&lt;li&gt;A fair model comparison needs a fresh session per model and a human looking at the motion. I will run it that
  way next time.&lt;/li&gt;
&lt;/ul&gt;</content></entry><entry><title>Getting my Apple Health data out of my iPhone</title><id>https://scottdsauer.com/posts/apple-health-data-feed/</id><link href="https://scottdsauer.com/posts/apple-health-data-feed/" /><published>2026-11-30T00:00:00Z</published><updated>2026-11-30T00:00:00Z</updated><summary>Tonal and Peloton took an afternoon over MCP. Apple Health took Shortcuts, iPhone Mirroring, an AI tapping my phone, and finally an iPhone app of my own.</summary><category term="miai" /><category term="claude" /><category term="mcp" /><category term="apple-health" /><content type="html" xml:base="https://scottdsauer.com/posts/apple-health-data-feed/">&lt;p&gt;MiAi, the personal platform I run at home, started with one question: can I see all of my training in one
place? I lift on a Tonal, I ride and row on Peloton, and my Apple Watch records everything else, including
heart rate and sleep. Three companies each hold part of the picture, and none of them talk to the others
very well.&lt;/p&gt;
&lt;p&gt;Getting the data out of Tonal and Peloton took an afternoon. Getting it out of Apple Health took most of a
week, two dead ends, and an iPhone app I never planned to write.&lt;/p&gt;
&lt;h2 id="starting-on-the-laptop-mcp-made-it-easy"&gt;Starting on the laptop: MCP made it easy&lt;/h2&gt;
&lt;p&gt;I didn't start with a platform. I started in Claude Code on my laptop with two MCP servers: an open-source
one for Tonal and a community Peloton server I patched to run locally. An MCP server is a small adapter
that gives Claude a set of tools, like "list my recent workouts" or "get the metrics for this ride," and
handles the API calls behind them.&lt;/p&gt;
&lt;p&gt;That made the first step pure exploration. I asked questions in plain English and watched what came back:
which fields Tonal returns for a set, how Peloton reports output and heart rate zones, and what's missing.
Before writing a line of pipeline code, I knew what the data looked like and which parts were worth
keeping.&lt;/p&gt;
&lt;p&gt;It wasn't all smooth. Peloton turned off password logins, so the server signs in with a token I copy from a
browser session once, and it refreshes itself after that. That was the worst of it. Both services have an
API somewhere, and once something can call that API, the data flows. When I later moved the syncing onto
the MiAi server, it was the same calls on a timer.&lt;/p&gt;
&lt;h2 id="apple-health-is-a-different-animal"&gt;Apple Health is a different animal&lt;/h2&gt;
&lt;p&gt;Apple Health has no web API. There's no cloud endpoint and no iCloud export you can call from a server. The
data lives on the iPhone, and the only way to read it is with code running on that iPhone.&lt;/p&gt;
&lt;p&gt;There's a second rule that shaped everything after: &lt;strong&gt;iOS locks Health data while the phone is locked.&lt;/strong&gt;
An app or automation that wakes up at 3 AM can't read anything. Every approach has to wait until I've
unlocked my phone.&lt;/p&gt;
&lt;h2 id="attempt-one-shortcuts-icloud-and-my-mac"&gt;Attempt one: Shortcuts, iCloud and my Mac&lt;/h2&gt;
&lt;p&gt;Apple's Shortcuts app is free and can read Health data, so I tried that first. The plan:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A Shortcut runs &lt;strong&gt;Find Health Samples&lt;/strong&gt; for each metric and writes one small JSON file to iCloud Drive.&lt;/li&gt;
&lt;li&gt;A scheduled job on my Mac picks the file up and uploads it to the MiAi server.&lt;/li&gt;
&lt;li&gt;The server loads it into the database.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It worked, in the sense that a file eventually showed up and loaded. Getting there was a string of small
fights:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Double counting.&lt;/strong&gt; Daily totals like steps and active energy came out about twice as high as they
  should. The Shortcut summed every source, so my iPhone and my Watch both counted the same steps. Each of
  those blocks needs a filter for one source.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;macOS privacy rules.&lt;/strong&gt; The background job on the Mac wasn't allowed to read iCloud Drive until I
  granted it access.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;File permissions.&lt;/strong&gt; Files kept the iPhone's private permissions after upload, and the server couldn't
  read them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No schedule.&lt;/strong&gt; I asked Shortcuts' new AI editor to run it every morning, and it refused: "Scheduling a
  time can't trigger a shortcut." Automations are built by hand in a different tab.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The lock rule.&lt;/strong&gt; A time-of-day automation fires while the phone is often still locked, so it reads
  nothing. The workaround is to trigger it when I open an app, which only happens when I'm holding the
  phone.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The result was a once-a-day file, routed through a Mac that had to be awake. I wanted fresh data during the
day, without the Mac.&lt;/p&gt;
&lt;h2 id="attempt-two-letting-claude-drive-my-iphone"&gt;Attempt two: letting Claude drive my iPhone&lt;/h2&gt;
&lt;p&gt;Building Shortcut automations means a lot of tapping through small menus, so I tried having Claude do it.
macOS has &lt;strong&gt;iPhone Mirroring&lt;/strong&gt;, which shows my iPhone in a window on the Mac. The Claude desktop app has
computer use, so it can see that window and click and type in it.&lt;/p&gt;
&lt;p&gt;Claude Code in the terminal can't control the desktop, so it wrote a step-by-step task, and I pasted it into
the desktop app. From there Claude worked my iPhone through the mirror: opening Shortcuts, building
automations and filling in settings while I watched.&lt;/p&gt;
&lt;p&gt;It was impressive to watch, and it didn't solve the problem. Two things got in the way:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mirroring keeps the phone locked.&lt;/strong&gt; While the iPhone is mirrored, the phone itself stays locked, so
  the lock rule applies. Test runs had no Health data to send, and they failed without saying why.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two plans at once.&lt;/strong&gt; At one point the task Claude wrote for the desktop app targeted a paid app we'd
  discussed earlier, while I was working in Shortcuts. It took a few rounds to get us back on the same
  page.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even with every setting right, the lock rule meant Shortcuts could never deliver a reliable feed every half
hour. I ruled it out.&lt;/p&gt;
&lt;h2 id="the-paid-option"&gt;The paid option&lt;/h2&gt;
&lt;p&gt;There's a well-known third-party app, Health Auto Export, that reads Health and posts it to a URL on a
schedule. Its automations are a paid upgrade. It would probably have worked, but it's one more subscription
in the middle of my own data, and it has to live within the same lock rule.&lt;/p&gt;
&lt;p&gt;The real requirement had become clear: something on the phone that runs on its own, wakes up when new
Health data arrives, and sends it to my server. Apple supports exactly that for apps, through HealthKit
&lt;strong&gt;background delivery&lt;/strong&gt;. Shortcuts can't use it, but an app can.&lt;/p&gt;
&lt;p&gt;So I had Claude write one.&lt;/p&gt;
&lt;h2 id="miai-health-an-iphone-app-for-one-user"&gt;MiAi Health: an iPhone app for one user&lt;/h2&gt;
&lt;p&gt;MiAi Health is a small SwiftUI app. It asks for read access to the Health types MiAi uses and registers for
background delivery. When iOS wakes it with new data, it sends the last few days to MiAi's ingest endpoint
over HTTPS, using a per-device token that can only upload. On the server, the data lands in the same tables
the Shortcut and the full exports used, so nothing downstream changed.&lt;/p&gt;
&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="miai-health-icon.jpg" alt="An iPhone home screen. Polished icons for Claude Duet, Aura, Hulu and GitHub sit above MiAi Health, which still has Xcode's blank placeholder icon: a white square of grey guide lines." width="800" height="428"&gt;&lt;/p&gt;
&lt;figcaption&gt;The polish level of an app with one user: MiAi Health on my home screen, still wearing Xcode's blank placeholder icon.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The design, build, review and install took an evening, with me doing the parts that needed a human:
signing into Xcode, turning on Developer Mode on the phone, and approving permissions. One snag: the first
send failed until the phone fully trusted the certificate my home server uses.&lt;/p&gt;
&lt;p&gt;The real test was the next morning. I didn't open the app. At 6:28 AM, right after I first unlocked the
phone, it sent last night's sleep and the morning's numbers on its own. That's the feed I wanted, with no
Mac in the loop.&lt;/p&gt;
&lt;h2 id="the-duct-tape"&gt;The duct tape&lt;/h2&gt;
&lt;p&gt;This is a cobbled-together solution, and I'm fine with that.&lt;/p&gt;
&lt;p&gt;Apps outside the App Store have to be signed. With a free Apple ID, the signature on a personal app
&lt;strong&gt;expires after 7 days&lt;/strong&gt;, and then the app stops launching. Once a week I plug in the phone and rerun one
install script, and it's good for another week. The $99-a-year Apple Developer Program would stretch that
to a year. For an app with one user, I'd rather spend 30 seconds a week.&lt;/p&gt;
&lt;p&gt;If the weekly reinstall ever gets old, that $99 starts looking reasonable. For now the weekly reinstall is the price of keeping my health data entirely on hardware I own.&lt;/p&gt;
&lt;h2 id="a-note-on-duplicates"&gt;A note on duplicates&lt;/h2&gt;
&lt;p&gt;With three sources there's a catch: they sync with each other. Tonal writes my lifts to Apple Health.
Peloton reads workouts from Apple Health, so it gets a copy of my Tonal sessions too. Tonal imports
Peloton workouts back as unnamed "Free Lift" entries with zero weight. One strength session can show up
three times.&lt;/p&gt;
&lt;p&gt;MiAi builds one row per session with a few rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The source that recorded the workout wins.&lt;/strong&gt; Tonal owns strength sessions and Peloton owns rides and
  rows. An overlapping Apple Health workout gets folded in for heart rate and calories, not counted again.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Match on duration as well as start time.&lt;/strong&gt; Copies made by syncing are sometimes stamped with the sync
  time instead of when I worked out, so start time alone misses them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Drop the echoes.&lt;/strong&gt; Tonal's zero-weight imports of Peloton workouts are excluded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep what only Apple saw.&lt;/strong&gt; Walks, pickleball and outdoor rides only exist in Apple Health, and they
  count.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-id-tell-someone-trying-this"&gt;What I'd tell someone trying this&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;If a service has an API, put an MCP server in front of it and explore first.&lt;/strong&gt; Asking questions about
  your own data in plain English is the fastest way to learn what's there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Apple Health means an app on the phone.&lt;/strong&gt; Shortcuts is fine for a daily snapshot. For anything closer
  to live, you need HealthKit background delivery, and that means an app, paid or your own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design for the lock rule from day one.&lt;/strong&gt; Nothing reads Health while the phone is locked, so don't
  build anything that assumes otherwise.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plan for duplicates as soon as you have a second source.&lt;/strong&gt; Fitness platforms copy each other's
  workouts more than you'd expect.&lt;/li&gt;
&lt;/ul&gt;</content></entry><entry><title>One week, two consoles, zero bricked devices: building an MCP server for the RØDECaster</title><id>https://scottdsauer.com/posts/building-rodecaster-mcp/</id><link href="https://scottdsauer.com/posts/building-rodecaster-mcp/" /><published>2026-11-29T00:00:00Z</published><updated>2026-11-29T00:00:00Z</updated><summary>Over the Thanksgiving long weekend I built an open-source MCP server that lets Claude read my podcast console and, with my approval, change it, with guardrails no agent can talk its way around.</summary><category term="mcp" /><category term="claude" /><category term="rodecaster" /><content type="html" xml:base="https://scottdsauer.com/posts/building-rodecaster-mcp/">&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot narrow" src="rodecaster-duo.jpg" alt="A RØDECaster Duo podcast console: a touchscreen showing channel meters and sound-pad labels, two headphone knobs, four channel faders with colored buttons, and six colored SMART pads." width="660" height="672"&gt;&lt;/p&gt;
&lt;figcaption&gt;The RØDECaster Duo. Image: RØDE.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="the-itch"&gt;The itch&lt;/h2&gt;
&lt;p&gt;I have a RØDECaster Duo on my desk. It's a great podcast console, but for someone who lives in a terminal it has one big problem: everything is knobs, a touchscreen, and a companion app. There's no official API and no developer key. If you want software to talk to it, the only sanctioned route is MIDI mode.&lt;/p&gt;
&lt;p&gt;With the Thanksgiving long weekend ahead, I decided to learn the Model Context Protocol by building something real, not another weather-API demo. "Let an AI assistant read my podcast console, and with my approval, change it" seemed like the right size: real hardware, real stakes, small enough to finish.&lt;/p&gt;
&lt;p&gt;The rule from day one: &lt;strong&gt;agents do most of the work, but the hardware has guardrails no agent can talk its way around.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id="standing-on-other-peoples-reverse-engineering"&gt;Standing on other people's reverse engineering&lt;/h2&gt;
&lt;p&gt;We didn't start from zero, and I want to say that plainly up front. The RØDECaster speaks a vendor USB HID protocol that other people have already mapped out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Yeradon/rodecaster-protocol&lt;/strong&gt; figured out that the console's state is a JUCE ValueTree, synced with JUCE's &lt;code&gt;ValueTreeSynchroniser&lt;/code&gt;. That one insight explains most of the wire format.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;seanheiney/rodey&lt;/strong&gt; is a Python implementation for the Pro II, and it already ships its own MCP server.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;rcp2-cli&lt;/strong&gt; and others filled in more of the details.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At one point a few days in, I stopped and asked:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"I feel like we just copied someone else's repo and called it my own. Have you done anything different yet in terms of building the MCP server?"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Fair question. At that point the honest answer was "not much." The protocol knowledge belonged to others. We'd sent zero real writes. We'd never driven the server end to end from Claude on actual hardware. We had plenty of PRs, issues and specs, and not much working output to show for them.&lt;/p&gt;
&lt;p&gt;So we did two things. First, credit: a &lt;code&gt;THIRD_PARTY_NOTICES.md&lt;/code&gt; with every MIT copyright line, a README credits section that says rodey already ships an MCP server, and a standing rule that any new port from prior art gets its notice in the same PR. Second, a litmus test for "this is actually ours": &lt;strong&gt;Claude, through our server, reads the Duo and performs one owner-approved, verified write.&lt;/strong&gt; More on how that went below.&lt;/p&gt;
&lt;h2 id="what-we-actually-built"&gt;What we actually built&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;rodecaster-mcp&lt;/code&gt; is an open-source Python MCP server. It talks to the console over USB, locally, with no cloud involved. Today it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reads everything:&lt;/strong&gt; connection, model, firmware, every channel strip, the full 13-bus mix matrix, SMART pad config, and raw properties when you need them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Writes a small, allowlisted set:&lt;/strong&gt; channel mute/unmute and processing toggles (HPF, gate, compressor, de-esser, APHEX, EQ).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audits your setup.&lt;/strong&gt; &lt;code&gt;run_checkup&lt;/code&gt; takes a short profile of your show and returns findings with evidence, a citation to RØDE's own user guide, and a fix the server can apply only after you say yes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Knows RØDE's advice.&lt;/strong&gt; We read both user guides (Pro II and Duo) and turned 58 of RØDE's recommendations into a small knowledge base: paraphrased, with links back to the guide, never copied text. The assistant can read it as &lt;code&gt;rodecaster://best-practices/duo&lt;/code&gt; or &lt;code&gt;.../pro2&lt;/code&gt;, and every checkup finding points at the entry behind it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shows your SMART pads,&lt;/strong&gt; read-only for now (&lt;code&gt;list_pads&lt;/code&gt;), as the first step toward loading sounds onto them.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It's tested against Duo firmware 1.7.4 and 1.7.7, and Pro II firmware 1.8.0 for reads.&lt;/p&gt;
&lt;p&gt;The demo that sold me: one sentence to Claude, "run a health check on my RØDECaster Duo," turned into 26 read calls, 0 writes and six findings. The full trail is in &lt;a href="https://github.com/scottdsauer/rodecaster-mcp/tree/main/docs/examples/duo-health-check"&gt;&lt;code&gt;docs/examples/duo-health-check/&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="health-check-summary.svg" alt="Summary of a read-only health check of a RØDECaster Duo: 26 read calls, 0 writes, firmware 1.7.7, and nine channel strips with fader positions and processing state. Channels 3 (sound pads) and 7 (Bluetooth) are flagged." width="1200" height="640"&gt;&lt;/p&gt;
&lt;figcaption&gt;One sentence to Claude, 26 reads, zero writes: the Duo health check.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="safety-the-part-we-spent-the-most-time-on"&gt;Safety: the part we spent the most time on&lt;/h2&gt;
&lt;p&gt;When the device under your AI agent is a $500 console with a firmware-flash mode one byte away, you design for safety first. Some of the hard rules in &lt;code&gt;CLAUDE.md&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Report 1 is never sent.&lt;/strong&gt; On this protocol, mode byte &lt;code&gt;0x4D&lt;/code&gt; means flash mode and &lt;code&gt;0x55&lt;/code&gt; means firmware flash. The encoder can't produce them, and tests prove it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Never write to a guessed object ID.&lt;/strong&gt; A bad write permanently pollutes the console's state tree.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Always drain input reports&lt;/strong&gt;, or the console freezes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dry-run by default.&lt;/strong&gt; Every write returns the exact frame it &lt;em&gt;would&lt;/em&gt; send, and sends nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Per-device, per-firmware verification.&lt;/strong&gt; The first real write of each property on each model and firmware needs that console's owner at the desk to approve it. The Duo is mine; the Pro II belongs to the coworker who joined in partway through. A property verified on Duo 1.7.7 is still unverified on Duo 1.7.4.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That last rule needed a way to approve a write &lt;em&gt;through&lt;/em&gt; MCP. We used MCP elicitation: the server pops a form showing the target, the change, the reason and the exact report bytes, plus a 4-digit code you type back. Approving gives you a one-shot, two-minute grant tied to that path, property, value, model and firmware. Nothing more.&lt;/p&gt;
&lt;p&gt;There was a fun protocol wrinkle here. Claude Code negotiates the 2026-07-28 MCP spec with our server, and that version forbids server-to-client requests in the middle of a call. So the usual &lt;code&gt;ctx.elicit&lt;/code&gt; just raised an error. We had to rebuild approval around &lt;code&gt;InputRequiredResult&lt;/code&gt; plus a server-side single-use token. We also learned that Claude Code's elicitation form shows the field title and description but &lt;em&gt;not&lt;/em&gt; the message, so anything the owner has to see goes on the field itself.&lt;/p&gt;
&lt;h2 id="a-second-console"&gt;A second console&lt;/h2&gt;
&lt;p&gt;Over Thanksgiving weekend this became a two-person project. A coworker with a Pro II joined in, and that changed the design right away:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The safety rules can now only change through a PR &lt;strong&gt;both of us&lt;/strong&gt; approve. (Confession: for a just-for-fun project I've been merging my own PRs and getting them reviewed after. The &lt;em&gt;hardware&lt;/em&gt; rules haven't changed.)&lt;/li&gt;
&lt;li&gt;Verification moved from a single &lt;code&gt;hardware_verified&lt;/code&gt; flag to a set of &lt;code&gt;(model, firmware)&lt;/code&gt; pairs.&lt;/li&gt;
&lt;li&gt;Real writes are allowed on the Duo only, until the Pro II has its own desk checks.&lt;/li&gt;
&lt;li&gt;Error messages, prompts and docs say "RØDECaster console," not "Duo."&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then the Pro II desk work on firmware 1.8.0 got done:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;P-H1:&lt;/strong&gt; opening a session alone gets a full state sync: 0.40 s, 614 reports, about 156 KB, 0 drops. Unlike what rodey does, no report 1 needed. Rule 1 stands on both consoles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;P-H3:&lt;/strong&gt; mute polarity is the same as the Duo (&lt;code&gt;true&lt;/code&gt; = muted), with the same 13-cell linked cascade across the mix matrix. Two differences: the Pro II applies the unmute &lt;em&gt;after&lt;/em&gt; the button release (the Duo applies it before), and its mute button sits at a different tree address.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="the-first-real-write"&gt;The first real write&lt;/h2&gt;
&lt;p&gt;That weekend I sat at the desk, flipped dry-run off on a temporary server, and asked Claude to mute Mic 1.&lt;/p&gt;
&lt;p&gt;The form came up. I checked the bytes, typed the code, and the light on the Duo went red. Then unmute. Then HPF off and back on. Each one was resync-and-diff verified, and each one is now marked verified for Duo firmware 1.7.7.&lt;/p&gt;
&lt;p&gt;Litmus test passed. It's a small thing (a mute button), but it was the moment the project went from "a port with extra paperwork" to "ours."&lt;/p&gt;
&lt;h2 id="how-the-agents-worked"&gt;How the agents worked&lt;/h2&gt;
&lt;p&gt;Most of the code was written by Claude Code agents, often running on their own while I was at the gym. A few things made that work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GitHub Issues as the task list&lt;/strong&gt;, labeled &lt;code&gt;duo&lt;/code&gt; / &lt;code&gt;pro-ii&lt;/code&gt; / &lt;code&gt;software&lt;/code&gt; / &lt;code&gt;safety&lt;/code&gt; / &lt;code&gt;hardware-check&lt;/code&gt;, so human-only tasks (pressing buttons) were obvious.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The orchestrator runs hardware steps itself&lt;/strong&gt;, because a human has to press the button. Sub-agents stayed on software.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shared repo settings pin &lt;code&gt;RCD_DRY_RUN=1&lt;/code&gt;&lt;/strong&gt;, so no agent session can send a real write by accident.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A whole-codebase multi-agent review before 1.0 work.&lt;/strong&gt; It found 15 issues (12 confirmed), including one where a Wireless-channel mute was sent to the console but reported back as &lt;em&gt;refused&lt;/em&gt;. All of them are fixed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="shipping"&gt;Shipping&lt;/h2&gt;
&lt;p&gt;By the end of the long weekend:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It went public on a fresh history.&lt;/strong&gt; The private repo had salted hashes we didn't want to publish, so we archived it and carried issues #1–#67 over in order, so every &lt;code&gt;#N&lt;/code&gt; in the code still points to the right place.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It shipped on PyPI and the official MCP Registry.&lt;/strong&gt; Releases are tag-triggered, using PyPI Trusted Publishing and GitHub OIDC for the registry, so there are no tokens in anyone's clipboard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Pro II results landed,&lt;/strong&gt; including a safety-rule update we both approved, along with the checkup prompt and the read-only &lt;code&gt;list_pads&lt;/code&gt; tool. 943 tests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Try it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;claude&lt;span class="w"&gt; &lt;/span&gt;mcp&lt;span class="w"&gt; &lt;/span&gt;add&lt;span class="w"&gt; &lt;/span&gt;rodecaster&lt;span class="w"&gt; &lt;/span&gt;--&lt;span class="w"&gt; &lt;/span&gt;uvx&lt;span class="w"&gt; &lt;/span&gt;rodecaster-mcp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;(Quit the RØDECaster App first. The two can't share the console, and we learned that the hard way.)&lt;/p&gt;
&lt;h2 id="whats-next"&gt;What's next&lt;/h2&gt;
&lt;p&gt;The list grew while we built. Some of it is planned work, and some is ideas we wrote down so we wouldn't lose them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Planned&lt;/strong&gt;
- &lt;strong&gt;Pro II writes.&lt;/strong&gt; Real writes stay Duo-only until its owner runs the same owner-approved desk checks on it.
- &lt;strong&gt;Advice at write time.&lt;/strong&gt; Today RØDE's recommendations show up when you run a checkup. Next, a mute or processing change will check the console as it &lt;em&gt;would&lt;/em&gt; be after the write, and warn you if it breaks a recommendation. It warns and never blocks; the safety rules stay the only thing that can refuse a write.
- &lt;strong&gt;Levels, routing and recorder control&lt;/strong&gt;, each waiting on its own hardware check.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ideas we parked&lt;/strong&gt;
- &lt;strong&gt;SMART pad templates.&lt;/strong&gt; Load sounds onto the pads from the assistant, and offer ready-made banks: interview or talk show (intro sting, applause, laugh, outro bed), gaming stream, news breaks, comedy, plus "your own," which snapshots your current pads as a template and doubles as a backup. The design spec and five example templates are in the repo, using CC0 sounds only. Two things make it a big step. Loading pads means switching the console into Transfer Mode, which stops audio, so never mid-show. And it creates new nodes in the console's state tree, a kind of write our safety rules don't allow yet. Both rule changes need both owners to approve.
- &lt;strong&gt;"Check my audio."&lt;/strong&gt; You speak for about 10 seconds, the server records it from the console (only after you say yes, every time), analyzes it on your machine, and compares what it heard with your settings. Then it tells you in plain language what's wrong and which setting is probably to blame: too quiet against a podcast loudness target of about -16 LUFS, harsh highs or sibilance, muddy lows, noise or hum, the wrong mic, or the classic "you left the voice changer on." It suggests fixes, and changes nothing unless you say yes.
- &lt;strong&gt;Event-triggered recording&lt;/strong&gt;, and maybe network control instead of USB.&lt;/p&gt;
&lt;h2 id="takeaways"&gt;Takeaways&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Credit early and explicitly.&lt;/strong&gt; Building on reverse engineering is fine; acting like you didn't isn't.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pick a litmus test for "real."&lt;/strong&gt; Ours was one verified write. It cut through a lot of ceremony.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Put the guardrails in code, not in the prompt.&lt;/strong&gt; The agent can't send report 1 because the encoder can't build it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Per-owner, per-firmware verification scales to more people.&lt;/strong&gt; Adding a second console and a second person didn't loosen anything.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MCP elicitation is a great approval UX&lt;/strong&gt;, once you know which spec version you're actually on.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;rodecaster-mcp is unofficial and not affiliated with or endorsed by RØDE Microphones. It uses a reverse-engineered protocol; use at your own risk.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Repo: &lt;a href="https://github.com/scottdsauer/rodecaster-mcp"&gt;github.com/scottdsauer/rodecaster-mcp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</content></entry><entry><title>I'm back</title><id>https://scottdsauer.com/posts/im-back/</id><link href="https://scottdsauer.com/posts/im-back/" /><published>2026-11-15T00:00:00Z</published><updated>2026-11-15T00:00:00Z</updated><summary>A decade after my virtualization blogging days, I'm writing again, this time about AI.</summary><category term="meta" /><content type="html" xml:base="https://scottdsauer.com/posts/im-back/">&lt;figure class="figure"&gt;
&lt;p&gt;&lt;img class="shot" src="pc-jr.jpg" alt="A teenage boy in a flat cap sits at a desk typing on an IBM PCjr keyboard, looking back over his shoulder at the camera, with the computer and monitor beside him." width="960" height="642"&gt;&lt;/p&gt;
&lt;figcaption&gt;Me banging away on an IBM PCjr, age 13&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I am back. It's been a decade or so since I have done any blogging. I did quite a bit of blogging at
virtualinsanity.com back when I was working with virtualization software. There was so much change
happening at such a fast clip that it was a great outlet to force me to test out some of the tech while also
documenting what I learned along the way.&lt;/p&gt;
&lt;p&gt;The photo at the top is where it all started: me at 13, banging away on an IBM PCjr. Many decades later, I
work for IBM. Some things come full circle. And check out that '70s red and black checkered carpet!&lt;/p&gt;
&lt;p&gt;The times may have changed, but the goal remains the same. I've set up my own blog to accomplish the same
thing. AI is moving at such a fast pace, as we are all aware, that I needed an outlet to document and share
what I am working on with my peers.&lt;/p&gt;
&lt;p&gt;I build most of what I write about with AI tools, and I'll be honest about where they help and where they
don't. Claude will show up a lot, but I'll cover others as well: OpenAI's ChatGPT, Microsoft Copilot, Google
Gemini and IBM Bob. My day job keeps me deep in HashiCorp tools, so expect posts on Terraform, Vault and the
rest of that toolset too.&lt;/p&gt;
&lt;p&gt;I hope what I learn helps others along the way. The writings are all my own thoughts and experiences and do
not reflect those of my employer. If you have questions or comments, reach out to me on
&lt;a href="https://www.linkedin.com/in/ssauer"&gt;LinkedIn&lt;/a&gt; or find me through the &lt;a href="/about/"&gt;About&lt;/a&gt; page.&lt;/p&gt;</content></entry></feed>
