#15397: feat: support Anthropic speed:"fast" parameter passthrough
agents
size: M
Cluster:
Bedrock and Caching Improvements
## 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
#10108: fix: override stale Anthropic OAuth stealth headers for Opus 4.6
by CivilBooks · 2026-02-06
76.8%
#22303: fix: extend cacheRetention auto-injection and runtime pass-through ...
by snese · 2026-02-21
74.8%
#20428: feat: capture Anthropic rate-limit response headers to disk
by AndrewArto · 2026-02-18
74.0%
#23700: feat: Claude CLI personal-use auth (no API key required) + native A...
by 88plug · 2026-02-22
73.8%
#21517: fix: preserve pi-ai default betas when context1m/anthropicBeta over...
by ManuelFerreras · 2026-02-20
73.3%
#10214: feat(compaction): Add Anthropic server-side compaction API support
by GodsBoy · 2026-02-06
73.1%
#22618: feat(tts): add OpenAI TTS speed parameter support
by useramuser · 2026-02-21
72.5%
#12248: fix: wire streaming config field through resolveExtraParams to stre...
by mcaxtr · 2026-02-09
72.1%
#14640: feat(agents): support per-agent temperature and maxTokens in agents...
by lailoo · 2026-02-12
72.1%
#7821: feat: Support ANTHROPIC_BASE_URL environment variable for custom en...
by y1y2u3u4 · 2026-02-03
72.1%