Skip to content

Add prompt caching, default to Sonnet 5.5, and offer Haiku 5.5 - #49

Merged
DIodide merged 10 commits into
mainfrom
feat/prompt-caching
Nov 30, 2026
Merged

DIodide merged 10 commits into
mainfrom
feat/prompt-caching

Conversation

@aikhanjum

Copy link
Copy Markdown
Collaborator

PI currently defaults to Opus and sends reusable prompt prefixes without cache markers. This makes Sonnet 5.5 the default and adds Haiku 5.5, including the request in TIG-311.

  • Apply five-minute cache breakpoints to the system prefix and final conversation block for every Claude call, including tool-result follow-ups and budget downgrades.
  • Share model selection between browser preferences and the server. Preserve existing Opus choices and migrate old Sonnet 5 or retired choices to Sonnet 5.5.
  • Keep Haiku selected when the weekly budget restricts Opus to Sonnet. Leave the existing dollar allowances unchanged.
  • Add Haiku pricing, applying its higher rates only to individual requests above 100,000 prompt tokens. Correct Sonnet 5.5 cache-read pricing using Anthropic's price list.

Stacked on #34, which depends on #33. Merge order is #33, #34, then this PR.

Validation passed with the repository's example development variables.

  • npx wrangler types
  • npm run typecheck
  • npm test, 78 passed and 0 failed
  • npm run build
  • git diff --check

Tests capture real SDK request bodies for all three models, including streaming and tool results, and cover budget selection and Haiku pricing thresholds. Provider responses are mocked. Live inference, signed-in UI behavior, and actual cache hits have not been verified. The installed Anthropic SDK accepts Haiku 5.5 through its compatibility path and emits an informational 128,000-token output-limit warning.

Implemented with Codex assistance.

aikhanjum and others added 4 commits October 8, 2026 19:24
Each turn now ends with one structured pi.usage log line: model, steps,
uncached input, cache reads and writes, output, reasoning, web searches,
estimated USD and wall time, with the student as a keyed pseudonym
instead of a NetID. This is the data for the PI cost analysis and the
basis for a per-student usage limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copies PrincetonCourses' ask-gateway tiers in dollars: $3 on any model,
then Sonnet 5 only for $1 more, then PI stops answering until enough
spend ages out of a rolling 7-day window. Spend is recorded per turn on
the student's desk object and pruned on write, so nothing wakes the
desk on a timer. An exhausted student gets the limit note from a
stand-in model that never calls Anthropic. Amounts are Worker vars.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every Claude call now goes through an AI SDK middleware that sets two
Anthropic cache breakpoints: the last system message (covers tool
definitions and the system prompt) and the last message (rolling, so each
step and each turn reads the previous prefix from cache). The production
key showed zero cache reads over two months, so every step paid full input
price. Wire tests capture the request body and check the breakpoints land.

Sonnet 5 is the default model in the server, shared settings and the
client store, per Ibraheem; Opus stays a per-chat choice. The budget note
no longer calls tier 1 "the Opus budget", since a Sonnet-only student can
use it up too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AbJwLPGAUb8rEEDz2ZR2iq

@DIodide DIodide left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed b66133a against feat/weekly-usage-limit. No blocking findings in this change.

Checked shared model selection/migration, tier-two preservation of Haiku, middleware application to normal and downgraded models, tool-result/streaming cache markers, and per-request long-context pricing. The Sonnet 5.5 cache-read rate and both Haiku 5.5 pricing tiers match Anthropic's current documentation.

Validation in an isolated checkout with example development variables: npm ci, npx wrangler types, npm run typecheck, npm test (78 passed), npm run build, and git diff --check all passed. Live inference and actual cache hits were not exercised. The SDK emits its documented Haiku compatibility warning.

This approval covers #49. Its base is the still-open #34 branch, which depends on #33; landing the full feature on main still requires handling that stack.

@DIodide DIodide left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after bringing current main through the parent stack. No blocking findings or implementation fixes needed. Prompt-cache markers, model migration/defaults, tier-two Haiku selection, and per-request pricing retain their intended behavior alongside current main.

Validation: Wrangler types, typecheck, all 111 tests, production build, and git diff --check passed. The built Worker ledger smoke test also passed. Live inference/cache-hit verification remains outside these mocked/local checks. Approved for landing after #33 and #34.

@DIodide DIodide left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked after #33 was squash-merged into main. The base-history update has an identical file tree to the reviewed and locally tested head; no implementation changed. Approval stands. Waiting for the new head CI before merging in stack order.

Base automatically changed from feat/weekly-usage-limit to main November 30, 2026 20:38
@DIodide
DIodide changed the base branch from feat/weekly-usage-limit to main November 30, 2026 20:38

@DIodide DIodide left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked after #34 merged and this PR retargeted to main. The squash-merge ancestry conflicts were resolved by retaining the already-reviewed #49 changes. Verified that this head has exactly the same file tree as 8f1ed52 (111 local tests, typecheck, build, Worker ledger smoke test, and GitHub CI passed). No implementation changed. Approved; waiting for the new head CI before merge.

@DIodide
DIodide merged commit 13da34a into main Nov 30, 2026
2 checks passed
@DIodide
DIodide deleted the feat/prompt-caching branch November 30, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants