Forward `service_tier` to xAI and record the served tier in `provider_details`

Merged
DS
20d ago
+127-10

Closes #12071

Why we make these changes

XaiModel listed service_tier in unsupported_settings, so the unified setting was silently dropped, though xAI's gRPC chat.create() and its Response both carry service_tier (xAI priority processing). This PR sends 'default' and 'priority', omits 'auto' and 'flex' (xAI has neither, and the SDK raises ValueError on them), and records the tier xAI reports serving the response at in provider_details, as #12072's maintainer decision does for Groq. It carries forward #12162, whose author can't touch the waiver under .github/.

[!WARNING]
Compatibility impact: xAI ignored service_tier silently, with no warning. Existing code that sets service_tier='priority' and runs an xAI model, directly or through settings shared across providers (an Agent's model_settings, a FallbackModel member), now sends it. xAI can serve those requests at priority and bill its premium per-token rate for them. 'default' is now sent too, which xAI treats like omitting it. Whenever xAI reports the tier that served a response, it lands in ModelResponse.provider_details['service_tier'], whether or not service_tier was set, as on OpenAI and Groq.

Why this can ship in a minor release: ServiceTier documents 'default' as the provider's standard tier and 'priority' as ignored only on providers without a priority tier. xAI offers both, so dropping them was a bug. This ships under the version policy's bug-fix exception: only code that relied on xAI ignoring service_tier, which nothing documented, sees a change.

Migration: to keep xAI on standard processing, set service_tier on each model rather than in shared settings, or don't set 'priority' for xAI models.

Release note: a shared service_tier='priority' now reaches xAI and can be billed at xAI's priority rate.

New public surface

none. The served tier goes in the existing ModelResponse.provider_details. service_tier on chat.create() needs xai-sdk>=1.17.0; main's floor is already xai-sdk>=1.21.0, so the PR adds only a comment noting it.

User-visible behavior

agent = Agent('xai:grok-4.3', model_settings=ModelSettings(service_tier='priority'))
result = await agent.run('Hello')
# before: chat.create() got no service_tier; provider_details is None
# after:  chat.create(service_tier='priority'); provider_details == {'service_tier': 'priority'} when xAI reports it

Verification

What changes for existing users

xAI users who set service_tier='priority' get priority processing and its billing. Requests that don't set service_tier are sent unchanged; their responses gain provider_details['service_tier'] only when xAI reports a served tier.

PR decisions

2026-11-15 · adopted PR #12162 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/12162
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-15 · carry-forward PR instead of pushing to pydanty's branch · iter -

  • Decision: Push head to xai-service-tier-carry-forward and open a dsfaccini PR with Closes #12071; close #12162 linking it
  • Why: the waiver lives under .github/, and the .github Directory Guard fails any pydanty[bot]-authored PR touching .github/ (.github/workflows/AGENTS.md)
  • Source: https://github.com/pydantic/pydantic-ai/pull/12162
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-15 · response tier in provider_details only when proto tier non-zero · iter -

  • Decision: Record served tier in provider_details, non-streamed and streamed, only when response.proto.service_tier != 0; no xai_service_tier setting
  • Why: follows DouweM's Groq decision on #12072; SDK maps UNSPECIFIED to 'default' and every recorded cassette carries 0
  • Source: https://github.com/pydantic/pydantic-ai/issues/12072
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

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

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

2026-11-15 · exempt delta d1c8d799f from reviewed f6aa45529 · iter -

2026-11-15 · exempt delta: API-compat waiver after reviewed f6aa45529 · iter -

  • Decision: push the waiver without another review
  • Why: rubric rung: compatibility. Data-only file the gate validates (check_api_compatibility.py --against v2.68.0 exits 0 with it); fingerprint, against and impact were in review 1's bundle as settled decision 6; only the PR URL is new. Chains from reviewed f6aa45529
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-15 · exempt delta 3ce0f57c5 (douwebot link finding) from reviewed f6aa45529 · iter -

2026-11-15 · douwebot required although its gate status read success · iter -

2026-11-16 · merge bar met at 3ce0f57c5; step-7 pick with David · iter -

  • Decision: CI, PR Review Checks (rerun after quota No result) and clean douwebot APPROVE all on 3ce0f57c5; monitor mode; no main merge or enqueue until the manager relays David's pick
  • Why: dispatch 20261115T222758Z: "Do not merge main or enqueue until I relay the pick."; PR Review Checks run 43770022995 failed No result on provider quota, one rerun at 00:05Z passed, no waiver
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · pre-push review 2 of 3 at 13922afc81e85aa5a19d35c6e792a4f1fd45f7f2 · iter -

2026-11-16 · pre-push review 2 of 3 at 13922afc81e85aa5a19d35c6e792a4f1fd45f7f2 · iter -

2026-11-16 · exempt delta a78cecfda (PR Review Checks test-file finding) from reviewed 13922afc8 · iter -

  • Decision: push without another local review (budget stays at 2 of 3)
  • Why: rubric rung: tests. Test-only relocation: tests/models/test_xai.py restored byte-identical to main 399bd253f; the three test bodies move to tests/models/test_xai_service_tier.py unchanged apart from XAI_NON_REASONING_MODEL -> local MODEL_NAME (same value); only new prose is the module docstring. No production, docs or wire change; assertions and established expectations unchanged; targeted pytest, pyright and ruff pass. Follows tests/AGENTS.md feature-file rule and the Groq precedent test_groq_service_tier.py. Chains from reviewed 13922afc8
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#discussion_r4582016966
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · exempt delta cd596cfb6 (PR Review Checks omission finding) from reviewed 13922afc8 · iter -

  • Decision: push without another local review (budget stays at 2 of 3)
  • Why: table row: missing coverage of established intended behavior. Test-only: test_xai_service_tier now asserts the exact service_tier key projection, so auto/flex must omit the key (settled decision 1: 'omit auto/flex'); no production change; targeted pytest, pyright, ruff pass. Chains via exempt a78cecfda from reviewed 13922afc8
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#discussion_r4582155326
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · non-blocking findings: push only for user-visible or hard-rule · iter -

  • Decision: "a non-blocking PR Review Checks or douwebot Optional finding gets a push only when it changes what a user sees or is a hard-rule violation (Any, cast, a test that cannot fail on the defect it pins). Answer the rest with the reason, react, resolve, and do not push. Blocking findings still get fixed."
  • Why: manager dispatch 20261116T051957Z (relaying for David): stop the push-per-finding loop on #13524
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · merge bar met at cd596cfb6; holding for step-7 pick · iter -

  • Decision: CI 43809454053 success, PR Review Checks success (no findings), douwebot APPROVE 5915378642 on cd596cfb6; 0 open threads; monitor mode; no enqueue until the manager relays David's pick
  • Why: dispatch 20261116T042200Z: resolve the conflict, drive CI, PR Review Checks and douwebot to APPROVE on the new head, then hold for the step-7 pick
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#pullrequestreview-5915378642
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · SDK floor superseded by main's xai-sdk>=1.21.0 · iter -

  • Decision: Resolved the pydantic_ai_slim/pyproject.toml conflict to main's xai-sdk>=1.21.0, keeping a comment that service_tier needs 1.17.0; uv.lock and the runner lock re-lock identical to main
  • Why: main merged #10612 (KubernetesSandbox), which raised the floor to 1.21.0 for protobuf 7; 1.21.0 satisfies the dispatched >=1.17.0, so lowering it would break main; the comment follows main's kept 1.16.0 image_file_id note
  • Source: https://github.com/pydantic/pydantic-ai/pull/10612
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · pre-push review 3 of 3 at 8b8342529cb61cc9386bd4fc2a4633947c1fe495 · iter -

2026-11-16 · pre-push review 3 of 3 at 8b8342529cb61cc9386bd4fc2a4633947c1fe495 · iter -

2026-11-16 · douwebot Optional on test docstring: skip, no push · iter -

2026-11-16 · merge bar met at 8b8342529; holding for step-7 pick · iter -

  • Decision: CI 43839804921 success, PR Review Checks success (no findings), douwebot APPROVE 5917709145 on 8b8342529 (one Optional, resolved); 0 open threads; mergeable clean; monitor mode; no enqueue until the manager relays David's pick
  • Why: dispatch 20261116T042200Z: drive CI, PR Review Checks and douwebot to APPROVE on the new head, then hold for the step-7 pick
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#pullrequestreview-5917709145
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · exempt delta bd21feefb (douwebot docstring Optional) from reviewed 8b8342529 · iter -

  • Decision: take the Optional after all: drop the 'no xAI key was available' clause from the test_xai_service_tier.py module docstring; push without another local review (budget exhausted, 3 of 3)
  • Why: manager dispatch 20261116T095137Z (relaying for David): the clause describes our environment, not the code, and goes stale once someone records. Table row: comments or docstrings only, no docs/** page; git diff 8b8342529..bd21feefb touches only the module docstring. Chains from reviewed 8b8342529
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#discussion_r4583981482
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280
  • Supersedes: douwebot Optional on test docstring: skip, no push

2026-11-16 · merge bar met at bd21feefb; holding for step-7 pick · iter -

  • Decision: CI 43843668378 success, PR Review Checks success (no findings), douwebot APPROVE 5918030908 on bd21feefb; 0 open threads; mergeable clean; monitor mode; no enqueue until the manager relays David's pick
  • Why: dispatch 20261116T095137Z: drive CI, PR Review Checks and douwebot to an APPROVE on the new head, then hold for step 7
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#pullrequestreview-5918030908
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · David picked pydanty:review-lite for step 7 on 2026-11-16 · iter -

  • Decision: David picked pydanty:review-lite for step 7 on 2026-11-16 (~21:10Z); merge main, push, apply the label, triage under the usual rules; the manager checks freshness and enqueues
  • Why: manager dispatch 20261116T2140Z (relaying for David): step-7 pick
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · exempt delta a4d2daf07 (main merge) from reviewed 8b8342529 · iter -

  • Decision: push without another local review (budget exhausted, 3 of 3)
  • Why: table row: target-branch merge with no conflict resolution; git diff upstream/main...HEAD is byte-identical to git diff upstream/main...bd21feefb (main 7b6daaea8 merged, 16 commits, none touching a PR file); chains via exempt bd21feefb from reviewed 8b8342529
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-16 · first pydanty:review-lite run failed without a review · iter -

2026-11-16 · manager re-applied pydanty:review-lite once at 2026-11-16T22:13:11Z · iter -

  • Decision: one rerun by the manager; do not re-apply it myself; if this run also fails, report it and the manager escalates rather than reruns
  • Why: manager dispatch 20261116T221320Z (relaying for David)
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · pydanty ignored the 22:13Z review-lite label; manager re-fired it at ~00:33Z · iter -

  • Decision: label re-applied at 22:13:10Z sat unconsumed over 2 h (no is-working, status comment or review); manager removed and re-added it once at 00:32:53-55Z; pydanty picked it up at 00:33:01Z (is-working, status comment 6933850902); do not touch the label; if ignored again, report and the manager escalates
  • Why: manager dispatch 20261117T003314Z (relaying for David); timeline labeled/unlabeled events on the PR
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · review-lite 1 and 2 (live xAI cassette): skip, recording stays parked · iter -

  • Decision: no push; reply with the reason; the PR body already states gRPC acceptance is unverified live
  • Why: no xAI key in the keys file (env-list-vars ~/.zsh_secrets lists none); dispatch 20261115T222758Z: 'keep the gRPC recording parked'; dispatch 20261116T2140Z: 'A pydanty CHANGES_REQUESTED does not block merge'
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#issuecomment-6933850902
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · review-lite 3 (no-setting claim): do, PR body only · iter -

  • Decision: qualify the PR body's New public surface, What changes and [!WARNING] lines: a response gains provider_details['service_tier'] whenever xAI reports a served tier, whether or not service_tier was set; no code change, no push
  • Why: verified: _service_tier_details reads only response.proto.service_tier and test_xai_service_tier_provider_details runs with no model_settings; precedent OpenAIChatModel, OpenAIResponsesModel and GroqModel record the served tier unconditionally
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#issuecomment-6933850902
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · review-lite Optional (CLAI2 can't select xAI tier): defer to #13560 · iter -

2026-11-17 · douwebot re-applied on a4d2daf07 for a head receipt · iter -

2026-11-17 · merge bar met at a4d2daf07 after review-lite; manager enqueues · iter -

  • Decision: CI 43962567029 success, PR Review Checks success, douwebot APPROVE 5930881162 on a4d2daf07 (no comments); review-lite CHANGES_REQUESTED 5930697711 triaged (2 skip, 1 PR body fix, 1 deferred to #13560); 0 open threads; mergeable clean; no enqueue
  • Why: dispatch 20261116T2140Z step 6: 'Report the final head SHA once it meets the merge bar, with 0 unresolved threads. Do not enqueue: I check freshness and enqueue.'
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524#pullrequestreview-5930881162
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · manager enqueued #13524 at 2026-11-17T01:20:30Z · iter -

  • Decision: the manager enqueued a4d2daf07; leave the re-enqueue to the manager; on ejection, diagnose and report, never re-enqueue myself
  • Why: manager dispatch 20261117T012044Z (relaying for David): 'leave the re-enqueue to me'
  • Source: https://github.com/pydantic/pydantic-ai/pull/13524
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · merge queue ejected #13524: waiver stale after v2.69.0 · iter -

  • Decision: ejected 2026-11-17T01:36:26Z (failed_checks); quality checks 'Check public API compatibility with the latest release' now compares against v2.69.0 (released 01:03:25Z), so the v2.68.0 waiver no longer covers fingerprint 2048365239934b54e3c4aa4b1f1439f3bc1b7345f481fbbc7664f2da0f799d02; fix 3a535f382 sets against to v2.69.0, reason and PR link unchanged
  • Why: job 133744269431 log: XaiModel.unsupported_settings error with that fingerprint; check_api_compatibility.py --against v2.69.0 on a scratch merge of 3a535f382 with upstream/main exits 0 with 0 errors (on the branch alone it reports 123 errors for 33 v2.69.0 commits the branch lacks); no other version-pinned text in the diff
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43994838600
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

2026-11-17 · exempt delta 3a535f382 (waiver against v2.69.0) from reviewed 8b8342529 · iter -

  • Decision: push without another local review (budget exhausted, 3 of 3)
  • Why: rubric rung: compatibility. Data-only file the gate validates; only 'against' changes (v2.68.0 -> v2.69.0), fingerprint, reason and PR link unchanged; the gate passes with it on the merge with main. Chains via exempt bd21feefb and a4d2daf07 from reviewed 8b8342529
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43994838600
  • Session: c90d0ba9-bd47-40b1-a63f-5a12cc627280

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.