Skip to content

Add timeout and max_retries to the OpenAI provider - #593

Open
inamdarmihir wants to merge 3 commits into
google:mainfrom
inamdarmihir:feat/82-openai-timeout-max-retries
Open

inamdarmihir wants to merge 3 commits into
google:mainfrom
inamdarmihir:feat/82-openai-timeout-max-retries

Conversation

@inamdarmihir

@inamdarmihir inamdarmihir commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

#82 asks for a way to set the LLM call timeout when large inputs time out. Gemini exposes http_options/retry settings and Ollama has a timeout argument, but OpenAILanguageModel has no equivalent: timeout and max_retries passed via language_model_params land in _extra_kwargs, are dropped by the request-parameter allowlist in infer(), and never reach openai.OpenAI(...).

This adds timeout and max_retries as keyword arguments on OpenAILanguageModel.__init__ and forwards them to the openai.OpenAI client only when set, so SDK defaults are unchanged otherwise. They are placed after max_workers and before **kwargs, so existing positional calls are unaffected. This also applies to OpenAI-compatible endpoints configured with base_url.

Usage:

lx.extract(..., model_id="gpt-4o-mini",
           language_model_params={"timeout": 300, "max_retries": 5})

Verified through factory.create_model with the real SDK: timeout=7.5, max_retries=0 yields a client with those values; without them the client keeps the SDK defaults (Timeout(connect=5.0, read=600, ...), max_retries=2).

Overlap note: #548 also touches the openai.OpenAI(...) construction (adds default_headers); the two should merge with a trivial rebase.

Fixes #82

Feature

How Has This Been Tested?

Added tests that the client receives timeout/max_retries when set and is constructed exactly as before when they are not.

$ pytest tests --deselect tests/create_provider_plugin_test.py
908 passed, 21 skipped
$ isort langextract tests && pyink langextract tests --config pyproject.toml
$ pylint --rcfile=.pylintrc langextract/providers/openai.py

tests/create_provider_plugin_test.py has 3 failures on main in my environment (offline editable install / build isolation) unrelated to this change.

Checklist:

  • I have read and acknowledged Google's Open Source Code of conduct.
  • I have read the Contributing page, and I either signed the Google Individual CLA or am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed Google's Python Style Guide and ran pylint over the affected code.

@github-actions github-actions Bot added the size/XS Pull request with less than 50 lines changed label Oct 27, 2026
@google-cla

google-cla Bot commented Oct 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@inamdarmihir
inamdarmihir force-pushed the feat/82-openai-timeout-max-retries branch from d14eaad to ebc5917 Compare October 27, 2026 07:13
Both were accepted through language_model_params but never reached the
OpenAI client: leftover kwargs are filtered to an allowlist of request
parameters, so users hitting client timeouts on large inputs had no
way to raise the limit.

Accept them as constructor arguments and pass them to openai.OpenAI
only when set, leaving the SDK defaults untouched otherwise.

Related to google#82
@inamdarmihir
inamdarmihir force-pushed the feat/82-openai-timeout-max-retries branch from ebc5917 to 445744c Compare October 27, 2026 07:16
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 8 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Pull request with less than 50 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can timeout be added for LLM call

2 participants