<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yi wang</title>
    <description>The latest articles on DEV Community by yi wang (@wangyi160).</description>
    <link>https://dev.to/wangyi160</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4246964%2F400c2be9-cc5a-4766-baf8-0bd8e13276f2.png</url>
      <title>DEV Community: yi wang</title>
      <link>https://dev.to/wangyi160</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wangyi160"/>
    <language>en</language>
    <item>
      <title>Auditable AI billing without a blockchain: signed batches and their limits</title>
      <dc:creator>yi wang</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:34:35 +0000</pubDate>
      <link>https://dev.to/wangyi160/auditable-ai-billing-without-a-blockchain-signed-batches-and-their-limits-4mb7</link>
      <guid>https://dev.to/wangyi160/auditable-ai-billing-without-a-blockchain-signed-batches-and-their-limits-4mb7</guid>
      <description>&lt;p&gt;The difficult part of AI API billing is often the request that almost finished. The router sent the prompt, the provider began responding, and the connection disappeared before final usage arrived. A database can store a precise number for that request without making the number well justified.&lt;/p&gt;

&lt;p&gt;I am building TeeRouter, and this led to two separate design questions: what evidence supports a charge, and how can someone later detect changes to the published accounting records?&lt;/p&gt;

&lt;p&gt;The implementation borrows a useful idea associated with blockchains: publish cryptographically verifiable records that readers can inspect independently. It does not run a blockchain or claim decentralized consensus. This article examines the &lt;a href="https://github.com/wangyi160/teerouter/tree/5c89b551d71040e94c800a944344846c7b0f9e7e" rel="noopener noreferrer"&gt;public source at commit &lt;code&gt;5c89b551&lt;/code&gt;&lt;/a&gt;; it is an implementation case study, not an independent certification of the deployed service.&lt;/p&gt;

&lt;h2&gt;
  
  
  First define what a charge means
&lt;/h2&gt;

&lt;p&gt;A receipt should preserve the pricing decision used for that request. Looking up today's price when displaying last week's usage makes historical charges difficult to reproduce.&lt;/p&gt;

&lt;p&gt;TeeRouter freezes the pricing revision, applicable rules, and pool multiplier at admission. Provider-specific calculators interpret native usage fields. The basis is public API list pricing multiplied by the pool's multiplier, not a claim about the merchant's actual subscription expenditure or negotiated invoice.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/docs/BILLING.en.md" rel="noopener noreferrer"&gt;billing implementation&lt;/a&gt; uses integer arithmetic, retains pre-rounding amounts, and rounds upward once per request to micro-USD. This makes the chosen calculation reproducible without promising to match a provider's monthly invoice rounding, taxes, or discounts.&lt;/p&gt;

&lt;p&gt;For a simple illustrative quote, 10,000 ordinary input tokens at $2 per million plus 1,000 output tokens at $8 per million produces a $0.028 base cost. A 1.2 multiplier gives $0.0336. These are made-up rates, not a current model quotation. Real records must also distinguish cached input, applicable pricing dimensions, and how each provider reports usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  A timeout is an observation, not a usage counter
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/docs/INTERRUPTED-BILLING.en.md" rel="noopener noreferrer"&gt;interrupted-request policy&lt;/a&gt; separates several outcomes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observed outcome&lt;/th&gt;
&lt;th&gt;Accounting treatment&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Router rejects the request before forwarding&lt;/td&gt;
&lt;td&gt;No charge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upstream rejects it with HTTP 3xx/4xx&lt;/td&gt;
&lt;td&gt;No charge; any reported counters are retained as waived usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sending fails before the complete request is flushed, with no generation evidence&lt;/td&gt;
&lt;td&gt;No charge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complete request is flushed, then the connection fails before a reply&lt;/td&gt;
&lt;td&gt;Estimate input at ordinary input pricing; no unseen output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Generation starts, then delivery fails&lt;/td&gt;
&lt;td&gt;Use official counters where available and estimates for supported missing portions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A successful response has missing or invalid usage&lt;/td&gt;
&lt;td&gt;Preserve an explicit pending reason&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A generated refusal inside a successful model response is different from an HTTP rejection: generation may have consumed billable tokens.&lt;/p&gt;

