Add `service_tier` support to `GroqModel`

Closed
PY
22d ago
+205-22

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Closes #12072

GroqModel listed service_tier in unsupported_settings, so every unified tier was dropped from the request and the tier Groq served was discarded. This implements the maintainer decision on #12072: map the unified tiers onto Groq's, add groq_service_tier for Groq's native values, and surface the served tier in provider_details.

[!WARNING]
Compatibility impact: a unified service_tier set in settings shared across models, for example on a FallbackModel or an Agent that also runs Groq, now reaches Groq instead of being dropped. Unified 'flex' then sends Groq's flex tier, which fails fast with a 498 when Groq is at capacity (#12062 tracks its error category).

Why this can ship in a minor release: ServiceTier documents that the unified field maps onto each provider's tiers and is ignored only where a provider lacks the tier. Groq has these tiers, so dropping them was a bug. This ships under the version policy's bug-fix exception: only code that relied on Groq ignoring service_tier, which nothing documented, sees a change.

Migration: to keep Groq on its standard tier while other models use flex, set groq_service_tier='on_demand' in the Groq model's settings, or set service_tier per model rather than in shared settings.

New public surface: GroqModelSettings.groq_service_tier: Literal['auto', 'on_demand', 'flex', 'performance'].

User-visible behavior:

 Agent('groq:llama-3.3-70b-versatile', model_settings={'service_tier': 'flex'})
-# request body: no service_tier
+# request body: "service_tier": "flex"
unified service_tiersent to Groq
'auto''auto'
'default''on_demand'
'flex''flex'
'priority'(omitted)

groq_service_tier wins over the unified field and is the only way to reach the enterprise 'performance' tier. The tier rides in extra_body, like reasoning_effort, because the minimum supported groq SDK (0.25.0) types service_tier without 'performance'. Streamed requests carry the tier too. The served tier lands in ModelResponse.provider_details['service_tier'] on non-streamed responses; streamed chunks carry no tier, so streamed responses are read as before.

Verification:

  • test_service_tier captures the outgoing request body with httpx.MockTransport: each mapped value, priority omitted, performance, precedence, and the merge with a user extra_body and reasoning_effort; test_service_tier_streamed_request does the same for a streamed request. No Groq API key was available to record a cassette; the maintainer decision allows a captured request body in that case.
  • Six existing cassette snapshots gain 'service_tier': 'on_demand' in provider_details, because the recorded Groq responses already carry it.
  • The unchanged probes in tests/models/test_model_settings_support.py pass with service_tier out of unsupported_settings.
  • The API compatibility gate's GroqModel.unsupported_settings change is waived in .github/api-compatibility-waivers/86956c2a7b69b71c63793e85e0042aabe6fc8f7abd5dbec695ed2267a5c979e5.json.

What changes for existing users: a service_tier that Groq used to drop is now sent; see the warning above.

Out of scope: bumping the groq SDK floor (its Omit migration is its own change), and an error category for flex's 498 (#12062).

PR decisions

2026-11-15 · adopted PR #12666 at 2026-11-15 · iter -

  • Decision: Branch-context bootstrapped from existing PR + issue(s). Decisions prior to this entry are backfilled from resolved threads.
  • Why: PR predates the branch-context setup
  • Source: https://github.com/pydantic/pydantic-ai/pull/12666
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · tier travels in extra_body · iter -

  • Decision: Send the resolved Groq tier through extra_body, generalising the reasoning_effort merge in _completions_create; drop cast(Any, ...)
  • Why: groq SDK floor 0.25.0 types service_tier without 'performance'; no casts or Any; a derived key overwrites a colliding user extra_body key, as reasoning_effort already does
  • Source: https://github.com/pydantic/pydantic-ai/issues/12072
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · response tier read via isinstance(getattr) · iter -

  • Decision: Read the response tier with isinstance(getattr(response, 'service_tier', None), str)
  • Why: ChatCompletion declares no service_tier field before groq 0.35.0, so it arrives as an extra; model_extra would read None once the field is declared; truthy getattr let Any into provider_details
  • Source: https://github.com/pydantic/pydantic-ai/issues/12072
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · inline mapping, module-level map · iter -

  • Decision: Replace the single-use _resolve_service_tier helper with a module-level _UNIFIED_TO_GROQ_SERVICE_TIER dict resolved inline in _completions_create
  • Why: Answers pydanty's open choice; single-use helper rule in agent_docs/index.md; complexity stays under the limit (14); precedent _TOP_LEVEL_TO_GLA_SERVICE_TIER in google.py
  • Source: https://github.com/pydantic/pydantic-ai/pull/12666#issuecomment-6673676426
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · MockTransport body capture, no cassette · iter -

  • Decision: Request tests capture the outgoing body with httpx.MockTransport in tests/models/test_groq.py::test_service_tier; no live Groq recording
  • Why: No Groq key on this box; the maintainer decision allows a captured request body when no key is available; the tier now travels in extra_body, which the MockGroq kwargs capture can't see as a top-level arg
  • Source: https://github.com/pydantic/pydantic-ai/issues/12072
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · compatibility impact: waiver + label · iter -

  • Decision: Waive GroqModel.unsupported_settings (fingerprint 86956c2a…, against v2.68.0), add compatibility impact label, [!WARNING] block and release note
  • Why: Unified flex in shared settings, e.g. on a FallbackModel, now reaches Groq, which can return 498 at capacity (#12062); precedent #10920
  • Source: https://github.com/pydantic/pydantic-ai/pull/10920
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · pre-push review 1 of 3 at 01dc643eb83a1dfff3fe22b48183e0f0dfd32a82 · iter -

2026-11-15 · pre-push review 1 of 3 at 01dc643eb83a1dfff3fe22b48183e0f0dfd32a82 — outcome · iter -

2026-11-15 · exempt delta 01dc643eb..ca6e40ef4 from reviewed 01dc643eb · iter -

  • Decision: No review 2: test-only addition (missing-coverage row), docstring-only trim (docstring row), and a docs/models/groq.md citation link
  • Why: Docs delta touches only the documentation rung: it adds a link to Groq's own flex-processing page and rewords the 498 clause to that page's sentence; it cannot move API, behavior or tests. Chains from reviewed 01dc643eb
  • Source: https://github.com/pydantic/pydantic-ai/pull/12666
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · exempt delta ca6e40ef4..8c082ddc0 from reviewed 01dc643eb · iter -

  • Decision: No review 2: docs/models/groq.md link markup only, applying douwebot's Optional finding
  • Why: Touches only the documentation rung: it turns inline code into a reference link to the existing pydantic_ai.messages.ModelResponse.provider_details symbol, same form as docs/native-tools.md; cannot move API, behavior or tests. Chains from reviewed 01dc643eb via the logged exempt delta to ca6e40ef4
  • Source: https://github.com/pydantic/pydantic-ai/pull/12666#discussion_r4576519102
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

2026-11-15 · standing rule: mask keys in live recordings (manager dispatch 2026-11-15T01:35Z) · iter -

  • Decision: For every live recording with real provider keys, pipe test output through a key-masking filter inside the env-run shell, and before each push grep cassettes and commits for raw key values
  • Why: Keeps provider key values out of test output and transcripts; this PR has no live recordings so far
  • Source: https://github.com/pydantic/pydantic-ai/pull/12666
  • Session: 0c144fde-8068-4df5-8eca-5e0cd89f4e88

Checklist

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

https://claude.ai/code/session_01BYcNCkFvZ4K2xWxbw9PJnG