Skip to content

feat: add service_tier support for priority processing#163

Merged
double-di merged 6 commits into
mainfrom
ddorozhkin/service-tier-v2
Jun 12, 2026
Merged

feat: add service_tier support for priority processing#163
double-di merged 6 commits into
mainfrom
ddorozhkin/service-tier-v2

Conversation

@double-di

Copy link
Copy Markdown
Contributor

Add service_tier parameter to chat.create() for requesting priority processing at a higher token price.

Changes

  • ServiceTier type: Literal["default", "priority"] in types/common.py
  • service_tier.py: Proto conversion helpers (service_tier_to_proto, service_tier_from_proto)
  • chat.py: Added service_tier parameter to create(), streaming chunk aggregation, and Response.service_tier property
  • Proto updates: ServiceTier enum in usage_pb2, service_tier field on request/response/chunk in chat_pb2 (v5 and v6)

Usage

# Request priority processing
chat = client.chat.create(
    model="grok-3-latest",
    messages=[{"role": "user", "content": "Hello"}],
    service_tier="priority",
)
response = await chat.send()
print(response.service_tier)  # "priority" or "default"

Supersedes #159.

@double-di double-di requested a review from a team as a code owner June 10, 2026 03:00
Omar-V2
Omar-V2 previously approved these changes Jun 10, 2026
Denis Dorozhkin added 4 commits June 11, 2026 02:05
Add service_tier parameter to chat.create() for requesting priority
processing. The response includes a service_tier field indicating which
tier was actually used.

- Add ServiceTier type (Literal['default', 'priority'])
- Add service_tier.py with proto conversion helpers
- Add service_tier to chat request, response, and streaming chunks
- Update proto definitions (usage_pb2, chat_pb2) for v5 and v6
Regenerated from xai-org/xai-proto#63 which adds ServiceTier enum
and service_tier field to chat request/response/chunk.
buf generate produces absolute imports (from xai.api.v1 import ...)
but the SDK expects relative imports (from . import ...) since the
proto files live under src/xai_sdk/proto/v5/ and v6/.
Regenerate chat_pb2 (v5 + v6) so service_tier matches the API wire format:
request=31, response=15, chunk=12 (was 30/13/11). Field-number-only change;
no fields added or removed.

Regenerated from xai-org/xai-proto#65.
Regenerate chat_pb2 (v5 + v6) to expose the code-execution generated files:
OutputFile message, output_files on response (13) and chunk (11), and the
INCLUDE_OPTION_CODE_EXECUTION_FILES_OUTPUT (9) include option. service_tier
unchanged (31/15/12).

Regenerated from xai-org/xai-proto#65.
double-di added a commit to xai-org/xai-proto that referenced this pull request Jun 12, 2026
…iles (#65)

Two changes that align the public `chat.proto` with the API.

### 1. Fix `service_tier` field numbers (wire correctness)
`service_tier` was assigned numbers that don't match the API, so a
requested tier and the tier reported back were silently dropped on the
wire.

| Message | before | after |
|---|---|---|
| `GetCompletionsRequest.service_tier` | 30 | **31** |
| `GetChatCompletionResponse.service_tier` | 13 | **15** |
| `GetChatCompletionChunk.service_tier` | 11 | **12** |

### 2. Add code-execution `output_files`
Expose the generated-files output from the code execution tool:
- `OutputFile` message (`file_id`, `name`)
- `output_files` on `GetChatCompletionResponse` (13) and
`GetChatCompletionChunk` (11)
- `INCLUDE_OPTION_CODE_EXECUTION_FILES_OUTPUT` (9) so it can be
requested

All field numbers match the API. `buf build` + `buf lint` pass.

xai-sdk-python bindings updated in xai-org/xai-sdk-python#163.
@double-di double-di merged commit 47aca07 into main Jun 12, 2026
7 checks passed
@double-di double-di deleted the ddorozhkin/service-tier-v2 branch June 12, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants