Repository navigation
Use the framework's default OpenAI client or key in the default model provider (breaking) - #168
Merged
campoy merged 5 commits intoOct 28, 2026
Conversation
Without `model_provider`, the plugin built its own `AsyncOpenAI` from `OPENAI_API_KEY` and `OPENAI_BASE_URL`. A client or key set with the framework's `set_default_openai_client` or `set_default_openai_key` was silently ignored: model calls went to the environment's endpoint with the environment's key, while native runs used the configured client. The default provider now uses the framework's default client, with its own retries turned off, or its default key, as native runs do. Without either it uses the environment as before. Breaking change: a Worker that sets a framework default client or key and uses the plugin's default provider now sends its model calls to that client or key. To keep using the environment's endpoint and key, pass `model_provider=OpenAIProvider(openai_client=AsyncOpenAI(max_retries=0))` and a model Activity timeout. The change is Worker-side only; Workflow histories are not affected.
Copying the client with with_options() builds a new client that reads the environment again, so its settings could differ from the client the application set. Use the default client unchanged, as native runs do; its own max_retries applies, and the README says to set it to 0 to leave retries to Temporal.
This was referenced Oct 27, 2026
Contributor
Author
|
Ready for review, @brianstrauch |
Member
|
Non-blocking suggestion: could we add a regression test for |
Add a default_key case to test_chat_completions_model: OPENAI_API_KEY holds another key, set_default_openai_key sets the test key, and every request must carry the test key. Without the fix the request carries the environment's key.
Contributor
Author
|
Thanks, added in c333030. |
brianstrauch
approved these changes
Oct 28, 2026
campoy
deleted the
fix/openai-agents-python-native-provider-settings-ignored
branch
October 28, 2026 22:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
model_provider, the model Activity's defaultOpenAIProvidernow uses the framework's defaults, as native runs do: the client set withset_default_openai_client, as it is, or elseAsyncOpenAI(api_key=<key set with set_default_openai_key>, max_retries=0). With neither set, that client still readsOPENAI_API_KEYandOPENAI_BASE_URL, as before.with_options(max_retries=0)would build a new client that readsOPENAI_CUSTOM_HEADERS,OPENAI_ORG_IDandOPENAI_PROJECT_IDagain, so its headers could differ from the client the application set. The README says to give that clientmax_retries=0to leave retries to Temporal.test_chat_completions_modelgainsdefault_clientanddefault_keycases.Why?
The OpenAI Agents SDK documents
set_default_openai_clientandset_default_openai_keyto point every model call at another OpenAI-compatible endpoint or key. WithOpenAIAgentsPlugin()and nomodel_provider, the plugin ignored both (#167): model calls, with their prompts, went to the Worker environment's endpoint with the environment's key, the run completed, and nothing warned. WithoutOPENAI_API_KEYthe Worker could not be built, even when a default client was set.Breaking change
A Worker that sets a framework default client or key and uses the plugin's default provider now sends its model calls to that client or key. To keep the environment's endpoint and key, pass
model_provider=OpenAIProvider(openai_client=AsyncOpenAI(max_retries=0))with a model Activity timeout (a custom provider requires one).The first commit message states the breaking change. The PR title says it too, because release notes come from the squash commit subject.
Old runs and rollback: the change runs only in the model Activity's constructor on the Worker. It adds no command and changes no Workflow-side value, so histories replay on either version, and the previous release is a safe rollback. During a mixed rollout, Workers on the two versions can send model calls to different endpoints.
Checklist
Closes [Bug] openai_agents: the default model provider ignores
set_default_openai_clientandset_default_openai_key#167How was this tested:
test_chat_completions_modelis parametrized with adefault_clientcase:OPENAI_API_KEYandOPENAI_BASE_URLpoint at an unreachable endpoint, the test client is set withset_default_openai_client, the plugin has nomodel_provider, and the model Activity gets one attempt. Onmainit fails withWorkflowFailureError, caused by aConnectErrorto the environment's endpoint. With this change it passes. Thedefault_keycase setsOPENAI_API_KEYto another key and the test key withset_default_openai_key, and checks that every model request carries the test key. Onmainit fails because the request carries the environment's key. With this change it passes. Themodel_providercase passes on both.set_default_openai_clientandset_default_openai_key#167 exits 1 ontemporalio-openai-agents1.1.0 and onmain, and 0 with this change: the default client case goes to/bwithkey-band the default key case to/awithkey-c, as in native runs.OPENAI_CUSTOM_HEADERS(anAuthorizationheader),OPENAI_ORG_IDandOPENAI_PROJECT_IDare set after the default client is built. With this change the Workflow sends the same headers as a native run (Bearer configured-key, no organization or project), and the client's own retries apply. The first commit, which copied the client withwith_options(max_retries=0), sent the environment's key and account headers; the second commit fixes that.ruff check --select I,ruff format --check,pyright,mypy,basedpyrightandpydocstylepass, and the full suite passes (388 tests). The container's uv 0.13.1 is outside the range themaketargets need, so the environment was made withUV_NO_EDITABLE=1 uv --no-config sync --frozenand the tools ran from the venv. The min Python, macOS and Windows cells did not run locally.Any docs updates needed?
The plugin README's "Model Providers" section has a new paragraph. Release notes must say where model calls now go and how to keep the environment's endpoint and key.
Not covered
RunConfig(model_provider=...)is also ignored in Workflows. That needs its own fix (a clear refusal) and is not in this PR.max_retries=0on a client the application set;openaihas no copy that keeps the client's settings without reading the environment again.temporalio1.34.0 bundles its own copy of the plugin astemporalio.contrib.openai_agents, with the same default client, so it needs the same change intemporalio/sdk-python. On sdk-pythonmainthat module only re-exportstemporalio.openai_agentsand gets the fix from a release of this package.Open questions
set_default_openai_clientroute broken by default.