Add Bedrock model profile for xAI Grok 4.6 and 4.7

Merged
AH
10d ago
+275-10

Why we make these changes

xAI Grok on Bedrock Converse (us.xai.grok-4.6, global.xai.grok-4.6, us.xai.grok-4.7, global.xai.grok-4.7) gets no model profile: BedrockProvider.model_profile has no xai entry. So tool_choice='required' is refused and the unified thinking setting is ignored. This adds an xai profile that composes grok_model_profile with Bedrock tool-choice support and a new 'xai' thinking variant.

New public surface

  • pydantic_ai.providers.bedrock.bedrock_xai_model_profile
  • 'xai' as a value of BedrockModelProfile.bedrock_thinking_variant
  • The four ids above in LatestBedrockModelNames and KnownModelName (including gateway/bedrock:)

User-visible behavior

  • thinking is sent as additionalModelRequestFields={'reasoning': {'effort': ...}}: 'minimal' → 'low', 'xhigh' passes through. True → 'medium' on Grok 4.6 and leaves the effort out on Grok 4.7, whose default is 'high'. Grok always reasons, so thinking=False is ignored.
  • Forced tool choice (tool_choice='required', a single forced tool, ToolOutput) keeps working while Grok thinks. Other non-Claude Bedrock models that think still fall back to native or prompted output. Converse accepting this was observed on Grok 4.6; Grok 4.7 is assumed to match.
  • temperature, top_p and top_k are dropped with a warning (bedrock_disallows_sampling_settings), since Converse rejects them on Grok 4.6 with ValidationException: This model doesn't support the temperature field; Grok 4.7 is assumed to match.
  • JSON schema and JSON object output stay off. The Grok 4.6 model card lists structured output as not supported on Converse; the Grok 4.7 card lists it as supported, but it stays off until verified.

Verification

What changes for existing users

Nothing. Only requests to Bedrock xai.* models change.

Live Converse observations on Grok 4.6 (from the original PR)
  • Model ids are us.xai.grok-4.6 and global.xai.grok-4.6 only; xai.grok-4.6 is served by Bedrock Mantle only.
  • Effort levels low (default), medium, high, xhigh are accepted via additionalModelRequestFields: {"reasoning": {"effort": "<level>"}}; max returns a 400.
  • inferenceConfig.temperature, topP and top_k are rejected with a ValidationException (This model doesn't support the temperature field. Remove temperature and try again.).
  • toolConfig works with all three toolChoice modes (auto, any, tool).
  • Explicit cachePoint blocks return AccessDeniedException; only implicit prompt caching applies, so bedrock_supports_prompt_caching stays False.
PR decisions

2026-10-22 · thread 1: forced tool choice with thinking on xai · iter -

2026-10-22 · add Grok 4.7 alongside 4.6 · iter -

  • Decision: Add us.xai.grok-4.7 and global.xai.grok-4.7 to every list the PR adds the 4.6 ids to (LatestBedrockModelNames, KnownModelName incl. gateway/bedrock:, docs thinking table), and pin 4.7 profile resolution in the 4.6 test
  • Why: Bedrock now serves Grok 4.7 (cross-region ids only, same reasoning levels as 4.6, default high)
  • Source: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-xai-grok-4-7.html

2026-10-22 · port xai forced-tool exemption onto main's guards · iter -

  • Decision: Main (#8808, #8812) removed _thinking_blocks_tool_forcing; the xai exemption now lives in one predicate, _thinking_rejects_tool_forcing, used by _default_structured_output_mode, prepare_request and _support_tool_forcing. Dropped the PR's noqa: C901, which main's refactor made unused.
  • Why: Keep the PR's intent (Grok accepts a forced toolChoice while reasoning) on main's API without scattering variant checks
  • Source: https://github.com/pydantic/pydantic-ai/pull/8812
  • Supersedes: thread 1: forced tool choice with thinking on xai

2026-10-22 · thinking=True on Grok 4.7 keeps the model default · iter -

2026-10-22 · Grok 4.7 structured output stays off · iter -

2026-10-22 · API gate waiver for LatestBedrockModelNames · iter -

  • Decision: Add the exact waiver for the LatestBedrockModelNames widening (against v2.59.0) to .github/api-compatibility-allowlist.json; the advisory Protect .github check fails on this fork PR as expected
  • Why: agent_docs/api-design.md requires an exact waiver for a permitted change the gate reports
  • Source: https://github.com/pydantic/pydantic-ai/pull/8639

2026-10-22 · drop sampling settings for Grok on Bedrock · iter -

  • Decision: Set bedrock_disallows_sampling_settings in bedrock_xai_model_profile; Grok 4.7 structured output stays off, documented as unverified
  • Why: Grok 4.6 rejects temperature, topP and top_k with a ValidationException on Converse; #8668's flag covers this
  • Source: https://github.com/pydantic/pydantic-ai/pull/8668

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.