@ai-sdk/openai-compatible 3.0.0-beta.5 → 3.0.0-beta.58

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +440 -8
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +69 -8
  4. package/dist/index.js +548 -428
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +20 -2
  7. package/dist/internal/index.js +91 -91
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/index.mdx +1 -0
  10. package/package.json +16 -17
  11. package/src/chat/convert-openai-compatible-chat-usage.ts +1 -1
  12. package/src/chat/convert-to-openai-compatible-chat-messages.ts +94 -73
  13. package/src/chat/map-openai-compatible-finish-reason.ts +1 -1
  14. package/src/chat/openai-compatible-api-types.ts +3 -5
  15. package/src/chat/openai-compatible-chat-language-model.ts +205 -191
  16. package/src/chat/openai-compatible-metadata-extractor.ts +1 -1
  17. package/src/chat/openai-compatible-prepare-tools.ts +2 -3
  18. package/src/completion/convert-openai-compatible-completion-usage.ts +1 -1
  19. package/src/completion/convert-to-openai-compatible-completion-prompt.ts +1 -2
  20. package/src/completion/map-openai-compatible-finish-reason.ts +1 -1
  21. package/src/completion/openai-compatible-completion-language-model.ts +52 -17
  22. package/src/embedding/openai-compatible-embedding-model.ts +36 -10
  23. package/src/image/openai-compatible-image-model.ts +35 -13
  24. package/src/index.ts +3 -3
  25. package/src/openai-compatible-error.ts +1 -2
  26. package/src/openai-compatible-provider.ts +18 -5
  27. package/src/utils/to-camel-case.ts +43 -0
  28. package/dist/index.d.mts +0 -290
  29. package/dist/index.mjs +0 -1742
  30. package/dist/index.mjs.map +0 -1
  31. package/dist/internal/index.d.mts +0 -193
  32. package/dist/internal/index.mjs +0 -340
  33. package/dist/internal/index.mjs.map +0 -1
  34. /package/src/chat/{openai-compatible-chat-options.ts → openai-compatible-chat-language-model-options.ts} +0 -0
  35. /package/src/completion/{openai-compatible-completion-options.ts → openai-compatible-completion-language-model-options.ts} +0 -0
  36. /package/src/embedding/{openai-compatible-embedding-options.ts → openai-compatible-embedding-model-options.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,437 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 3.0.0-beta.58
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0416e3e]
8
+ - @ai-sdk/provider@4.0.0-beta.20
9
+ - @ai-sdk/provider-utils@5.0.0-beta.50
10
+
11
+ ## 3.0.0-beta.57
12
+
13
+ ### Patch Changes
14
+
15
+ - b8396f0: trigger initial beta release
16
+ - Updated dependencies [b8396f0]
17
+ - @ai-sdk/provider-utils@5.0.0-beta.49
18
+ - @ai-sdk/provider@4.0.0-beta.19
19
+
20
+ ## 3.0.0-canary.56
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [aeda373]
25
+ - Updated dependencies [375fdd7]
26
+ - Updated dependencies [b4507d5]
27
+ - @ai-sdk/provider-utils@5.0.0-canary.48
28
+
29
+ ## 3.0.0-canary.55
30
+
31
+ ### Patch Changes
32
+
33
+ - Updated dependencies [bae5e2b]
34
+ - @ai-sdk/provider-utils@5.0.0-canary.47
35
+
36
+ ## 3.0.0-canary.54
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [ce769dd]
41
+ - @ai-sdk/provider@4.0.0-canary.18
42
+ - @ai-sdk/provider-utils@5.0.0-canary.46
43
+
44
+ ## 3.0.0-canary.53
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [ee798eb]
49
+ - Updated dependencies [daf6637]
50
+ - @ai-sdk/provider-utils@5.0.0-canary.45
51
+
52
+ ## 3.0.0-canary.52
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [6c93e36]
57
+ - Updated dependencies [f617ac2]
58
+ - @ai-sdk/provider-utils@5.0.0-canary.44
59
+
60
+ ## 3.0.0-canary.51
61
+
62
+ ### Patch Changes
63
+
64
+ - 9f1e1ba: fix: accept empty string `role` in streaming delta chunks from OpenAI-compatible providers
65
+
66
+ ## 3.0.0-canary.50
67
+
68
+ ### Patch Changes
69
+
70
+ - 7fc6bd6: Raise minimum supported Node.js version to 22. Supported versions: 22, 24, and 26.
71
+ - Updated dependencies [7fc6bd6]
72
+ - @ai-sdk/provider-utils@5.0.0-canary.43
73
+ - @ai-sdk/provider@4.0.0-canary.17
74
+
75
+ ## 3.0.0-canary.49
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [a6617c5]
80
+ - @ai-sdk/provider-utils@5.0.0-canary.42
81
+
82
+ ## 3.0.0-canary.48
83
+
84
+ ### Patch Changes
85
+
86
+ - Updated dependencies [28dfa06]
87
+ - Updated dependencies [e93fa91]
88
+ - @ai-sdk/provider-utils@5.0.0-canary.41
89
+
90
+ ## 3.0.0-canary.47
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [a7de9c9]
95
+ - @ai-sdk/provider-utils@5.0.0-canary.40
96
+
97
+ ## 3.0.0-canary.46
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [105f95b]
102
+ - @ai-sdk/provider-utils@5.0.0-canary.39
103
+
104
+ ## 3.0.0-canary.45
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [ca446f8]
109
+ - @ai-sdk/provider-utils@5.0.0-canary.38
110
+
111
+ ## 3.0.0-canary.44
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies [d848405]
116
+ - @ai-sdk/provider-utils@5.0.0-canary.37
117
+
118
+ ## 3.0.0-canary.43
119
+
120
+ ### Patch Changes
121
+
122
+ - Updated dependencies [ca39020]
123
+ - @ai-sdk/provider-utils@5.0.0-canary.36
124
+
125
+ ## 3.0.0-canary.42
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [f634bac]
130
+ - @ai-sdk/provider-utils@5.0.0-canary.35
131
+
132
+ ## 3.0.0-canary.41
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [69254e0]
137
+ - Updated dependencies [3015fc3]
138
+ - @ai-sdk/provider-utils@5.0.0-canary.34
139
+
140
+ ## 3.0.0-canary.40
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies [2427d88]
145
+ - @ai-sdk/provider-utils@5.0.0-canary.33
146
+
147
+ ## 3.0.0-canary.39
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies [5463d0d]
152
+ - @ai-sdk/provider-utils@5.0.0-canary.32
153
+ - @ai-sdk/provider@4.0.0-canary.16
154
+
155
+ ## 3.0.0-canary.38
156
+
157
+ ### Patch Changes
158
+
159
+ - cd9c311: fix(openai, openai-compatible): only send null content for assistant messages with tool calls
160
+
161
+ ## 3.0.0-canary.37
162
+
163
+ ### Patch Changes
164
+
165
+ - 0c4c275: trigger initial canary release
166
+ - Updated dependencies [0c4c275]
167
+ - @ai-sdk/provider-utils@5.0.0-canary.31
168
+ - @ai-sdk/provider@4.0.0-canary.15
169
+
170
+ ## 3.0.0-beta.36
171
+
172
+ ### Patch Changes
173
+
174
+ - e59c955: feat(vertex): add grok models to vertex provider
175
+
176
+ ## 3.0.0-beta.35
177
+
178
+ ### Major Changes
179
+
180
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
181
+
182
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
183
+
184
+ ### Patch Changes
185
+
186
+ - Updated dependencies [08d2129]
187
+ - @ai-sdk/provider-utils@5.0.0-beta.30
188
+
189
+ ## 3.0.0-beta.34
190
+
191
+ ### Patch Changes
192
+
193
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
194
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
195
+ - Updated dependencies [9bd6512]
196
+ - Updated dependencies [258c093]
197
+ - Updated dependencies [b6783da]
198
+ - @ai-sdk/provider-utils@5.0.0-beta.29
199
+ - @ai-sdk/provider@4.0.0-beta.14
200
+
201
+ ## 3.0.0-beta.33
202
+
203
+ ### Patch Changes
204
+
205
+ - 9f0e36c: trigger release for all packages after provenance setup
206
+ - Updated dependencies [9f0e36c]
207
+ - @ai-sdk/provider@4.0.0-beta.13
208
+ - @ai-sdk/provider-utils@5.0.0-beta.28
209
+
210
+ ## 3.0.0-beta.32
211
+
212
+ ### Patch Changes
213
+
214
+ - ab81968: fix(openai-compatible): buffer tool call deltas until function.name arrives
215
+ - 58a2ad7: fix: more precise default message for tool execution denial
216
+ - Updated dependencies [785fe16]
217
+ - Updated dependencies [67df0a0]
218
+ - Updated dependencies [befb78c]
219
+ - Updated dependencies [0458559]
220
+ - Updated dependencies [5852c0a]
221
+ - Updated dependencies [fc92055]
222
+ - @ai-sdk/provider-utils@5.0.0-beta.27
223
+
224
+ ## 3.0.0-beta.31
225
+
226
+ ### Patch Changes
227
+
228
+ - bfb756d: patch - send content: null instead of empty string for tool-only assistant messages
229
+ - Updated dependencies [2e98477]
230
+ - @ai-sdk/provider-utils@5.0.0-beta.26
231
+
232
+ ## 3.0.0-beta.30
233
+
234
+ ### Patch Changes
235
+
236
+ - Updated dependencies [eea8d98]
237
+ - @ai-sdk/provider-utils@5.0.0-beta.25
238
+
239
+ ## 3.0.0-beta.29
240
+
241
+ ### Patch Changes
242
+
243
+ - f807e45: Extract shared `StreamingToolCallTracker` class into `@ai-sdk/provider-utils` to deduplicate streaming tool call handling across OpenAI-compatible providers. Also adds missing `generateId()` fallback for `toolCallId` in Alibaba's `doGenerate` path and ensures all providers finalize unfinished tool calls during stream flush.
244
+ - Updated dependencies [f807e45]
245
+ - @ai-sdk/provider-utils@5.0.0-beta.24
246
+
247
+ ## 3.0.0-beta.28
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies [350ea38]
252
+ - @ai-sdk/provider-utils@5.0.0-beta.23
253
+
254
+ ## 3.0.0-beta.27
255
+
256
+ ### Patch Changes
257
+
258
+ - Updated dependencies [083947b]
259
+ - @ai-sdk/provider-utils@5.0.0-beta.22
260
+
261
+ ## 3.0.0-beta.26
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies [add1126]
266
+ - @ai-sdk/provider-utils@5.0.0-beta.21
267
+
268
+ ## 3.0.0-beta.25
269
+
270
+ ### Patch Changes
271
+
272
+ - b3976a2: Add workflow serialization support to all provider models.
273
+
274
+ **`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
275
+
276
+ **All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
277
+
278
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
279
+
280
+ - Updated dependencies [b3976a2]
281
+ - Updated dependencies [ff5eba1]
282
+ - @ai-sdk/provider-utils@5.0.0-beta.20
283
+ - @ai-sdk/provider@4.0.0-beta.12
284
+
285
+ ## 3.0.0-beta.24
286
+
287
+ ### Major Changes
288
+
289
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
290
+
291
+ ### Patch Changes
292
+
293
+ - Updated dependencies [ef992f8]
294
+ - @ai-sdk/provider@4.0.0-beta.11
295
+ - @ai-sdk/provider-utils@5.0.0-beta.19
296
+
297
+ ## 3.0.0-beta.23
298
+
299
+ ### Patch Changes
300
+
301
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
302
+ - Updated dependencies [90e2d8a]
303
+ - @ai-sdk/provider-utils@5.0.0-beta.18
304
+
305
+ ## 3.0.0-beta.22
306
+
307
+ ### Patch Changes
308
+
309
+ - Updated dependencies [3ae1786]
310
+ - @ai-sdk/provider-utils@5.0.0-beta.17
311
+
312
+ ## 3.0.0-beta.21
313
+
314
+ ### Patch Changes
315
+
316
+ - Updated dependencies [176466a]
317
+ - @ai-sdk/provider@4.0.0-beta.10
318
+ - @ai-sdk/provider-utils@5.0.0-beta.16
319
+
320
+ ## 3.0.0-beta.20
321
+
322
+ ### Patch Changes
323
+
324
+ - Updated dependencies [e311194]
325
+ - @ai-sdk/provider@4.0.0-beta.9
326
+ - @ai-sdk/provider-utils@5.0.0-beta.15
327
+
328
+ ## 3.0.0-beta.19
329
+
330
+ ### Patch Changes
331
+
332
+ - 008271d: feat(openai-compatible): emit warning when using kebab-case instead of camelCase
333
+ - Updated dependencies [34bd95d]
334
+ - Updated dependencies [008271d]
335
+ - @ai-sdk/provider@4.0.0-beta.8
336
+ - @ai-sdk/provider-utils@5.0.0-beta.14
337
+
338
+ ## 3.0.0-beta.18
339
+
340
+ ### Patch Changes
341
+
342
+ - Updated dependencies [b0c2869]
343
+ - Updated dependencies [7e26e81]
344
+ - @ai-sdk/provider-utils@5.0.0-beta.13
345
+
346
+ ## 3.0.0-beta.17
347
+
348
+ ### Patch Changes
349
+
350
+ - 816ff67: fix(openai-compatible): honor camelCase providerOptions key in chat and completion models
351
+
352
+ ## 3.0.0-beta.16
353
+
354
+ ### Patch Changes
355
+
356
+ - Updated dependencies [46d1149]
357
+ - @ai-sdk/provider-utils@5.0.0-beta.12
358
+
359
+ ## 3.0.0-beta.15
360
+
361
+ ### Patch Changes
362
+
363
+ - 6fd51c0: fix(provider): preserve error type prefix in getErrorMessage
364
+ - Updated dependencies [6fd51c0]
365
+ - @ai-sdk/provider-utils@5.0.0-beta.11
366
+ - @ai-sdk/provider@4.0.0-beta.7
367
+
368
+ ## 3.0.0-beta.14
369
+
370
+ ### Patch Changes
371
+
372
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
373
+ - Updated dependencies [c29a26f]
374
+ - @ai-sdk/provider-utils@5.0.0-beta.10
375
+ - @ai-sdk/provider@4.0.0-beta.6
376
+
377
+ ## 3.0.0-beta.13
378
+
379
+ ### Patch Changes
380
+
381
+ - 38fc777: Add AI Gateway hint to provider READMEs
382
+
383
+ ## 3.0.0-beta.12
384
+
385
+ ### Patch Changes
386
+
387
+ - Updated dependencies [2e17091]
388
+ - @ai-sdk/provider-utils@5.0.0-beta.9
389
+
390
+ ## 3.0.0-beta.11
391
+
392
+ ### Patch Changes
393
+
394
+ - Updated dependencies [986c6fd]
395
+ - Updated dependencies [493295c]
396
+ - @ai-sdk/provider-utils@5.0.0-beta.8
397
+
398
+ ## 3.0.0-beta.10
399
+
400
+ ### Patch Changes
401
+
402
+ - Updated dependencies [1f509d4]
403
+ - @ai-sdk/provider-utils@5.0.0-beta.7
404
+ - @ai-sdk/provider@4.0.0-beta.5
405
+
406
+ ## 3.0.0-beta.9
407
+
408
+ ### Patch Changes
409
+
410
+ - 74d520f: feat: migrate providers to support new top-level `reasoning` parameter
411
+
412
+ ## 3.0.0-beta.8
413
+
414
+ ### Patch Changes
415
+
416
+ - Updated dependencies [3887c70]
417
+ - @ai-sdk/provider-utils@5.0.0-beta.6
418
+ - @ai-sdk/provider@4.0.0-beta.4
419
+
420
+ ## 3.0.0-beta.7
421
+
422
+ ### Patch Changes
423
+
424
+ - Updated dependencies [776b617]
425
+ - @ai-sdk/provider-utils@5.0.0-beta.5
426
+ - @ai-sdk/provider@4.0.0-beta.3
427
+
428
+ ## 3.0.0-beta.6
429
+
430
+ ### Patch Changes
431
+
432
+ - Updated dependencies [61753c3]
433
+ - @ai-sdk/provider-utils@5.0.0-beta.4
434
+
3
435
  ## 3.0.0-beta.5
4
436
 
5
437
  ### Patch Changes
@@ -309,13 +741,13 @@
309
741
  Before
310
742
 
311
743
  ```ts
