Skip to content

feat(ai): add fast mode support for claude-opus-5 and claude-opus-4-8 - #924

Open
Xsidz wants to merge 4 commits into
PrimeIntellect-ai:mainfrom
Xsidz:fix/anthropic-fast-mode
Open

feat(ai): add fast mode support for claude-opus-5 and claude-opus-4-8#924
Xsidz wants to merge 4 commits into
PrimeIntellect-ai:mainfrom
Xsidz:fix/anthropic-fast-mode

Conversation

@Xsidz

@Xsidz Xsidz commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Adds fast mode support for `claude-opus-5` and `claude-opus-4-8` on the Anthropic API (Claude API only — not Bedrock, Vertex, or Foundry).

Fast mode enables up to 2.5× higher output tokens/second at premium pricing. Per the Anthropic docs, three things are required:

  1. Use the beta messages endpoint (`client.beta.messages.create`)
  2. Pass the `fast-mode-2026-02-01` beta header
  3. Set `speed: "fast"` as a top-level request body parameter

Changes:

  • `packages/ai/src/models.ts` — extended `supportsFastMode` to return `true` for `claude-opus-5` and `claude-opus-4-8` on the `anthropic` provider
  • `packages/ai/src/providers/anthropic.ts`:
    • Added `FAST_MODE_BETA = "fast-mode-2026-02-01"` constant
    • Added `speed?: "fast"` to `AnthropicOptions`
    • Added `useFastMode` param to `createClient`; pushes the beta to `betaFeatures` when set
    • Updated the `createClient` call site to pass `options?.speed === "fast"`
    • Sets `speed: "fast"` on the params in `buildParams` when fast mode is active
    • Routes through `client.beta.messages.create` instead of `client.messages.create` when fast mode is active
  • `packages/ai/test/fast-mode.test.ts` — added 4 new test cases covering supported models, unsupported models, and API mismatch

Test plan

  • `npm run check` passes (biome, tsgo, installer render, browser smoke)
  • `test/fast-mode.test.ts` — 9/9 tests pass including 4 new Anthropic cases
  • All Anthropic unit tests pass: `anthropic-sse-parsing`, `anthropic-eager-tool-input-compat`, `anthropic-thinking-disable`, `anthropic-tool-name-normalization`, `xhigh`, `supports-xhigh`, `interleaved-thinking` — 50 pass, 0 fail
  • Broader unit suite — 87 pass, 0 fail

Fixes #867

Note

Add fast mode support for claude-opus-5 and claude-opus-4-8 on Anthropic

  • Adds a supportsAnthropicFastMode() helper in models.ts that identifies eligible models (claude-opus-5, claude-opus-4-8) on the anthropic-messages API.
  • Extends AnthropicOptions with an optional speed: "fast" field; when set (or when serviceTier is "priority"), requests are routed through the fast-mode-2026-02-01 beta endpoint with speed: "fast" in the payload.
  • Updates AgentSession and createAgentSession in the coding agent to preserve the priority service tier for fast-mode-capable models instead of downgrading to default.
  • Behavioral Change: reported usage costs are doubled when fast mode is active, reflecting Anthropic's 2× pricing for the beta.

Macroscope summarized 04d3c82.

Copilot AI lite review requested due to automatic review settings August 8, 2026 11:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Anthropic “fast mode” plumbing for claude-opus-5 and claude-opus-4-8 (beta header + beta endpoint + speed: "fast" request param), plus model capability detection, tests, and changelog entries.

Changes:

  • Expanded supportsFastMode() to include Anthropic Opus 5 / Opus 4.8 on anthropic-messages.
  • Added speed?: "fast" to AnthropicOptions and routed fast-mode requests through client.beta.messages.create with the fast-mode-2026-02-01 beta header and speed: "fast" param.
  • Added test coverage for the new Anthropic fast-mode model capability checks and updated changelogs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/ai/src/models.ts Expands fast-mode capability detection to Anthropic Opus 5 / 4.8.
