Add Bedrock model profile for xAI Grok 4.6 and 4.7
Merged
AH
10d ago+275+275+012345678901234567890123456789-10-10-01234567890123456789
- Closes #8727
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 ofBedrockModelProfile.bedrock_thinking_variant- The four ids above in
LatestBedrockModelNamesandKnownModelName(includinggateway/bedrock:)
User-visible behavior
thinkingis sent asadditionalModelRequestFields={'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, sothinking=Falseis 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_pandtop_kare dropped with a warning (bedrock_disallows_sampling_settings), since Converse rejects them on Grok 4.6 withValidationException: 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
test_bedrock_xai_grokpins the resolved profile for all four ids.test_xai_variant_*cover every unified level,thinking=False,thinking=Trueon Grok 4.7, and a user-suppliedreasoningwinning.test_bedrock_xai_grok_*cover forced tool choice andToolOutputwith thinking.test_bedrock_xai_grok_drops_sampling_settingscovers the dropped sampling settings.- No cassettes: our Bedrock test account gets
AccessDeniedExceptionfor every Grok inference profile, so the tests stay at the profile and request-mapping level.
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.6andglobal.xai.grok-4.6only;xai.grok-4.6is served by Bedrock Mantle only. - Effort levels
low(default),medium,high,xhighare accepted viaadditionalModelRequestFields: {"reasoning": {"effort": "<level>"}};maxreturns a 400. inferenceConfig.temperature,topPandtop_kare rejected with aValidationException(This model doesn't support the temperature field. Remove temperature and try again.).toolConfigworks with all threetoolChoicemodes (auto,any,tool).- Explicit
cachePointblocks returnAccessDeniedException; only implicit prompt caching applies, sobedrock_supports_prompt_cachingstaysFalse.
PR decisions
2026-10-22 · thread 1: forced tool choice with thinking on xai · iter -
- Decision: Exempt the xai variant in _thinking_blocks_tool_forcing so tool_choice='required'/single tool/ToolOutput work with thinking
- Why: Converse accepts all toolChoice modes for Grok while it reasons (Macroscope flagged UserError)
- Source: https://github.com/pydantic/pydantic-ai/pull/8639#discussion_r4105394626
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 -
- Decision: The xai Bedrock variant omits reasoning for thinking=True when the profile sets grok_default_effort_omitted (Grok 4.7), matching the direct xAI adapter
- Why: thinking=True means the provider's default effort; Grok 4.7's default is high, so sending medium would lower it
- Source: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-xai-grok-4-7.html
2026-10-22 · Grok 4.7 structured output stays off · iter -
- Decision: supports_json_schema_output/supports_json_object_output stay False for Grok 4.7 even though its card lists structured outputs as supported
- Why: Not verifiable: the test account has no Grok access on Converse
- Source: https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-xai-grok-4-7.html
2026-10-22 · API gate waiver for LatestBedrockModelNames · iter -
- Decision: Add the exact waiver for the
LatestBedrockModelNameswidening (against v2.59.0) to.github/api-compatibility-allowlist.json; the advisoryProtect .githubcheck 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.