Skip to content

Add anthropic speed, fast mode for opus 4.6#4300

Merged
dsfaccini merged 38 commits intopydantic:mainfrom
bohdanhr:add-anthropic-speed
Apr 28, 2026
Merged

Add anthropic speed, fast mode for opus 4.6#4300
dsfaccini merged 38 commits intopydantic:mainfrom
bohdanhr:add-anthropic-speed

Conversation

@bohdanhr
Copy link
Copy Markdown
Contributor

@bohdanhr bohdanhr commented Feb 11, 2026

Pre-Review Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Linting and type checking pass per make format and make typecheck.
  • PR title is fit for the release changelog.

Pre-Merge Checklist

  • New tests for any fix or new behavior, maintaining 100% coverage.
  • Updated documentation for new features and behaviors, including docstrings for API docs.

@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) feature New feature request, or PR implementing a feature (enhancement) labels Feb 11, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@bohdanhr bohdanhr changed the title Add anthropic speed Add anthropic speed, fast mode for opus 4.6 Feb 11, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

Comment thread pydantic_ai_slim/pydantic_ai/profiles/anthropic.py Outdated
@bohdanhr bohdanhr requested a review from DouweM February 12, 2026 10:58
devin-ai-integration[bot]

This comment was marked as resolved.

bohdanhr and others added 4 commits February 12, 2026 15:04
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

@dsfaccini
Copy link
Copy Markdown
Collaborator

this is green now but the tests need to be made VCR

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread docs/models/anthropic.md Outdated
@bohdanhr
Copy link
Copy Markdown
Contributor Author

@dsfaccini im consistently getting 429 throttled trying to make calls to anthropic with fast mode, would you be able to try?

@dsfaccini
Copy link
Copy Markdown
Collaborator

hey @bohdanhr I've actually been blocked for a couple days bc my personal org has no access to fast mode (waitlisted), I'm trying to use it through our gateway to see if that works

@bohdanhr
Copy link
Copy Markdown
Contributor Author

@dsfaccini same here, we are not waitlisted either.

…gnore

- Revert task budget changes merged in from another feature; they belong in pydantic#5140
- Restrict fast-mode support to Claude Opus 4.6 only (per Anthropic docs)
- Silently ignore `anthropic_speed` on unsupported models (no UserWarning),
  per DouweM's review and models/AGENTS.md convention
- OMIT `speed` on unsupported models regardless of value (not just for 'fast')
- Document prompt-cache invalidation when switching speeds, and that fast mode
  is not available on Bedrock/Vertex
- Fix docs example to use claude-opus-4-6
- Remove stale untracked cassettes from failed real-API recording attempts
devin-ai-integration[bot]

This comment was marked as resolved.

Fast mode is only available on the direct Anthropic API. Even when the model
supports it (Opus 4.6), sending `speed` via Bedrock, Vertex, or Foundry clients
would likely error at the provider gateway. Add `_FAST_MODE_UNSUPPORTED_CLIENTS`
and check client type in `_effective_speed` and the fast-mode beta gate.
devin-ai-integration[bot]

This comment was marked as resolved.

The `_FAST_MODE_UNSUPPORTED_CLIENTS` tuple already blocks fast mode on Foundry
clients, but the user-facing docstring and docs admonition only listed Bedrock
and Vertex. Update both so Foundry users know `anthropic_speed` is silently
omitted on their client too.
Comment thread tests/models/test_anthropic.py Outdated
Comment on lines +1978 to +1980
from unittest.mock import AsyncMock, MagicMock

import anthropic
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

move these up top please

- _effective_speed emits UserWarning when 'fast' is set on an
  unsupported model or client (Bedrock/Vertex/Foundry); still omits
  `speed` from the request
- Update anthropic_speed docstring to document the warning behavior
- Move `import anthropic` and `AsyncMock, MagicMock` out of
  test_anthropic_speed_omitted_on_non_direct_clients to the top of
  tests/models/test_anthropic.py
- Update tests to assert the warning (UserWarning with match) for the
  'fast' + unsupported-model and non-direct-client cases
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Reverts the UserWarning added in 015d076. Per DouweM's review (2026-02-13)
and pydantic_ai/models/AGENTS.md, unsupported model settings must be
silently ignored at runtime; the field docstring already documents the
limit. Also reverts the docs note added in 71db952.
devin-ai-integration[bot]

This comment was marked as resolved.

dsfaccini and others added 6 commits April 26, 2026 17:50
Per DouweM's review, the two-call split in `prepare_request` was deliberate:
warn once against the user's input early, then silently scrub any sampling
params re-introduced by the post-`super().prepare_request` merge of defaults.
Earlier branch commits collapsed the two calls into one (e7aa77a) and then
removed the now-unused `warn` param for coverage (a44ad41), which moved the
warning point and could fire for params the user never set. This restores
the original main-branch structure.
@dsfaccini dsfaccini merged commit f0b1947 into pydantic:main Apr 28, 2026
45 checks passed
Alex-Resch pushed a commit to Alex-Resch/pydantic-ai that referenced this pull request Apr 29, 2026
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: David Sanchez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic feature New feature request, or PR implementing a feature (enhancement) size: M Medium PR (101-500 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable fast mode with anthropic opus 4.6

4 participants