Skip to content

feat(models): support Grok 4.5/4.6 on xAI and OpenRouter - #2871

Merged
naorpeled merged 1 commit into
The-PR-Agent:mainfrom
PeterDaveHello:feature/grok45And46Support
Aug 30, 2026
Merged

feat(models): support Grok 4.5/4.6 on xAI and OpenRouter#2871
naorpeled merged 1 commit into
The-PR-Agent:mainfrom
PeterDaveHello:feature/grok45And46Support

Conversation

@PeterDaveHello

Copy link
Copy Markdown
Contributor

Summary

  • register published Grok 4.5 and 4.6 model IDs, aliases, and canonical OpenRouter routes with 500K context windows
  • clamp always-on Grok reasoning effort to model-specific levels for native xAI and OpenRouter requests
  • add a targeted compatibility workaround for the LiteLLM grok-build-latest registry gap
  • update the xAI configuration guide with aliases, defaults, global effort impact, and routing limitations

Behavior changes

  • PR-Agent sends its configured reasoning effort, medium by default, to Grok 4.5 and 4.6; high restores the native xAI default but also affects other registered reasoning models
  • none and minimal map to low because reasoning cannot be disabled
  • max and xhigh map to high on Grok 4.5; Grok 4.6 retains xhigh and maps max to xhigh
  • OpenRouter-specific precedence is resolved before the same Grok clamp is applied
  • OpenRouter routing suffixes such as :nitro currently require custom_model_max_tokens

Testing

  • focused token, reasoning, OpenRouter, and handler suites: 239 passed
  • Python compilation and git diff whitespace checks passed

References

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Support Grok 4.5 and 4.6 across xAI and OpenRouter

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Registers Grok 4.5/4.6 routes with 500K context windows.
• Clamps always-on reasoning effort across native xAI and OpenRouter requests.
• Documents configuration behavior and verifies token, routing, and LiteLLM compatibility.
Diagram

sequenceDiagram
    participant C as Configuration
    participant H as LiteLLM Handler
    participant R as Model Registry
    participant G as Grok Clamp
    participant L as LiteLLM
    participant P as xAI or OpenRouter
    C->>H: Model and effort
    H->>R: Resolve capabilities
    R-->>H: Context and levels
    H->>G: Normalize final effort
    G-->>H: Supported effort
    H->>L: Provider request
    L->>P: Route completion
    P-->>L: Model response
    L-->>H: Completion result
Loading
High-Level Assessment

The model-specific capability table plus shared clamp helpers fits the existing registry-based design and keeps native xAI and OpenRouter behavior consistent. Relying solely on LiteLLM was considered but is unsuitable while the pinned registry omits grok-build-latest and does not encode the required always-on, generation-specific effort semantics.

Files changed (6) +260 / -2

Enhancement (2) +67 / -0
__init__.pyRegister Grok models and reasoning capabilities +20/-0

Register Grok models and reasoning capabilities

• Adds native xAI and canonical OpenRouter Grok 4.5/4.6 IDs with 500K context windows. Registers reasoning-capable aliases and defines generation-specific accepted effort levels.

pr_agent/algo/init.py

litellm_ai_handler.pyClamp and route Grok reasoning effort +47/-0

Clamp and route Grok reasoning effort

• Adds Grok model normalization and effort clamping for native xAI and OpenRouter requests after provider-specific precedence is resolved. It also allowlists reasoning_effort for grok-build-latest to bridge the pinned LiteLLM registry gap.

pr_agent/algo/ai_handlers/litellm_ai_handler.py

Tests (2) +184 / -0
test_get_max_tokens.pyVerify Grok 500K context windows +20/-0

Verify Grok 500K context windows

• Adds parameterized coverage confirming all registered xAI aliases and canonical OpenRouter routes resolve to 500,000 tokens.

tests/unittest/test_get_max_tokens.py

test_litellm_reasoning_effort.pyCover Grok reasoning and LiteLLM compatibility +164/-0

Cover Grok reasoning and LiteLLM compatibility

• Tests generation-specific effort levels, clamp mappings, native xAI forwarding, OpenRouter precedence and budgets, routing suffixes, invalid overrides, and the grok-build-latest LiteLLM allowlist workaround.

tests/unittest/test_litellm_reasoning_effort.py

Documentation (1) +8 / -2
changing_a_model.mdDocument Grok 4.5/4.6 setup and reasoning behavior +8/-2

Document Grok 4.5/4.6 setup and reasoning behavior

• Updates the xAI example to Grok 4.6 and documents registered IDs, aliases, 500K context windows, reasoning-effort clamping, OpenRouter precedence, and routing-suffix token limitations.

docs/docs/usage-guide/changing_a_model.md

Other (1) +1 / -0
configuration.tomlClarify always-on reasoning clamping +1/-0

Clarify always-on reasoning clamping

• Documents that explicit none effort is clamped to the lowest supported level for always-on models such as Grok.

pr_agent/settings/configuration.toml

@qodo-code-review