&lt;p&gt;The controversial row is the timeout after a full flush. A successful local flush does &lt;strong&gt;not&lt;/strong&gt; prove that the remote application received or executed the request. The policy chooses a financial treatment for that ambiguity; it does not eliminate the ambiguity. Customers need to know that an estimated input charge can occur at this boundary.&lt;/p&gt;

&lt;p&gt;Estimation is restricted to failed or interrupted model requests and is labelled &lt;code&gt;estimated&lt;/code&gt; or &lt;code&gt;mixed&lt;/code&gt;, with partial coverage. Unknown hidden output is not invented. A downstream cancellation cancels the upstream operation rather than draining it in the background, although closing a connection cannot guarantee the provider immediately stops computing.&lt;/p&gt;

&lt;p&gt;Publishing these distinctions matters more than making every row appear confidently “settled.” A signed estimate remains an estimate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sign a batch, retain the exact bytes
&lt;/h2&gt;

&lt;p&gt;The current &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/docs/CONSUMPTION-PROOFS.en.md" rel="noopener noreferrer"&gt;public receipt format&lt;/a&gt; signs batches of records. A manifest includes the boot and key identity, batch number, previous hash, sequence range, record digest, count, and calculated total.&lt;/p&gt;

&lt;p&gt;Conceptually, verification follows this chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original record bytes -&amp;gt; SHA-256 digest -&amp;gt; manifest
manifest + protocol label -&amp;gt; Ed25519 signature
manifest -&amp;gt; reference to preceding batch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is one signature per batch. The current public format does not have per-record Merkle inclusion proofs. A reader needs the original complete &lt;code&gt;records_json&lt;/code&gt; to verify the records; reserializing JSON may change the bytes being checked.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/verifier/README.en.md" rel="noopener noreferrer"&gt;verifier&lt;/a&gt; distinguishes a valid signature from an independently trusted TEE signing identity. The latter also requires hardware evidence and an approved reference policy. It is not established by a public key or a “verified” label included in the downloaded bundle.&lt;/p&gt;

&lt;p&gt;Hash links let readers check continuity between supplied batches. They do not create consensus, prove that an operator has disclosed the latest batch, or prove that no other history exists. Independently retaining known batch heads could strengthen monitoring, but that is a separate system property, not something the signature supplies automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Storage acknowledgment is not settlement
&lt;/h2&gt;

&lt;p&gt;Consider a batch that reaches external storage, followed by a lost acknowledgment. Regenerating it with new metadata would complicate duplicate detection. TeeRouter freezes the signed bytes before upload and resends those same bytes on a later cycle.&lt;/p&gt;

&lt;p&gt;A valid durable-storage acknowledgment permits releasing the uploaded raw details. It does &lt;strong&gt;not&lt;/strong&gt; reset consumption or update user balances. Per-user, per-batch summaries remain until a separate settlement acknowledgment applies a balance update through an identified uploaded head.&lt;/p&gt;

&lt;p&gt;That boundary is necessary because requests may finish while settlement is happening. Retiring consumption only through the acknowledged head preserves newer charges. Revisions and idempotent retries prevent repeating the same settlement from applying it twice.&lt;/p&gt;

&lt;p&gt;The default upload cycle is five minutes. That is a delivery schedule, not a guarantee of completeness or immediate publication.&lt;/p&gt;

&lt;h2&gt;
  
  
  What survives a restart?
&lt;/h2&gt;

&lt;p&gt;The optional &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/docs/ACCOUNTING-JOURNAL.en.md" rel="noopener noreferrer"&gt;accounting journal&lt;/a&gt; stores committed events and delivery state in SQLite WAL with authenticated encryption. Frozen batches keep their original signatures after restart; new batches use the new process identity.&lt;/p&gt;

&lt;p&gt;It protects successfully committed records. It cannot reconstruct an in-flight request that never produced an event, recover usage that was never observed, or prevent deletion or rollback of an entire journal copy. On a journal write failure or capacity limit, the implementation closes new admission instead of silently discarding accepted events.&lt;/p&gt;

&lt;p&gt;This makes durability a concrete, bounded claim rather than “nothing can ever be lost.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Public accounting without publishing conversations
&lt;/h2&gt;

&lt;p&gt;Public batches exclude prompts, answers, credentials, and refusal text. They contain accounting fields and refusal categories. User pseudonyms rotate using a fresh public batch nonce and a private random identity, rather than hashing a short username.&lt;/p&gt;

&lt;p&gt;That reduces direct linkage across batches but does not guarantee anonymity. Timing, model choices, merchant identifiers, and distinctive traffic volumes can still correlate activity.&lt;/p&gt;

&lt;p&gt;The resulting ledger is useful because readers can check the bytes they received, inspect charge evidence, and distinguish estimates from observed usage. Deposits, withdrawals, externally managed balances, missing history, and provider-side execution remain separate questions. Keeping those boundaries explicit is what makes the evidence meaningful.&lt;/p&gt;




&lt;p&gt;Writing disclosure: This article was drafted by an AI assistant from the linked public source code and protocol documentation. The account owner maintains TeeRouter.&lt;/p&gt;

</description>
      <category>security</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
    <item>
      <title>What a TEE can actually prove about an AI API router</title>
      <dc:creator>yi wang</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:34:21 +0000</pubDate>
      <link>https://dev.to/wangyi160/what-a-tee-can-actually-prove-about-an-ai-api-router-2d27</link>
      <guid>https://dev.to/wangyi160/what-a-tee-can-actually-prove-about-an-ai-api-router-2d27</guid>
      <description>&lt;p&gt;An AI API router sits in an awkward place. It needs to read a request to select an upstream account, enforce permissions, and calculate usage. That also gives its operator opportunities to change parameters, misuse credentials, or report a different price from the one the client expected.&lt;/p&gt;

&lt;p&gt;Publishing the router's source helps people inspect those decisions. It leaves another question unanswered: is that the program handling my request?&lt;/p&gt;

&lt;p&gt;I am building TeeRouter, an open-source router that explores this question using trusted execution environments and independently verifiable receipts. This is a case study of its public implementation at &lt;a href="https://github.com/wangyi160/teerouter/tree/5c89b551d71040e94c800a944344846c7b0f9e7e" rel="noopener noreferrer"&gt;commit &lt;code&gt;5c89b551&lt;/code&gt;&lt;/a&gt;, rather than an independent audit or verification of a live deployment. The interesting part is how narrow the useful guarantees need to be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the connection
&lt;/h2&gt;

&lt;p&gt;Suppose a service presents a valid hardware attestation report. If the report is unrelated to the TLS connection carrying your prompts, it tells you very little about where those prompts go. An untrusted frontend could show evidence from a legitimate enclave while processing requests somewhere else.&lt;/p&gt;

&lt;p&gt;TeeRouter binds its current TLS certificate and a client-generated challenge into the attestation report. The binding in the &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/src/attestation.rs" rel="noopener noreferrer"&gt;channel implementation&lt;/a&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REPORT_DATA = SHA512(
    UTF8("teellm:attested-channel:v1\0")
    || nonce32
    || SHA256(certDER)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The nonce gives the verifier a freshness challenge. The certificate digest connects the evidence to the certificate used for TLS. The protocol label separates this purpose from other uses of attestation data.&lt;/p&gt;

&lt;p&gt;This only works if the client actually checks that binding and uses the corresponding authenticated connection. Downloading a report, displaying a green badge, and then sending traffic to an unrelated endpoint would discard the useful property.&lt;/p&gt;

&lt;h2&gt;
  
  
  A hardware signature is only the beginning
&lt;/h2&gt;

&lt;p&gt;An authentic report can still describe a program you should not trust. A verifier needs an independently chosen policy defining which measurements and security state it accepts.&lt;/p&gt;

&lt;p&gt;For the TDX path, the project checks certificate chains, revocation and trusted computing base information, measurements, the relevant event sequence, and the report-data binding. The &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/SECURITY-TEE.en.md" rel="noopener noreferrer"&gt;security document&lt;/a&gt; makes the independence requirement explicit: evidence supplied by the server cannot also be the sole authority deciding what counts as trustworthy.&lt;/p&gt;