312
- model.textEmbeddingModel('my-model-id');
744
+ model.textEmbeddingModel("my-model-id");
313
745
  ```
314
746
 
315
747
  After
316
748
 
317
749
  ```ts
318
- model.embeddingModel('my-model-id');
750
+ model.embeddingModel("my-model-id");
319
751
  ```
320
752
 
321
753
  - 2625a04: feat(openai); update spec for mcp approval
@@ -530,13 +962,13 @@
530
962
  Before
531
963
 
532
964
  ```ts
533
- model.textEmbeddingModel('my-model-id');
965
+ model.textEmbeddingModel("my-model-id");
534
966
  ```
535
967
 
536
968
  After
537
969
 
538
970
  ```ts
539
- model.embeddingModel('my-model-id');
971
+ model.embeddingModel("my-model-id");
540
972
  ```
541
973
 
542
974
  - Updated dependencies [8d9e8ad]
@@ -972,7 +1404,7 @@
972
1404
 
973
1405
  ```js
974
1406
  await generateImage({
975
- model: luma.image('photon-flash-1', {
1407
+ model: luma.image("photon-flash-1", {
976
1408
  maxImagesPerCall: 5,
977
1409
  pollIntervalMillis: 500,
978
1410
  }),
@@ -985,7 +1417,7 @@
985
1417
 
986
1418
  ```js
987
1419
  await generateImage({
988
- model: luma.image('photon-flash-1'),
1420
+ model: luma.image("photon-flash-1"),
989
1421
  prompt,
990
1422
  n: 10,
991
1423
  maxImagesPerCall: 5,
@@ -1254,7 +1686,7 @@
1254
1686
 
1255
1687
  ```js
1256
1688
  await generateImage({
1257
- model: luma.image('photon-flash-1', {
1689
+ model: luma.image("photon-flash-1", {
1258
1690
  maxImagesPerCall: 5,
1259
1691
  pollIntervalMillis: 500,
1260
1692
  }),
@@ -1267,7 +1699,7 @@
1267
1699
 
1268
1700
  ```js
1269
1701
  await generateImage({
1270
- model: luma.image('photon-flash-1'),
1702
+ model: luma.image("photon-flash-1"),
1271
1703
  prompt,
1272
1704
  n: 10,
1273
1705
  maxImagesPerCall: 5,
package/README.md CHANGED
@@ -4,6 +4,8 @@ This package provides a foundation for implementing providers that expose an Ope
4
4
 
5
5
  The primary [OpenAI provider](../openai/README.md) is more feature-rich, including OpenAI-specific experimental and legacy features. This package offers a lighter-weight alternative focused on core OpenAI-compatible functionality.
6
6
 
7
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access hundreds of models from any provider — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
8
+
7
9
  ## Setup
8
10
 
9
11
  The provider is available in the `@ai-sdk/openai-compatible` module. You can install it with
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { SharedV4ProviderMetadata, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, EmbeddingModelV4, ImageModelV4, ProviderV4 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { SharedV4ProviderMetadata, LanguageModelV4, LanguageModelV4Usage, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, EmbeddingModelV4, ImageModelV4, ProviderV4 } from '@ai-sdk/provider';
3
+ import { FetchFunction, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
3
4
  import { ZodType, z } from 'zod/v4';
4
5
 
5
6
  declare const openaiCompatibleErrorDataSchema: z.ZodObject<{
@@ -71,7 +72,7 @@ type MetadataExtractor = {
71
72
 
72
73
  type OpenAICompatibleChatConfig = {
73
74
  provider: string;
74
- headers: () => Record<string, string | undefined>;
75
+ headers?: () => Record<string, string | undefined>;
75
76
  url: (options: {
76
77
  modelId: string;
77
78
  path: string;
@@ -94,23 +95,50 @@ type OpenAICompatibleChatConfig = {
94
95
  * than the official OpenAI API.
95
96
  */
96
97
  transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
98
+ /**
99
+ * Optional usage converter for OpenAI-compatible providers with different
100
+ * token accounting semantics.
101
+ */
102
+ convertUsage?: (usage: z.infer<typeof openaiCompatibleTokenUsageSchema>) => LanguageModelV4Usage;
97
103
  };
98
104
  declare class OpenAICompatibleChatLanguageModel implements LanguageModelV4 {
99
105
  readonly specificationVersion = "v4";
100
106
  readonly supportsStructuredOutputs: boolean;
101
107
  readonly modelId: OpenAICompatibleChatModelId;
102
- private readonly config;
108
+ protected readonly config: OpenAICompatibleChatConfig;
103
109
  private readonly failedResponseHandler;
104
110
  private readonly chunkSchema;
111
+ static [WORKFLOW_SERIALIZE](model: OpenAICompatibleChatLanguageModel): {
112
+ modelId: string;
113
+ config: _ai_sdk_provider.JSONObject;
114
+ };
115
+ static [WORKFLOW_DESERIALIZE](options: {
116
+ modelId: string;
117
+ config: OpenAICompatibleChatConfig;
118
+ }): OpenAICompatibleChatLanguageModel;
105
119
  constructor(modelId: OpenAICompatibleChatModelId, config: OpenAICompatibleChatConfig);
106
120
  get provider(): string;
107
121
  private get providerOptionsName();
108
122
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
109
123
  private transformRequestBody;
124
+ private convertUsage;
110
125
  private getArgs;
111
126
  doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
112
127
  doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
113
128
  }
129
+ declare const openaiCompatibleTokenUsageSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
130
+ prompt_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
131
+ completion_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
132
+ total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
133
+ prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
134
+ cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
135
+ }, z.core.$strip>>>;
136
+ completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
137
+ reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
138
+ accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
139
+ rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
140
+ }, z.core.$strip>>>;
141
+ }, z.core.$loose>>>;
114
142
 
115
143
  type OpenAICompatibleCompletionModelId = string;
116
144
  declare const openaiCompatibleLanguageModelCompletionOptions: z.ZodObject<{
@@ -124,7 +152,7 @@ type OpenAICompatibleLanguageModelCompletionOptions = z.infer<typeof openaiCompa
124
152
  type OpenAICompatibleCompletionConfig = {
125
153
  provider: string;
126
154
  includeUsage?: boolean;
127
- headers: () => Record<string, string | undefined>;
155
+ headers?: () => Record<string, string | undefined>;
128
156
  url: (options: {
129
157
  modelId: string;
130
158
  path: string;
@@ -142,6 +170,14 @@ declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV4
142
170
  private readonly config;
143
171
  private readonly failedResponseHandler;
144
172
  private readonly chunkSchema;
173
+ static [WORKFLOW_SERIALIZE](model: OpenAICompatibleCompletionLanguageModel): {
174
+ modelId: string;
175
+ config: _ai_sdk_provider.JSONObject;
176
+ };
177
+ static [WORKFLOW_DESERIALIZE](options: {
178
+ modelId: string;
179
+ config: OpenAICompatibleCompletionConfig;
180
+ }): OpenAICompatibleCompletionLanguageModel;
145
181
  constructor(modelId: OpenAICompatibleCompletionModelId, config: OpenAICompatibleCompletionConfig);
146
182
  get provider(): string;
147
183
  private get providerOptionsName();
@@ -172,7 +208,7 @@ type OpenAICompatibleEmbeddingConfig = {
172
208
  modelId: string;
173
209
  path: string;
174
210
  }) => string;
175
- headers: () => Record<string, string | undefined>;
211
+ headers?: () => Record<string, string | undefined>;
176
212
  fetch?: FetchFunction;
177
213
  errorStructure?: ProviderErrorStructure<any>;
178
214
  };
@@ -183,6 +219,14 @@ declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV4 {
183
219
  get provider(): string;
184
220
  get maxEmbeddingsPerCall(): number;
185
221
  get supportsParallelCalls(): boolean;
222
+ static [WORKFLOW_SERIALIZE](model: OpenAICompatibleEmbeddingModel): {
223
+ modelId: string;
224
+ config: _ai_sdk_provider.JSONObject;
225
+ };
226
+ static [WORKFLOW_DESERIALIZE](options: {
227
+ modelId: string;
228
+ config: OpenAICompatibleEmbeddingConfig;
229
+ }): OpenAICompatibleEmbeddingModel;
186
230
  constructor(modelId: OpenAICompatibleEmbeddingModelId, config: OpenAICompatibleEmbeddingConfig);
187
231
  private get providerOptionsName();
188
232
  doEmbed({ values, headers, abortSignal, providerOptions, }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>>;
@@ -192,7 +236,7 @@ type OpenAICompatibleImageModelId = string;
192
236
 
193
237
  type OpenAICompatibleImageModelConfig = {
194
238
  provider: string;
195
- headers: () => Record<string, string | undefined>;
239
+ headers?: () => Record<string, string | undefined>;
196
240
  url: (options: {
197
241
  modelId: string;
198
242
  path: string;
@@ -213,12 +257,20 @@ declare class OpenAICompatibleImageModel implements ImageModelV4 {
213
257
  * The provider options key used to extract provider-specific options.
214
258
  */
215
259
  private get providerOptionsKey();
260
+ static [WORKFLOW_SERIALIZE](model: OpenAICompatibleImageModel): {
261
+ modelId: string;
262
+ config: _ai_sdk_provider.JSONObject;
263
+ };
264
+ static [WORKFLOW_DESERIALIZE](options: {
265
+ modelId: string;
266
+ config: OpenAICompatibleImageModelConfig;
267
+ }): OpenAICompatibleImageModel;
216
268
  constructor(modelId: OpenAICompatibleImageModelId, config: OpenAICompatibleImageModelConfig);
217
269
  private getArgs;
218
270
  doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
219
271
  }
220
272
 
221
- interface OpenAICompatibleProvider<CHAT_MODEL_IDS extends string = string, COMPLETION_MODEL_IDS extends string = string, EMBEDDING_MODEL_IDS extends string = string, IMAGE_MODEL_IDS extends string = string> extends Omit<ProviderV4, 'imageModel'> {
273
+ interface OpenAICompatibleProvider<CHAT_MODEL_IDS extends string = string, COMPLETION_MODEL_IDS extends string = string, EMBEDDING_MODEL_IDS extends string = string, IMAGE_MODEL_IDS extends string = string> extends ProviderV4 {
222
274
  (modelId: CHAT_MODEL_IDS): LanguageModelV4;
223
275
  languageModel(modelId: CHAT_MODEL_IDS, config?: Partial<OpenAICompatibleChatConfig>): LanguageModelV4;
224
276
  chatModel(modelId: CHAT_MODEL_IDS): LanguageModelV4;
@@ -279,6 +331,15 @@ interface OpenAICompatibleProviderSettings {
279
331
  * or provider-specific metrics from both streaming and non-streaming responses.
280
332
  */
281
333
  metadataExtractor?: MetadataExtractor;
334
+ /**
335
+ * The supported URLs for chat models.
336
+ */
337
+ supportedUrls?: OpenAICompatibleChatConfig['supportedUrls'];
338
+ /**
339
+ * Optional usage converter for providers with token accounting semantics that
340
+ * differ from the default OpenAI-compatible shape.
341
+ */
342
+ convertUsage?: OpenAICompatibleChatConfig['convertUsage'];
282
343
  }
283
344
  /**
284
345
  * Create an OpenAICompatible provider instance.