packages/ai/src/providers/anthropic.ts Implements fast-mode request wiring (beta header, beta endpoint, request speed).
packages/ai/test/fast-mode.test.ts Adds unit tests for Anthropic fast-mode capability detection.
packages/ai/CHANGELOG.md Documents the new Anthropic fast-mode support in the AI package.
packages/coding-agent/CHANGELOG.md Adds a coding-agent changelog entry referencing the new fast-mode support.
Suppressed comments (2)

packages/ai/src/providers/anthropic.ts:543

  • The beta endpoint routing should be gated the same way as the fast-mode header/body param, otherwise speed: "fast" on unsupported models/providers will route through the beta client and may fail unexpectedly.
			const createFn =
				options?.speed === "fast"
					? (client.beta.messages.create.bind(client.beta.messages) as typeof client.messages.create)
					: client.messages.create.bind(client.messages);

packages/ai/src/providers/anthropic.ts:1079

  • speed: "fast" is currently added to the request params for any model when the option is set. This should be restricted to the supported Claude API models to avoid sending an unknown top-level field to other providers/models handled by this stream implementation.
	if (options?.speed === "fast") {
		// speed is in the beta MessageCreateParamsStreaming but not yet in the base type
		(params as MessageCreateParamsStreaming & { speed?: "fast" }).speed = "fast";
	}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/ai/src/providers/anthropic.ts Outdated
Comment thread packages/ai/src/models.ts Outdated
Comment thread packages/coding-agent/CHANGELOG.md Outdated
Xsidz pushed a commit to Xsidz/prime-agent that referenced this pull request Aug 8, 2026
- Add supportsAnthropicFastMode() separate from supportsFastMode()
  to avoid incorrectly gating serviceTier:"priority" on Anthropic models
- Guard all three fast-mode paths in anthropic.ts with the new check
  so unsupported providers/models are never affected
- Update tests to use the new function and assert supportsFastMode()
  still returns false for Anthropic models
- Clarify coding-agent CHANGELOG entry

Addresses review feedback on PR PrimeIntellect-ai#924

@Xsidz Xsidz left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in af98c34d:

  1. Added supportsAnthropicFastMode() as a separate function from supportsFastMode() — Anthropic fast mode (speed="fast") and the Codex priority service tier (serviceTier="priority") are unrelated features. The existing supportsFastMode gate for serviceTier is unchanged.
  2. All three fast-mode paths in anthropic.ts (beta header, speed body param, client.beta.messages routing) are now guarded with supportsAnthropicFastMode(model), so unsupported providers and models are never affected.
  3. Updated the coding-agent CHANGELOG to clarify this is an AI SDK addition.

@BILLKISHORE

Copy link
Copy Markdown

Two things worth checking before this merges.

Pricing. Fast mode bills at $10/MTok input and $50/MTok output, against Opus 5's catalog entry of cost: { input: 5, output: 25 }. This diff changes no cost path, so a fast request is costed at standard rates and fast usage is under-reported by half. openai-codex-responses covers the equivalent case in applyServiceTierPricing, scaling all four cost components after calculateCost.

Reachability. The diff touches no coding-agent source, so nothing sets options.speed. The agent gates its fast toggle on supportsFastMode (interactive-mode.ts:7679, agent-session.ts:6820, sdk.ts:249), and this PR deliberately keeps that false for Anthropic, so selecting fast on an Opus model still sends a standard request. The coding-agent CHANGELOG entry describes a user-facing change that no code path reaches yet.

The model set looks right. Opus 4.7 returns an error for speed: "fast" and Opus 4.6 silently runs at standard speed while billing standard rates, so excluding both is correct.

I had a branch for #867 going before I saw this one. Not opening it; happy to send the pricing multiplier and the wiring as a follow-up if that is useful.

Xsidz pushed a commit to Xsidz/prime-agent that referenced this pull request Aug 8, 2026
…x pricing

- serviceTier="priority" on claude-opus-5/4-8 now activates fast mode
  (same UX as Codex models, no new toggle needed)