&lt;p&gt;There is an operational consequence here. Updating the router is also a trust-policy problem. A client must have a defensible reason to accept the new measured software. Automatically trusting every measurement announced by the service would weaken the point of checking measurements at all.&lt;/p&gt;

&lt;p&gt;The application also matters. A correctly attested program with a credential-export endpoint would still export credentials. TEE isolation does not repair bad authorization logic, unsafe dependencies, or mistakes in the approved code. It reduces particular infrastructure trust assumptions under its hardware and software threat model; it does not remove the need for review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate the administrator from the person making a request
&lt;/h2&gt;

&lt;p&gt;A router administrator needs to change balances and permissions. That does not mean the administrator should be able to impersonate a user and spend their balance.&lt;/p&gt;

&lt;p&gt;The current &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/docs/USER-AUTH.en.md" rel="noopener noreferrer"&gt;user authentication protocol&lt;/a&gt; requires a client-owned Ed25519 signature as well as a valid Bearer credential. A user ID is derived from the public key; the signing seed stays with the client.&lt;/p&gt;

&lt;p&gt;The signature covers the exact body bytes, method, path and query, relevant headers, a timestamp, a random nonce, and the router's boot ID. Including authorization and routing headers prevents someone from preserving the body while silently changing the account-pool selection or other signed instructions. Including a boot ID makes proofs from an earlier process invalid after a restart.&lt;/p&gt;

&lt;p&gt;This is a deliberately limited separation of powers. An administrator can still deny service, change permission settings, or alter externally managed balances. What administrator authority alone cannot do, under the verified implementation, is produce a valid signature for the existing user's key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve the request, including the expensive details
&lt;/h2&gt;

&lt;p&gt;AI requests carry more financially significant settings than a model name. Cache controls, service tiers, reasoning options, and tool definitions can all affect behavior or cost.&lt;/p&gt;

&lt;p&gt;TeeRouter's documented forwarding boundary preserves native generation parameters instead of silently adding its own cache or retention choices. Account egress is explicitly configured, official upstream HTTPS certificates remain checked, and a failed proxy is not supposed to fall back to a direct connection. These are application properties to inspect in the approved version, not properties hardware provides automatically.&lt;/p&gt;

&lt;p&gt;There is also a boundary the router cannot cross: the upstream provider still receives the prompt. Attesting an intermediary does not attest the provider's internal inference service, prove which model weights it ran, or establish how it retains requests. A router can preserve a requested parameter; it cannot turn that parameter into independently observed behavior inside another company's infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evidence needs more than one status flag
&lt;/h2&gt;

&lt;p&gt;The project also signs consumption batches. Its &lt;a href="https://github.com/wangyi160/teerouter/blob/5c89b551d71040e94c800a944344846c7b0f9e7e/verifier/README.en.md" rel="noopener noreferrer"&gt;standalone verifier&lt;/a&gt; distinguishes signature verification, record verification, and TEE verification.&lt;/p&gt;

&lt;p&gt;That distinction is useful beyond this project. A mathematically valid signature says that a key signed particular bytes. Hardware evidence and an approved reference policy can establish more about that key's origin. Neither result alone establishes that every request appears in the supplied history or that the latest batch has been disclosed.&lt;/p&gt;

&lt;p&gt;For someone assessing a deployment, I would want separate answers to these questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which software and reference policy did I approve?&lt;/li&gt;
&lt;li&gt;Is this evidence fresh and bound to the connection I am using?&lt;/li&gt;
&lt;li&gt;Which operations remain possible for the administrator?&lt;/li&gt;
&lt;li&gt;Which data and decisions still depend on the upstream provider?&lt;/li&gt;
&lt;li&gt;Which failures can interrupt availability or leave accounting incomplete?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those answers are more useful than a single “TEE verified” label. The practical value is being able to inspect a specific program, verify a connection to an accepted instance, and understand exactly which remaining promises still require trust.&lt;/p&gt;




&lt;p&gt;Writing disclosure: This article was drafted by an AI assistant from the linked public source code and protocol documentation. The account owner maintains TeeRouter.&lt;/p&gt;

</description>
      <category>security</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