qodo-code-review Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (2) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. reasoning_effort comment uses narrative phrasing 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The added comment says the setting “keeps” reasoning disabled and describes Grok behavior
narratively rather than using imperative phrasing. Rewrite it as an instruction, such as “Use none
to keep reasoning disabled...” while retaining the Grok exception.
Code

pr_agent/settings/configuration.toml[R423-425]

+# Explicit openrouter.reasoning_effort = "none" keeps reasoning disabled, except on
+# Grok 4.5/4.6: there "none" is clamped to the lowest supported
+# effort first, so a positive budget wins over it.
Relevance

●●● Strong

Recent configuration-comment precedents consistently accepted imperative rewrites, including
matching phrasing-rule findings.

PR-#2823
PR-#2796
PR-#2862

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 2694688 requires newly added behavior-describing comments to use imperative
phrasing. The added comment at lines 423-425 narrates what the setting does rather than instructing
the reader how to configure it.

Rule 2694688: Docstrings and comments must use imperative phrasing
pr_agent/settings/configuration.toml[423-425]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new `openrouter.reasoning_effort` comment uses descriptive third-person phrasing (`keeps`, `is clamped`) instead of imperative phrasing.

## Issue Context
Preserve the documented Grok 4.5/4.6 exception and budget precedence while rewriting the comment as an instruction.

## Fix Focus Areas
- pr_agent/settings/configuration.toml[423-425]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Grok docs exceed 120 characters 📘 Rule violation ⚙ Maintainability
Description
The newly added Grok documentation paragraphs on lines 196, 198, and 200 each exceed the
120-character maximum. These paragraphs should be wrapped across physical lines to satisfy the
repository-wide line-length requirement.
Code

docs/docs/usage-guide/changing_a_model.md[196]

+Grok 4.5 and Grok 4.6 are registered with a 500K token context window (`xai/grok-4.5`, `xai/grok-4.5-latest`, `xai/grok-build-latest`, `xai/grok-4.6`, `openrouter/x-ai/grok-4.5`, `openrouter/x-ai/grok-4.6`). xAI publishes `grok-4.5-latest` and `grok-build-latest` aliases for Grok 4.5; Grok 4.6 currently has no published alias.
Relevance

● Weak

Recent repository precedents explicitly rejected identical requests to wrap long Markdown
documentation lines for the 120-character rule.

PR-#2817
PR-#2774

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2694690 requires every non-generated modified source line to be at most 120
characters. The PR adds three unwrapped Markdown paragraphs whose physical lines substantially
exceed that limit.

Rule 2694690: Enforce maximum line length of 120 characters
docs/docs/usage-guide/changing_a_model.md[196-196]
docs/docs/usage-guide/changing_a_model.md[198-198]
docs/docs/usage-guide/changing_a_model.md[200-200]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly added Grok documentation paragraphs exceed the required 120-character maximum line length.

## Issue Context
Wrap the Markdown source without changing the rendered paragraph content or meaning.

## Fix Focus Areas
- docs/docs/usage-guide/changing_a_model.md[196-196]
- docs/docs/usage-guide/changing_a_model.md[198-198]
- docs/docs/usage-guide/changing_a_model.md[200-200]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Context sources
✅ Compliance rules (platform): 34 rules
Review mode: ⚖️ Balanced: The push changes runtime model registration and reasoning/precedence behavior across native xAI and OpenRouter paths, creating real compatibility and request-shaping risk, but not enough independent logic for extended review.

Grey Divider

Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 7b3168d ⚖️ Balanced

Results up to commit 08e4918 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 📜 Skill insights (0)


Informational
1. Grok docs exceed 120 characters 📘 Rule violation ⚙ Maintainability
Description
The newly added Grok documentation paragraphs on lines 196, 198, and 200 each exceed the
120-character maximum. These paragraphs should be wrapped across physical lines to satisfy the
repository-wide line-length requirement.
Code

docs/docs/usage-guide/changing_a_model.md[196]

+Grok 4.5 and Grok 4.6 are registered with a 500K token context window (`xai/grok-4.5`, `xai/grok-4.5-latest`, `xai/grok-build-latest`, `xai/grok-4.6`, `openrouter/x-ai/grok-4.5`, `openrouter/x-ai/grok-4.6`). xAI publishes `grok-4.5-latest` and `grok-build-latest` aliases for Grok 4.5; Grok 4.6 currently has no published alias.
Relevance

● Weak

Recent repository precedents explicitly rejected identical requests to wrap long Markdown
documentation lines for the 120-character rule.

PR-#2817
PR-#2774

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2694690 requires every non-generated modified source line to be at most 120
characters. The PR adds three unwrapped Markdown paragraphs whose physical lines substantially
exceed that limit.

Rule 2694690: Enforce maximum line length of 120 characters
docs/docs/usage-guide/changing_a_model.md[196-196]
docs/docs/usage-guide/changing_a_model.md[198-198]
docs/docs/usage-guide/changing_a_model.md[200-200]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly added Grok documentation paragraphs exceed the required 120-character maximum line length.

