fix(templates): map LITELLM_API_KEY to OPENAI_API_KEY in Temporal workers - #514
Open
michaelxu2288 wants to merge 2 commits into
Open
michaelxu2288 wants to merge 2 commits into
michaelxu2288 wants to merge 2 commits into
Conversation
stainless-app
Bot
force-pushed
the
next
branch
2 times, most recently
from
September 18, 2026 21:47
bc51c52 to
761833e
Compare
…kers The temporal-openai-agents and temporal-pydantic-ai templates' .env.example only set LITELLM_API_KEY. The OpenAI Agents template's acp.py copies it into OPENAI_API_KEY, the Pydantic AI template never does, and in both the model call runs in the Temporal worker, a separate process started by agentex agents run, which never got the mapping. Following either template's own instructions fails in the worker with openai.OpenAIError: Missing credentials after the activity's retries, while the ACP process looks healthy. (temporal-langgraph is fine: graph.py, imported by the worker, already does the mapping.) Apply the same three-line mapping in both run_worker.py templates and add a parametrized test asserting the worker entrypoints carry it. Reproduced and verified on scaffolded agents against a local backend with only LITELLM_API_KEY set: before, no reply and Missing credentials in the worker log; after, the turn completes (gpt-5-nano). Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
…apping the key The worker is a separate process and agents run does not load the project .env into it today, so the LITELLM_API_KEY -> OPENAI_API_KEY mapping ran against an empty environment. Call load_dotenv() first (as acp.py already does), so the template works on its own; scaleapi#515 makes the CLI load .env for both processes as well. Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
michaelxu2288
force-pushed
the
fix/templates-temporal-openai-key
branch
from
October 1, 2026 09:40
b5f5e05 to
cd23d16
Compare
This branch has not been deployed
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.
Problem
temporal-openai-agentsandtemporal-pydantic-aiship an.env.examplethat only setsLITELLM_API_KEY. In the OpenAI Agents template,project/acp.pycopies it intoOPENAI_API_KEY; the Pydantic AI template never does. In both, the model call runs in the Temporal worker, a separate process started byagentex agents run, which never gets the mapping. Following either template's own instructions fails in the worker withopenai.OpenAIError: Missing credentialsafter the activity's retries, while the ACP process looks healthy and the task just never answers. (temporal-langgraphis fine:graph.py, which the worker imports, already maps the key.)Repro:
agentex init(Temporal + OpenAI Agents SDK, or Temporal + Pydantic AI),.envwith onlyLITELLM_API_KEY=<openai key>, run against./dev.sh, send a message: no reply; worker log shows Missing credentials.Fix
Apply the same three-line mapping (no-op when
OPENAI_API_KEYis already set) in bothproject/run_worker.pytemplates, and add a parametrized test asserting the worker entrypoints carry it.Verification
Scaffolded agents against a local backend with only
LITELLM_API_KEYset:Depends on / pairs with #515 ("fix(cli): load the agent's .env into locally run ACP and worker processes"): without it,
.envreaches the worker only through litellm's import-timeload_dotenv(), which is too late for frameworks that build their client at import. The mapping is placed at the top ofrun_worker.py, before project imports, for that reason.tests/lib/cli/test_init_templates.py: 28 passed. ruff clean.The PR is not ready to merge because a generated requirements image can fail to build when its private mirror lacks a public dependency.
What we checked:
.envand map the key before their project imports.Summary
The PR adds early API-key setup to two Temporal worker templates and makes ACP wait for task creation before replying. It also updates the SDK’s production URL and changes release, security-scanning, and repository CI workflows.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR S[Injected index secret] --> D[Requirements Dockerfile] D --> M[Private mirror as default] M -->|Package present| B[Image builds] M -->|Public package missing| F[Image build fails]Reviews (3) · Last reviewed commit: "fix(templates): load the project .env in..."