Skip to content

Commit 245d798

Browse files
hntrlopen-swe
andcommitted
fix(openai): support Azure AD auth with OpenAI 3.8
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
1 parent 79cab2d commit 245d798

12 files changed

Lines changed: 209 additions & 138 deletions

File tree

libs/partners/openai/langchain_openai/chat_models/azure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ def validate_environment(self) -> Self:
683683
},
684684
"default_query": self.default_query,
685685
}
686+
if self.azure_ad_token or self.azure_ad_token_provider:
687+
client_params["api_key"] = None
686688
if self.max_retries is not None:
687689
client_params["max_retries"] = self.max_retries
688690

libs/partners/openai/langchain_openai/data/_profiles.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,36 @@
11701170
],
11711171
"reasoning_effort_default": "medium",
11721172
},
1173+
"gpt-6-astra": {
1174+
"image_url_inputs": True,
1175+
"pdf_inputs": True,
1176+
"pdf_tool_message": True,
1177+
"image_tool_message": True,
1178+
"tool_choice": True,
1179+
"tool_call_streaming": True,
1180+
"name": "GPT-6 Astra",
1181+
"release_date": "2026-09-03",
1182+
"last_updated": "2026-09-03",
1183+
"open_weights": False,
1184+
"max_input_tokens": 1050000,
1185+
"max_output_tokens": 128000,
1186+
"text_inputs": True,
1187+
"image_inputs": True,
1188+
"text_outputs": True,
1189+
"reasoning_output": True,
1190+
"tool_calling": True,
1191+
"structured_output": True,
1192+
"attachment": True,
1193+
"temperature": False,
1194+
"reasoning_effort_levels": [
1195+
"low",
1196+
"medium",
1197+
"high",
1198+
"xhigh",
1199+
"max",
1200+
],
1201+
"reasoning_effort_default": "medium",
1202+
},
11731203
"gpt-image-1": {
11741204
"name": "gpt-image-1",
11751205
"status": "deprecated",

libs/partners/openai/langchain_openai/data/profile_augmentations.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,21 @@ reasoning_effort_default = "medium"
114114
[overrides."gpt-5.6-terra"]
115115
reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]
116116
reasoning_effort_default = "medium"
117+
118+
[overrides."gpt-6-astra"]
119+
name = "GPT-6 Astra"
120+
release_date = "2026-09-03"
121+
last_updated = "2026-09-03"
122+
open_weights = false
123+
max_input_tokens = 1050000
124+
max_output_tokens = 128000
125+
text_inputs = true
126+
image_inputs = true
127+
text_outputs = true
128+
reasoning_output = true
129+
tool_calling = true
130+
structured_output = true
131+
attachment = true
132+
temperature = false
133+
reasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]
134+
reasoning_effort_default = "medium"

libs/partners/openai/langchain_openai/embeddings/azure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def validate_environment(self) -> Self:
205205
},
206206
"default_query": self.default_query,
207207
}
208+
if self.azure_ad_token or self.azure_ad_token_provider:
209+
client_params["api_key"] = None
208210
if not self.client:
209211
sync_specific: dict = {"http_client": self.http_client}
210212
self.client = openai.AzureOpenAI(

libs/partners/openai/langchain_openai/llms/azure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def validate_environment(self) -> Self:
181181
},
182182
"default_query": self.default_query,
183183
}
184+
if self.azure_ad_token or self.azure_ad_token_provider:
185+
client_params["api_key"] = None
184186
if not self.client:
185187
sync_specific = {"http_client": self.http_client}
186188
self.client = openai.AzureOpenAI(

libs/partners/openai/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ requires-python = ">=3.10.0,<4.0.0"
2525
dependencies = [
2626
"langchain-core>=1.6.0,<2.0.0",
2727
"certifi>=2024.6.2",
28-
"openai>=2.45.0,<4.0.0",
28+
"openai>=3.8.0,<4.0.0",
2929
"tiktoken>=0.7.0,<1.0.0",
3030
]
3131

libs/partners/openai/tests/unit_tests/chat_models/test_azure.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
AZURE_PROFILE_TEST_MODEL = "gpt-5.5"
1616
AZURE_PROFILE_TEST_MODEL_NAME = "GPT-5.5"
1717
AZURE_PROFILE_TEST_MAX_INPUT_TOKENS = 1_050_000
18+
AZURE_AD_TOKEN = "token" # noqa: S105
1819

1920

2021
def test_initialize_azure_openai() -> None:
@@ -29,6 +30,17 @@ def test_initialize_azure_openai() -> None:
2930
assert llm.azure_endpoint == "my-base-url"
3031

3132

33+
def test_azure_ad_token_takes_precedence_over_api_key() -> None:
34+
llm = AzureChatOpenAI(
35+
api_key="api_key",
36+
azure_ad_token=AZURE_AD_TOKEN,
37+
azure_endpoint="https://endpoint.com",
38+
api_version="2023-05-15",
39+
)
40+
41+
assert llm.root_client._azure_ad_token == AZURE_AD_TOKEN
42+
43+
3244
def test_initialize_more() -> None:
3345
llm = AzureChatOpenAI( # type: ignore[call-arg]
3446
api_key="xyz", # type: ignore[arg-type]

libs/partners/openai/tests/unit_tests/chat_models/test_azure_standard.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_bind_tool_pydantic(
3131
def init_from_env_params(self) -> tuple[dict, dict, dict]:
3232
return (
3333
{
34-
"AZURE_OPENAI_API_KEY": "api_key",
3534
"AZURE_OPENAI_ENDPOINT": "https://endpoint.com",
3635
"AZURE_OPENAI_AD_TOKEN": "token",
3736
"OPENAI_ORG_ID": "org_id",
@@ -40,7 +39,6 @@ def init_from_env_params(self) -> tuple[dict, dict, dict]:
4039
},
4140
{},
4241
{
43-
"openai_api_key": "api_key",
4442
"azure_endpoint": "https://endpoint.com",
4543
"azure_ad_token": "token",
4644
"openai_organization": "org_id",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from langchain_openai import AzureOpenAIEmbeddings
2+
3+
AZURE_AD_TOKEN = "token" # noqa: S105
4+
5+
6+
def test_azure_ad_token_takes_precedence_over_api_key() -> None:
7+
embeddings = AzureOpenAIEmbeddings(
8+
api_key="api_key",
9+
azure_ad_token=AZURE_AD_TOKEN,
10+
azure_endpoint="https://endpoint.com",
11+
api_version="2023-05-15",
12+
)
13+
14+
assert embeddings.client._client._azure_ad_token == AZURE_AD_TOKEN

libs/partners/openai/tests/unit_tests/embeddings/test_azure_standard.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def embedding_model_params(self) -> dict:
1717
def init_from_env_params(self) -> tuple[dict, dict, dict]:
1818
return (
1919
{
20-
"AZURE_OPENAI_API_KEY": "api_key",
2120
"AZURE_OPENAI_ENDPOINT": "https://endpoint.com",
2221
"AZURE_OPENAI_AD_TOKEN": "token",
2322
"OPENAI_ORG_ID": "org_id",
@@ -26,7 +25,6 @@ def init_from_env_params(self) -> tuple[dict, dict, dict]:
2625
},
2726
{},
2827
{
29-
"openai_api_key": "api_key",
3028
"azure_endpoint": "https://endpoint.com",
3129
"azure_ad_token": "token",
3230
"openai_organization": "org_id",

0 commit comments

Comments
 (0)