Skip to content

Commit bba2eea

Browse files
ci(tutorials): route the tutorials CI's OpenAI calls through the internal gateway (#573)
1 parent d94a1dd commit bba2eea

5 files changed

Lines changed: 44 additions & 7 deletions

File tree

‎.github/workflows/agentex-tutorials-test.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ jobs:
162162
id: run-test
163163
working-directory: ./examples/tutorials
164164
env:
165-
OPENAI_API_KEY: ${{ secrets.TUTORIAL_OPENAI_API_KEY }}
165+
# OpenAI calls go through an internal gateway that passes the OpenAI API through
166+
# unchanged. The key and the gateway URL are both secrets, scoped to this CI.
167+
OPENAI_API_KEY: ${{ secrets.TUTORIAL_SMIG_API_KEY }}
168+
OPENAI_BASE_URL: ${{ secrets.TUTORIAL_OPENAI_BASE_URL }}
169+
# The OpenAI Agents SDK exports traces to api.openai.com with OPENAI_API_KEY and ignores
170+
# OPENAI_BASE_URL, which would send the gateway key to OpenAI. CI doesn't need those traces.
171+
OPENAI_AGENTS_DISABLE_TRACING: "1"
166172
ANTHROPIC_API_KEY: ${{ secrets.TUTORIAL_ANTHROPIC_API_KEY }}
167173
# Enable the gated live tests only for the matching subprocess-CLI
168174
# harness tutorial (the CLI is installed for it in the step above).

‎examples/tutorials/10_async/00_base/040_other_sdks/project/acp.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class StateModel(BaseModel):
4848
turn_number: int
4949

5050

51+
def _websearch_env():
52+
"""Env for the web search MCP server: the OpenAI key, plus OPENAI_BASE_URL when set (for a gateway)."""
53+
env = {"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")}
54+
if os.environ.get("OPENAI_BASE_URL"):
55+
env["OPENAI_BASE_URL"] = os.environ["OPENAI_BASE_URL"]
56+
return env
57+
58+
5159
MCP_SERVERS = [
5260
StdioServerParameters(
5361
command="npx",
@@ -59,7 +67,7 @@ class StateModel(BaseModel):
5967
# unpinned, so cap it until the server allows a newer mcp.
6068
command="uvx",
6169
args=["--with", "pydantic<2.14", "openai-websearch-mcp"],
62-
env={"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")},
70+
env=_websearch_env(),
6371
),
6472
]
6573

‎examples/tutorials/10_async/10_temporal/010_agent_chat/project/workflow.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class StateModel(BaseModel):
4848
turn_number: int
4949

5050

51+
def _websearch_env():
52+
"""Env for the web search MCP server: the OpenAI key, plus OPENAI_BASE_URL when set (for a gateway)."""
53+
env = {"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")}
54+
if os.environ.get("OPENAI_BASE_URL"):
55+
env["OPENAI_BASE_URL"] = os.environ["OPENAI_BASE_URL"]
56+
return env
57+
58+
5159
MCP_SERVERS = [ # No longer needed due to reasoning
5260
# StdioServerParameters(
5361
# command="npx",
@@ -59,7 +67,7 @@ class StateModel(BaseModel):
5967
# pydantic helper that pydantic 2.14 removed; uvx resolves pydantic
6068
# unpinned, so cap it until the server allows a newer mcp.
6169
args=["--with", "pydantic<2.14", "openai-websearch-mcp"],
62-
env={"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")},
70+
env=_websearch_env(),
6371
),
6472
]
6573

‎examples/tutorials/10_async/10_temporal/020_state_machine/project/workflows/deep_research/performing_deep_research.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313

1414
logger = make_logger(__name__)
1515

16+
17+
def _websearch_env():
18+
"""Env for the web search MCP server: the OpenAI key, plus OPENAI_BASE_URL when set (for a gateway)."""
19+
env = {"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")}
20+
if os.environ.get("OPENAI_BASE_URL"):
21+
env["OPENAI_BASE_URL"] = os.environ["OPENAI_BASE_URL"]
22+
return env
23+
24+
1625
# These reference MCP servers still import the mcp 1.x API (``McpError``), which
1726
# mcp 2.0.0 renamed to ``MCPError``. uvx gives each server its own isolated env and
1827
# resolves ``mcp`` unpinned there, ignoring the version this project pins, so without
@@ -31,9 +40,7 @@
3140
StdioServerParameters(
3241
command="uvx",
3342
args=[*_MCP_PIN, "openai-websearch-mcp"],
34-
env={
35-
"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")
36-
}
43+
env=_websearch_env(),
3744
),
3845
StdioServerParameters(
3946
command="uvx",

‎examples/tutorials/10_async/10_temporal/050_agent_chat_guardrails/project/workflow.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class StateModel(BaseModel):
6767
turn_number: int
6868

6969

70+
def _websearch_env():
71+
"""Env for the web search MCP server: the OpenAI key, plus OPENAI_BASE_URL when set (for a gateway)."""
72+
env = {"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")}
73+
if os.environ.get("OPENAI_BASE_URL"):
74+
env["OPENAI_BASE_URL"] = os.environ["OPENAI_BASE_URL"]
75+
return env
76+
77+
7078
MCP_SERVERS = [
7179
StdioServerParameters(
7280
command="npx",
@@ -75,7 +83,7 @@ class StateModel(BaseModel):
7583
StdioServerParameters(
7684
command="uvx",
7785
args=["openai-websearch-mcp"],
78-
env={"OPENAI_API_KEY": os.environ.get("OPENAI_API_KEY", "")},
86+
env=_websearch_env(),
7987
),
8088
]
8189

0 commit comments

Comments
 (0)