Skip to content

Commit 0a3ff77

Browse files
committed
update
1 parent f400acb commit 0a3ff77

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed

articles/ai-services/openai/how-to/batch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ manager: nitinme
66
ms.service: azure-ai-openai
77
ms.custom: references_regions
88
ms.topic: how-to
9-
ms.date: 01/14/2025
9+
ms.date: 03/31/2025
1010
author: mrbullwinkle
1111
ms.author: mbullwin
1212
recommendations: false

articles/ai-services/openai/includes/batch/batch-python.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,21 @@ token_provider = get_bearer_token_provider(
9595
client = AzureOpenAI(
9696
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
9797
azure_ad_token_provider=token_provider,
98-
api_version="2024-10-21"
98+
api_version="2025-03-01-preview"
9999
)
100100

101101
# Upload a file with a purpose of "batch"
102102
file = client.files.create(
103103
file=open("test.jsonl", "rb"),
104-
purpose="batch"
104+
purpose="batch",
105+
extra_body={"expires_after":{"seconds": 1209600, "anchor": "created_at"}} # Optional you can set to a number between 1209600-2592000. This is equivalent to 14-30 days
105106
)
106107

108+
107109
print(file.model_dump_json(indent=2))
110+
111+
print(f"File expiration: {datetime.fromtimestamp(file.expires_at) if file.expires_at is not None else 'Not set'}")
112+
108113
file_id = file.id
109114
```
110115

@@ -118,37 +123,48 @@ from openai import AzureOpenAI
118123

119124
client = AzureOpenAI(
120125
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
121-
api_version="2024-10-21",
126+
api_version="2025-03-01-preview",
122127
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
123128
)
124129

125130
# Upload a file with a purpose of "batch"
126131
file = client.files.create(
127132
file=open("test.jsonl", "rb"),
128-
purpose="batch"
133+
purpose="batch",
134+
extra_body={"expires_after":{"seconds": 1209600, "anchor": "created_at"}} # Optional you can set to a number between 1209600-2592000. This is equivalent to 14-30 days
129135
)
130136

137+
131138
print(file.model_dump_json(indent=2))
139+
140+
print(f"File expiration: {datetime.fromtimestamp(file.expires_at) if file.expires_at is not None else 'Not set'}")
141+
132142
file_id = file.id
133143
```
134144

135145
---
136146

147+
By adding `extra_body={"expires_after":{"seconds": 1209600, "anchor": "created_at"}}` you are setting our upload file to expire in 14 days. There is a max limit of 500 batch files per resource when no expiration is set. By setting a value for expiration the number of batch files per resource is increased to 10,000 files per resource.
148+
137149
**Output:**
138150

139151
```json
140152
{
141-
"id": "file-9f3a81d899b4442f98b640e4bc3535dd",
142-
"bytes": 815,
143-
"created_at": 1722476551,
153+
"id": "file-655111ec9cfc44489d9af078f08116ef",
154+
"bytes": 176064,
155+
"created_at": 1743391067,
144156
"filename": "test.jsonl",
145157
"object": "file",
146158
"purpose": "batch",
147-
"status": null,
159+
"status": "processed",
160+
"expires_at": 1744600667,
148161
"status_details": null
149162
}
163+
File expiration: 2025-04-13 23:17:47
150164
```
151165

166+
167+
152168
## Create batch job
153169

154170
Once your file has uploaded successfully you can submit the file for batch processing.
@@ -159,14 +175,19 @@ batch_response = client.batches.create(
159175
input_file_id=file_id,
160176
endpoint="/chat/completions",
161177
completion_window="24h",
178+
extra_body={"output_expires_after":{"seconds": 1209600, "anchor": "created_at"}} # Optional you can set to a number between 1209600-2592000. This is equivalent to 14-30 days
179+
)
162180
)
163181

164182
# Save batch ID for later use
165183
batch_id = batch_response.id
166184

167185
print(batch_response.model_dump_json(indent=2))
186+
168187
```
169188

189+
The default 500 max file limit per resource also applies to output files. Here you add `extra_body={"output_expires_after":{"seconds": 1209600, "anchor": "created_at"}}` so that your output files expire in 14 days. By setting a value for expiration the number of batch files per resource is increased to 10,000 files per resource.
190+
170191
> [!NOTE]
171192
> Currently the completion window must be set to 24h. If you set any other value than 24h your job will fail. Jobs taking longer than 24 hours will continue to execute until canceled.
172193
@@ -178,7 +199,7 @@ print(batch_response.model_dump_json(indent=2))
178199
"completion_window": "24h",
179200
"created_at": 1722476583,
180201
"endpoint": null,
181-
"input_file_id": "file-9f3a81d899b4442f98b640e4bc3535dd",
202+
"input_file_id": "file-655111ec9cfc44489d9af078f08116ef",
182203
"object": "batch",
183204
"status": "validating",
184205
"cancelled_at": null,

articles/ai-services/openai/includes/batch/batch-rest.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,33 @@ Once your input file is prepared, you first need to upload the file to then be a
7474
[!INCLUDE [Azure key vault](~/reusable-content/ce-skilling/azure/includes/ai-services/security/azure-key-vault.md)]
7575

7676
```http
77-
curl -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files?api-version=2024-10-21 \
77+
curl -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files?api-version=2025-03-01-preview \
7878
-H "Content-Type: multipart/form-data" \
7979
-H "api-key: $AZURE_OPENAI_API_KEY" \
8080
-F "purpose=batch" \
81-
-F "file=@C:\\batch\\test.jsonl;type=application/json"
81+
-F "file=@C:\\batch\\test.jsonl;type=application/json" \
82+
-F "expires_after.seconds=1209600" \
83+
-F "expires_after.anchor=created_at"
84+
8285
```
8386

84-
The above code assumes a particular file path for your test.jsonl file. Adjust this file path as necessary for your local system.
87+
The above code assumes a particular file path for your test.jsonl file. Adjust this file path as necessary for your local system.
88+
89+
By adding `"expires_after.seconds=1209600"` and `"expires_after.anchor=created_at"` you are setting your upload file to expire in 14 days. There is a max limit of 500 batch files per resource when no expiration is set. By setting a value for expiration the number of batch files per resource is increased to 10,000 files per resource. You can set to a number between 1209600-2592000. This is equivalent to 14-30 days.
90+
91+
8592

8693
**Output:**
8794

8895
```json
8996
{
90-
"status": "pending",
91-
"bytes": 686,
97+
"status": "processed",
98+
"bytes": 817,
9299
"purpose": "batch",
93100
"filename": "test.jsonl",
94-
"id": "file-21006e70789246658b86a1fc205899a4",
95-
"created_at": 1721408291,
101+
"expires_at": 1744607747,
102+
"id": "file-7733bc35e32841e297a62a9ee50b3461",
103+
"created_at": 1743398147,
96104
"object": "file"
97105
}
98106

@@ -104,7 +112,7 @@ The above code assumes a particular file path for your test.jsonl file. Adjust t
104112
Depending on the size of your upload file it might take some time before it's fully uploaded and processed. To check on your file upload status run:
105113

106114
```http
107-
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/{file-id}?api-version=2024-10-21 \
115+
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/{file-id}?api-version=2025-03-01-preview \
108116
-H "api-key: $AZURE_OPENAI_API_KEY"
109117
```
110118

@@ -116,7 +124,8 @@ curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/{file-id}?api-vers
116124
"bytes": 686,
117125
"purpose": "batch",
118126
"filename": "test.jsonl",
119-
"id": "file-21006e70789246658b86a1fc205899a4",
127+
"expires_at": 1744607747,
128+
"id": "file-7733bc35e32841e297a62a9ee50b3461",
120129
"created_at": 1721408291,
121130
"object": "file"
122131
}
@@ -128,16 +137,22 @@ curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/files/{file-id}?api-vers
128137
Once your file has uploaded successfully you can submit the file for batch processing.
129138

130139
```http
131-
curl -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/batches?api-version=2024-10-21 \
140+
curl -X POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/batches?api-version=2025-03-01-preview \
132141
-H "api-key: $AZURE_OPENAI_API_KEY" \
133142
-H "Content-Type: application/json" \
134143
-d '{
135144
"input_file_id": "file-abc123",
136145
"endpoint": "/chat/completions",
137-
"completion_window": "24h"
146+
"completion_window": "24h",
147+
"output_expires_after": {
148+
"seconds": 1209600
149+
},
150+
"anchor": "created_at"
138151
}'
139152
```
140153

154+
The default 500 max file limit per resource also applies to output files. Here you add `"output_expires_after":{"seconds": 1209600},` and `"anchor": "created_at"` so that your output files expire in 14 days. By setting a value for expiration the number of batch files per resource is increased to 10,000 files per resource.
155+
141156
> [!NOTE]
142157
> Currently the completion window must be set to 24h. If you set any other value than 24h your job will fail. Jobs taking longer than 24 hours will continue to execute until canceled.
143158

0 commit comments

Comments
 (0)