@ai-sdk/openai 4.0.32 → 4.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2812 -2315
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +646 -22
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +38 -0
- package/package.json +1 -1
- package/src/openai-provider.ts +6 -5
- package/src/openai-responses-batch.ts +675 -0
- package/src/responses/openai-responses-language-model.ts +1 -1
package/docs/03-openai.mdx
CHANGED
|
@@ -1858,6 +1858,44 @@ The metadata includes the following fields:
|
|
|
1858
1858
|
- **itemId** _string_ — The ID of the compaction item in the Responses API
|
|
1859
1859
|
- **encryptedContent** _string_ (optional) — The encrypted compaction state. This is automatically sent back to the API when the message is included in subsequent requests.
|
|
1860
1860
|
|
|
1861
|
+
### Text Batches
|
|
1862
|
+
|
|
1863
|
+
<Note type="warning">
|
|
1864
|
+
Text batch APIs are experimental and may change in future releases.
|
|
1865
|
+
</Note>
|
|
1866
|
+
|
|
1867
|
+
The OpenAI provider supports the [Batch API](https://developers.openai.com/api/docs/guides/batch) for text generation.
|
|
1868
|
+
|
|
1869
|
+
```ts
|
|
1870
|
+
import { openai } from '@ai-sdk/openai';
|
|
1871
|
+
import {
|
|
1872
|
+
experimental_startTextBatch as startTextBatch,
|
|
1873
|
+
experimental_getBatchResults as getBatchResults,
|
|
1874
|
+
experimental_getBatchStatus as getBatchStatus,
|
|
1875
|
+
} from 'ai';
|
|
1876
|
+
|
|
1877
|
+
const model = openai('gpt-4.1-nano');
|
|
1878
|
+
|
|
1879
|
+
const batch = await startTextBatch({
|
|
1880
|
+
model,
|
|
1881
|
+
requests: [
|
|
1882
|
+
{ id: 'france', prompt: 'What is the capital of France?' },
|
|
1883
|
+
{ id: 'germany', prompt: 'What is the capital of Germany?' },
|
|
1884
|
+
],
|
|
1885
|
+
});
|
|
1886
|
+
|
|
1887
|
+
// Persist `batch` and check its status later, or poll for status updates.
|
|
1888
|
+
const { status } = await getBatchStatus({ model, batch });
|
|
1889
|
+
|
|
1890
|
+
if (status !== 'pending') {
|
|
1891
|
+
for await (const result of getBatchResults({ model, batch })) {
|
|
1892
|
+
console.log(result);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
```
|
|
1896
|
+
|
|
1897
|
+
Starting a batch returns a serializable reference that can be persisted and used to retrieve the batch results later, or poll for status updates.
|
|
1898
|
+
|
|
1861
1899
|
### Chat Models
|
|
1862
1900
|
|
|
1863
1901
|
You can create models that call the [OpenAI chat API](https://platform.openai.com/docs/api-reference/chat) using the `.chat()` factory method.
|
package/package.json
CHANGED
package/src/openai-provider.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
EmbeddingModelV4,
|
|
3
|
+
Experimental_BatchLanguageModelV4 as BatchLanguageModelV4,
|
|
3
4
|
FilesV4,
|
|
4
5
|
ImageModelV4,
|
|
5
6
|
LanguageModelV4,
|
|
@@ -30,8 +31,8 @@ import type { OpenAIEmbeddingModelId } from './embedding/openai-embedding-model-
|
|
|
30
31
|
import { OpenAIImageModel } from './image/openai-image-model';
|
|
31
32
|
import type { OpenAIImageModelId } from './image/openai-image-model-options';
|
|
32
33
|
import { openaiTools } from './openai-tools';
|
|
34
|
+
import { OpenAIResponsesBatchLanguageModel } from './openai-responses-batch';
|
|
33
35
|
import { OpenAIRealtimeModel } from './realtime/openai-realtime-model';
|
|
34
|
-
import { OpenAIResponsesLanguageModel } from './responses/openai-responses-language-model';
|
|
35
36
|
import type { OpenAIResponsesModelId } from './responses/openai-responses-language-model-options';
|
|
36
37
|
import { OpenAISpeechModel } from './speech/openai-speech-model';
|
|
37
38
|
import type { OpenAISpeechModelId } from './speech/openai-speech-model-options';
|
|
@@ -43,12 +44,12 @@ import { OpenAISkills } from './skills/openai-skills';
|
|
|
43
44
|
import { VERSION } from './version';
|
|
44
45
|
|
|
45
46
|
export interface OpenAIProvider extends ProviderV4 {
|
|
46
|
-
(modelId: OpenAIResponsesModelId):
|
|
47
|
+
(modelId: OpenAIResponsesModelId): BatchLanguageModelV4;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Creates an OpenAI model for text generation.
|
|
50
51
|
*/
|
|
51
|
-
languageModel(modelId: OpenAIResponsesModelId):
|
|
52
|
+
languageModel(modelId: OpenAIResponsesModelId): BatchLanguageModelV4;
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Creates an OpenAI chat model for text generation.
|
|
@@ -58,7 +59,7 @@ export interface OpenAIProvider extends ProviderV4 {
|
|
|
58
59
|
/**
|
|
59
60
|
* Creates an OpenAI responses API model for text generation.
|
|
60
61
|
*/
|
|
61
|
-
responses(modelId: OpenAIResponsesModelId):
|
|
62
|
+
responses(modelId: OpenAIResponsesModelId): BatchLanguageModelV4;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Creates an OpenAI completion model for text generation.
|
|
@@ -301,7 +302,7 @@ export function createOpenAI(
|
|
|
301
302
|
};
|
|
302
303
|
|
|
303
304
|
const createResponsesModel = (modelId: OpenAIResponsesModelId) => {
|
|
304
|
-
return new
|
|
305
|
+
return new OpenAIResponsesBatchLanguageModel(modelId, {
|
|
305
306
|
provider: `${providerName}.responses`,
|
|
306
307
|
url: ({ path }) => `${baseURL}${path}`,
|
|
307
308
|
headers: getHeaders,
|