- Apply 2x cost multiplier at both calculateCost call sites since
  catalog rates are $5/$25 but fast mode bills at $10/$50
- Import supportsAnthropicFastMode in agent-session.ts and sdk.ts;
  update all four supportsFastMode gates to also pass through priority
  tier for Anthropic fast-mode models
- Update CHANGELOG to accurately describe the user-visible change

Addresses maintainer feedback on PR PrimeIntellect-ai#924
@Xsidz

Xsidz commented Aug 8, 2026

Copy link
Copy Markdown
Author

Good catches, both of them. Fixed in f937323.

Pricing: added a 2x multiplier after both calculateCost call sites in anthropic.ts, the same pattern applyServiceTierPricing uses for Codex. The catalog entry stays at $5/$25 since that's the standard rate; the multiplier only fires when fast mode is actually active.

Reachability: serviceTier="priority" on claude-opus-5 and claude-opus-4-8 now passes through all four supportsFastMode gates in agent-session.ts and sdk.ts by also checking supportsAnthropicFastMode, so the existing priority toggle in the UI activates fast mode without needing a new option. The CHANGELOG now describes the user-visible behavior rather than the internal plumbing.

Happy to add a follow-up if there's anything I missed.

@Xsidz
Xsidz force-pushed the fix/anthropic-fast-mode branch 2 times, most recently from d3afc9f to 306b217 Compare August 11, 2026 17:35
Siddhesh Kabra added 4 commits August 11, 2026 23:32
When speed='fast':
- Adds fast-mode-2026-02-01 beta header via createClient
- Routes through client.beta.messages.create
- Sets speed='fast' in the request body

Also extends supportsFastMode() to return true for the two
Anthropic models that support it.

Part of fixes PrimeIntellect-ai#867
Verifies claude-opus-5 and claude-opus-4-8 are supported, other
Anthropic models are rejected, and API mismatches are rejected.

Part of fixes PrimeIntellect-ai#867
- Add supportsAnthropicFastMode() separate from supportsFastMode()
  so serviceTier:"priority" only passes through for Anthropic fast
  models, not for Codex-only gate
- serviceTier="priority" on claude-opus-5/4-8 now activates fast mode
- Apply 2x cost multiplier after calculateCost for fast requests
- Update coding-agent CHANGELOG with accurate user-visible description

Part of fixes PrimeIntellect-ai#867
@Xsidz
Xsidz force-pushed the fix/anthropic-fast-mode branch from 306b217 to 04d3c82 Compare August 11, 2026 18:05
@BILLKISHORE

Copy link
Copy Markdown

Both fixes came through the restructure intact, and splitting supportsAnthropicFastMode from supportsFastMode is a better shape than widening the Codex gate.

One thing worth thinking about before this lands: fast mode is a gated research preview. The docs say access is granted per account ("contact your account manager", otherwise a waitlist), so most accounts cannot use it today.

On current main, serviceTier is never read in anthropic.ts, so toggling fast mode on an Anthropic model is a harmless no-op. After this PR the same toggle sends speed: "fast" with the beta header, and there is no fallback in the diff. For an account without preview access that turns a no-op into a failed request, on a toggle that /fast presents as a plain on/off.

The existing degradation at agent-session.ts:9027 does not cover it, since it tests model capability and access here is an account property that no model check can see.

A couple of options depending on how defensive you want to be. Catching the access error once and retrying without speed would keep the toggle harmless for accounts that lack it, at the cost of one wasted round trip. Alternatively, leaving the request to fail but surfacing a message that names fast mode as the reason would at least make the failure legible, since the current path gives the user a bare API error from a toggle they just flipped.

One smaller naming point: the Anthropic docs state fast mode is not available alongside a Priority Tier commitment. Prime Agent's serviceTier: "priority" is a local concept and never reaches Anthropic on the wire, so there is no actual conflict, but an account that has both a Priority Tier commitment and fast-mode access would find "priority" meaning the opposite of what Anthropic means by it. Probably worth a sentence in the docs.

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.

Support Opus 5 and Opus 4.8 fast on Anthropic API

3 participants