## Issue Context
Wrap the Markdown source without changing the rendered paragraph content or meaning.

## Fix Focus Areas
- docs/docs/usage-guide/changing_a_model.md[196-196]
- docs/docs/usage-guide/changing_a_model.md[198-198]
- docs/docs/usage-guide/changing_a_model.md[200-200]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@IsmaelMartinez IsmaelMartinez left a comment

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.

Thanks, this is carefully done and the tests earn it: 29 of the 35 go red when the source is reverted, and of the six that stay green, four are the litellm registry pins your docstring flags as deliberate.

One suggestion inline on configuration.toml, then this is good to go.

Qodo's line-length finding on changing_a_model.md I would leave alone. The same rule has been raised and let through on #2817 and #2774, and that file already carries lines of 1098 and 785 characters.

Comment thread pr_agent/settings/configuration.toml
@PeterDaveHello
PeterDaveHello force-pushed the feature/grok45And46Support branch from 08e4918 to 7b3168d Compare August 29, 2026 11:21
@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit 7b3168d

@naorpeled

Copy link
Copy Markdown
Member

Hey @PeterDaveHello,
Thanks for this!
Could you please resolve the merge conflicts?

Register published xAI model IDs and aliases, plus their canonical
OpenRouter routes, with 500K context windows so token budgeting works
without custom limits.

Clamp always-on Grok reasoning values to model-specific levels for
native xAI and OpenRouter calls. Allow reasoning_effort through pinned
LiteLLM for the grok-build-latest alias missing from its registry.

PR-Agent sends its configured effort, medium by default, to these
models; use high to retain xAI's native default.

References:
- https://docs.x.ai/developers/models/grok-4.5
- https://docs.x.ai/developers/models/grok-4.6
- https://openrouter.ai/docs/guides/best-practices/reasoning-tokens
@PeterDaveHello
PeterDaveHello force-pushed the feature/grok45And46Support branch from 7b3168d to cb8fa07 Compare August 30, 2026 04:19
@qodo-code-review

qodo-code-review Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@naorpeled
naorpeled merged commit 505997f into The-PR-Agent:main Aug 30, 2026
5 checks passed
@naorpeled

Copy link
Copy Markdown
Member

Thanks Peter!

@PeterDaveHello
PeterDaveHello deleted the feature/grok45And46Support branch August 30, 2026 10:44
Kyzcreig pushed a commit to Kyzcreig/pr-agent that referenced this pull request Aug 30, 2026
…dels

Addresses @IsmaelMartinez's review on The-PR-Agent#2530. All three findings verified against
the code and reproduced before fixing.

1. OpenRouter double-configuration. He wrote: "grok_model is the basename, so
   openrouter/x-ai/grok-4 lands here too and gets reasoning_effort from [config]
   while the OpenRouter block below is already setting extra_body.reasoning from
   [openrouter]." Reproduced exactly -- with the flag on,
   openrouter/x-ai/grok-4.5 came out with BOTH top-level reasoning_effort='high'
   (from [config]) and extra_body.reasoning={'effort':'high'} (from [openrouter]).
   Adopted his inline `not is_openrouter` suggestion; the OpenRouter block is now
   the sole owner of that path.

2. allowed_openai_params too broad. He wrote: "grok-2 and grok-3 have
   reasoning_effort dropped without the allowlist and included with it ...
   grok-4.5 does not need the allowlist at all; grok-4.20-multi-agent genuinely
   does." Confirmed against the pinned litellm: get_supported_openai_params
   reports reasoning_effort for xai/grok-4.5 and xai/grok-4.20-multi-agent but not
   for xai/grok-3. The allowlist is now added only when litellm does not already
   report the param, mirroring how main does it for its own Grok path.

3. MAX_TOKENS entries. Added xai/grok-4.20-multi-agent (main's The-PR-Agent#2871, merged
   today, added the 4.5/4.6 entries but not this one), so the documented
   xhigh-capable model can actually run without custom_model_max_tokens.

Also, and this narrows the PR substantially: main gained native always-on Grok
4.5/4.6 reasoning support in The-PR-Agent#2871 while this sat. The opt-in branch now also
skips any model main already covers via GROK_REASONING_EFFORT_LEVELS, so it no
longer overrides main's clamping. The residual scope is xAI-direct Grok families
main does not cover.

Rebased onto main (a64730a); the configuration.toml conflict he flagged is
resolved (kept main's add_user_to_requests + "max" effort alongside our flag).

Tests: adds the OpenRouter-isolation regression, an allowlist-narrowing test, and
a test that natively-supported models are left to main. Adopts the
_restore_litellm_globals autouse fixture per his third note.
tests/unittest: 2702 passed, 1 pre-existing failure
(TestLiteLLMReasoningEffortGrok::...[grok-4.6-xhigh-False]) that reproduces
identically on pristine upstream/main and is untouched by this branch.

Co-authored-by: IsmaelMartinez <IsmaelMartinez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants