← Back to PRs

#15397: feat: support Anthropic speed:"fast" parameter passthrough

by mode80 open 2026-02-13 11:34 View on GitHub →
agents size: M
## Summary Adds support for Anthropic's [fast mode](https://docs.anthropic.com/en/docs/about-claude/models#fast-mode) (`speed: "fast"`) via model params config. Fast mode delivers ~2.5x faster output tokens on Claude Opus 4.6 at premium pricing. Closes #12176 ## Changes **`src/agents/pi-embedded-runner/extra-params.ts`** - New `resolveAnthropicSpeed()` — extracts `speed: "fast"` from model params (Anthropic-only, ignored for other providers) - New `appendAnthropicBeta()` — safely appends beta features to the `anthropic-beta` header without overwriting existing betas (interleaved-thinking, fine-grained-tool-streaming, etc.) - Modified `createStreamFnWithExtraParams()` — when speed is detected: 1. Injects `speed` into the API request body via `onPayload` callback 2. Appends `fast-mode-2026-02-01` to the `anthropic-beta` header **`src/agents/pi-embedded-runner.ts`** — re-exports `appendAnthropicBeta` for testing **`src/agents/pi-embedded-runner-extraparams.test.ts`** — 7 new tests covering beta header appending, speed injection via config and override, provider isolation, and param combination ## Configuration ```json { "agents": { "defaults": { "models": { "anthropic/claude-opus-4-6": { "params": { "speed": "fast" } } } } } } ``` ## Implementation Note The `onPayload` callback is used to inject `speed` into the request body because pi-ai's `buildParams()` doesn't yet recognize the `speed` parameter. This is a functional bridge — once pi-ai adds native `speed` support in `buildParams()`, the `onPayload` injection can be replaced with a simple passthrough (like `temperature`). Similarly, `appendAnthropicBeta()` works around `mergeHeaders()` using `Object.assign` (which overwrites rather than appends the `anthropic-beta` header). A pi-ai fix to append comma-separated beta values would make this helper unnecessary. Both workarounds are safe, tested, and forward-compatible with native pi-ai support. ## Test Results All 13 tests pass (6 existing + 7 new): ``` ✓ src/agents/pi-embedded-runner-extraparams.test.ts (13 tests) 10ms ``` TypeScript compilation clean (`tsc --noEmit` passes). <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends the embedded pi-agent runner’s “extra params” passthrough to support Anthropic fast mode. When `params.speed === "fast"` is set for an `anthropic/*` model, the stream wrapper injects `speed: "fast"` into the request body via `onPayload` and appends the required `fast-mode-2026-02-01` value to the `anthropic-beta` header without overwriting existing beta flags. It also re-exports the helper used to append beta values and adds unit tests covering header merging, payload injection, provider isolation, and combination with existing stream params like `temperature`. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Changes are narrow in scope (Anthropic-only), preserve existing behavior for other providers, and are covered by focused unit tests for both header handling and payload injection. No verified regressions or correctness issues were found in the modified code paths. - No files require special attention <sub>Last reviewed commit: 763f81b</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs