Skip to content

Commit f169d32

Browse files
Merge pull request #7436 from mrbullwinkle/mrb_10_01_2025_api_update
[Azure OpenAI] API Lifecycle Update
2 parents a5acf63 + ab9febd commit f169d32

File tree

1 file changed

+137
-65
lines changed

1 file changed

+137
-65
lines changed

articles/ai-foundry/openai/api-version-lifecycle.md

Lines changed: 137 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ manager: nitinme
66
ms.service: azure-ai-foundry
77
ms.subservice: azure-ai-foundry-openai
88
ms.topic: conceptual
9-
ms.date: 09/05/2025
9+
ms.date: 10/01/2025
1010
author: mrbullwinkle
1111
ms.author: mbullwin
1212
recommendations: false
@@ -43,29 +43,13 @@ For the initial v1 Generally Available (GA) API launch we're only supporting a s
4343

4444
## Code changes
4545

46-
# [API Key](#tab/key)
46+
# [Python](#tab/python)
4747

48-
### Last generation API
48+
### v1 API
4949

50-
```python
51-
import os
52-
from openai import AzureOpenAI
53-
54-
client = AzureOpenAI(
55-
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
56-
api_version="2025-04-01-preview",
57-
azure_endpoint="https://YOUR-RESOURCE-NAME.openai.azure.com")
58-
)
59-
60-
response = client.responses.create(
61-
model="gpt-4.1-nano", # Replace with your model deployment name
62-
input="This is a test."
63-
)
50+
[Python v1 examples](./supported-languages.md)
6451

65-
print(response.model_dump_json(indent=2))
66-
```
67-
68-
### Next generation API
52+
**API Key**:
6953

7054
```python
7155
import os
@@ -88,33 +72,13 @@ print(response.model_dump_json(indent=2))
8872
- `base_url` passes the Azure OpenAI endpoint and `/openai/v1` is appended to the endpoint address.
8973
- `api-version` is no longer a required parameter with the v1 GA API.
9074

91-
# [Microsoft Entra ID](#tab/entra)
92-
93-
### Last generation API
75+
**API Key** with environment variables set for `OPENAI_BASE_URL` and `OPENAI_API_KEY`:
9476

9577
```python
96-
from openai import AzureOpenAI
97-
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
98-
99-
token_provider = get_bearer_token_provider(
100-
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
101-
)
102-
103-
client = AzureOpenAI(
104-
azure_endpoint = "https://YOUR-RESOURCE-NAME.openai.azure.com/",
105-
azure_ad_token_provider=token_provider,
106-
api_version="2025-04-01-preview"
107-
)
108-
109-
response = client.responses.create(
110-
model="gpt-4.1-nano", # Replace with your model deployment name
111-
input="This is a test."
112-
)
113-
114-
print(response.model_dump_json(indent=2))
78+
client = OpenAI()
11579
```
11680

117-
### Next generation API
81+
**Microsoft Entra ID**:
11882

11983
> [!IMPORTANT]
12084
> Handling automatic token refresh was previously handled through use of the `AzureOpenAI()` client. The v1 API removes this dependency, by adding automatic token refresh support to the `OpenAI()` client.
@@ -143,40 +107,148 @@ print(response.model_dump_json(indent=2))
143107
- `base_url` passes the Azure OpenAI endpoint and `/openai/v1` is appended to the endpoint address.
144108
- `api_key` parameter is set to `token_provider`, enabling automatic retrieval and refresh of an authentication token instead of using a static API key.
145109

146-
# [REST](#tab/rest)
110+
# [C#](#tab/dotnet)
111+
112+
### v1 API
147113

148-
### Last generation API
114+
[C# v1 examples](./supported-languages.md)
149115

150116
**API Key**:
151117

152-
```bash
153-
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview \
154-
-H "Content-Type: application/json" \
155-
-H "api-key: $AZURE_OPENAI_API_KEY" \
156-
-d '{
157-
"model": "gpt-4.1-nano",
158-
"input": "This is a test"
159-
}'
118+
```csharp
119+
OpenAIClient client = new(
120+
new ApiKeyCredential("{your-api-key}"),
121+
new OpenAIClientOptions()
122+
{
123+
Endpoint = new("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/"),
124+
})
160125
```
161126

162127
**Microsoft Entra ID**:
163128

164-
```bash
165-
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview \
166-
-H "Content-Type: application/json" \
167-
-H "Authorization: Bearer $AZURE_OPENAI_AUTH_TOKEN" \
168-
-d '{
169-
"model": "gpt-4.1-nano",
170-
"input": "This is a test"
171-
}'
129+
```csharp
130+
#pragma warning disable OPENAI001
131+
132+
BearerTokenPolicy tokenPolicy = new(
133+
new DefaultAzureCredential(),
134+
"https://cognitiveservices.azure.com/.default");
135+
OpenAIClient client = new(
136+
authenticationPolicy: tokenPolicy,
137+
options: new OpenAIClientOptions()
138+
{
139+
Endpoint = new("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/"),
140+
})
172141
```
173142

174-
### Next generation API
143+
# [JavaScript](#tab/javascript)
144+
145+
### v1 API
146+
147+
[JavaScript v1 examples](./supported-languages.md)
148+
149+
**API Key**:
150+
151+
```javascript
152+
const client = new OpenAI({
153+
baseURL: "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
154+
apiKey: "{your-api-key}"
155+
});
156+
```
157+
158+
**API Key** with environment variables set for `OPENAI_BASE_URL` and `OPENAI_API_KEY`:
159+
160+
```javascript
161+
const client = new OpenAI();
162+
```
163+
164+
**Microsoft Entra ID**:
165+
166+
```javascript
167+
const tokenProvider = getBearerTokenProvider(
168+
new DefaultAzureCredential(),
169+
'https://cognitiveservices.azure.com/.default');
170+
const client = new OpenAI({
171+
baseURL: "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
172+
apiKey: tokenProvider
173+
});
174+
```
175+
176+
# [Go](#tab/go)
177+
178+
### v1 API
179+
180+
[Go v1 examples](./supported-languages.md)
181+
182+
**API Key**:
183+
184+
```go
185+
client := openai.NewClient(
186+
option.WithBaseURL("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/"),
187+
option.WithAPIKey("{your-api-key}")
188+
)
189+
```
190+
191+
**API Key** with environment variables set for `OPENAI_BASE_URL` and `OPENAI_API_KEY`:
192+
193+
```go
194+
client := openai.NewClient()
195+
```
196+
197+
198+
**Microsoft Entra ID**:
199+
200+
```go
201+
tokenCredential, err := azidentity.NewDefaultAzureCredential(nil)
202+
203+
client := openai.NewClient(
204+
option.WithBaseURL("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/"),
205+
azure.WithTokenCredential(tokenCredential)
206+
)
207+
```
208+
209+
# [Java](#tab/Java)
210+
211+
### v1 API
212+
213+
**API Key**:
214+
215+
```java
216+
217+
OpenAIClient client = OpenAIOkHttpClient.builder()
218+
.baseUrl("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/")
219+
.credential(AzureApiKeyCredential.create("{your-api-key}"))
220+
.build();
221+
```
222+
223+
**API Key** with environment variables set for `OPENAI_BASE_URL` and `OPENAI_API_KEY`:
224+
225+
```java
226+
OpenAIClient client = OpenAIOkHttpClient.builder()
227+
.fromEnv()
228+
.build();
229+
```
230+
231+
**Microsoft Entra ID**:
232+
233+
```java
234+
Credential tokenCredential = BearerTokenCredential.create(
235+
AuthenticationUtil.getBearerTokenSupplier(
236+
new DefaultAzureCredentialBuilder().build(),
237+
"https://cognitiveservices.azure.com/.default"));
238+
OpenAIClient client = OpenAIOkHttpClient.builder()
239+
.baseUrl("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/")
240+
.credential(tokenCredential)
241+
.build();
242+
```
243+
244+
# [REST](#tab/rest)
245+
246+
### v1 API
175247

176248
**API Key**:
177249

178250
```bash
179-
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses?api-version=preview \
251+
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses \
180252
-H "Content-Type: application/json" \
181253
-H "api-key: $AZURE_OPENAI_API_KEY" \
182254
-d '{
@@ -188,7 +260,7 @@ curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses?api
188260
**Microsoft Entra ID**:
189261

190262
```bash
191-
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses?api-version=preview \
263+
curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses \
192264
-H "Content-Type: application/json" \
193265
-H "Authorization: Bearer $AZURE_OPENAI_AUTH_TOKEN" \
194266
-d '{

0 commit comments

Comments
 (0)