openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Define + export `ServiceTiers` string literal

Open s-banach opened this issue 4 months ago • 3 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [x] This is a feature request for the Python library

Describe the feature or improvement you're requesting

If I want to annotate service_tier in my code, I have to hard-code a type like Literal["auto", "default", "flex", "scale", "priority", "fast"], and then the hard-coded type annotation breaks if I'm using anything other than the latest version of the sdk.

Additional context

No response

s-banach avatar Jul 30 '26 20:07 s-banach

Hey, looks like we need a centralized ServiceTiers type, can I add that??

Mahnoor-Zaffar avatar Jul 31 '26 14:07 Mahnoor-Zaffar

Proposed Plan to Define and Export ServiceTier String Literal

Problem Analysis

When configuring service_tier in OpenAI API completion/chat requests, developers currently have to hardcode string literal union types (e.g. Literal["auto", "default", "flex", "scale", "priority", "fast"]) in their applications. When new service tiers are introduced or when using type checkers, hardcoded type annotations break across SDK version upgrades.

Proposed Implementation

  1. Define ServiceTier Literal: In src/openai/types/_shared_params.py (or src/openai/types/__init__.py), define ServiceTier as an exported typing_extensions.Literal:
    ServiceTier = Literal["auto", "default", "flex", "scale", "priority", "fast"]
    
  2. Export Type Alias: Export ServiceTier and ServiceTiers in src/openai/types/__init__.py so SDK consumers can import from openai.types import ServiceTier.
  3. Type Annotation Usage: Wire ServiceTier into client completion parameters where service_tier is accepted.
  4. Unit Test Verification: Add type verification tests in tests/test_client.py checking that ServiceTier is exported from openai.types and type checks cleanly.

SparshGarg999 avatar Aug 14 '26 17:08 SparshGarg999

The other thing they should actually change is clarify “auto” is only an input tier and not an output tier, but god knows if any humans actually write this code anymore.

s-banach avatar Aug 14 '26 17:08 s-banach