Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support for "retry-after-ms" HTTP header variant #957

Closed
1 task done
trrwilson opened this issue Dec 8, 2023 · 3 comments
Closed
1 task done

Feature: support for "retry-after-ms" HTTP header variant #957

trrwilson opened this issue Dec 8, 2023 · 3 comments
Labels
Azure for issues relating to the Azure OpenAI service enhancement New feature or request

Comments

@trrwilson
Copy link

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

  • This is a feature request for the Python library

Describe the feature or improvement you're requesting

Feature request: add support for the millisecond-precision retry-after-ms variant of the standard retry-after response header, using its value as a higher-resolution first selection when present that falls back to the lower-resolution standard when not present.

openai-python's retry header handling is cleanly done in _base_client.py and parses the standard retry-after header, which provides second-resolution guidance on how long a client should wait before initiating a retry.

Some services, including Azure OpenAI and particularly in the context of provisioned customers, can provide a retry-after-ms header in addition to retry-after. This millisecond-resolution variant is primarily valuable when retry behavior is being used to efficiently control traffic of service-to-service calls within a topology that often has delays that can be well under a single whole second.

As a reference/comparison, Azure's SDKs use a precedence order of three retry headers, e.g. as per here in the azure-sdk-for-js core logic:

  • If the retry-after-ms header key is present, use its value as the number of milliseconds to delay
  • Else, if the x-ms-retry-after-ms header key is present, instead use its value as the number of milliseconds to delay
  • Else, if the retry-after header key is present, use its value as the number of whole seconds to delay
  • Else, fall back to standard fallback heuristics to calculate a retry delay

openai-python already uses a float value from retry-after as the input into time.sleep(), so this superficially looks like a fairly straightforward addition:

retry_after = float(retry_header)

Conceptually, this would just be a float(retry_ms_header) / 1000 style of thing.

Thank you!

Additional context

No response

@rattrayalex
Copy link
Collaborator

Thanks for raising! Sounds like a good idea to me.

@kristapratico , do you know whether in practice retry-after-ms will be non-present in many situations where x-ms-retry-after-ms is present? That is, can we implement only the former but not the latter?

@rattrayalex rattrayalex added enhancement New feature or request Azure for issues relating to the Azure OpenAI service labels Dec 9, 2023
@trrwilson
Copy link
Author

Thanks, @rattrayalex !

The Azure OpenAI service team confirmed that it's only using the retry-after-ms header, not the x-ms-retry-after-ms variant. So the provisioned customers will be fully served by having just the retry-after-ms value optionally checked for in advance of the conventional retry-after.

@rattrayalex
Copy link
Collaborator

Thank you @trrwilson ! I've ticketed this internally. I frankly don't anticipate it happening very soon, but we do hope to do it (and should be pretty easy).

luckdev2350 added a commit to luckdev2350/openai_python that referenced this issue May 9, 2024
risingstar0225 added a commit to risingstar0225/openai_py that referenced this issue Jul 26, 2024
megamanics pushed a commit to devops-testbed/openai-python that referenced this issue Aug 14, 2024
principlesoftware-dev added a commit to principlesoftware-dev/Python-openAI that referenced this issue Sep 4, 2024
cgayapr pushed a commit to cgayapr/openai-python that referenced this issue Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure for issues relating to the Azure OpenAI service enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants