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

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 +432 -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,429 @@
1
1
  # @ai-sdk/openai-compatible
2
2
 
3
+ ## 3.0.0-beta.57
4
+
5
+ ### Patch Changes
6
+
7
+ - b8396f0: trigger initial beta release
8
+ - Updated dependencies [b8396f0]
9
+ - @ai-sdk/provider-utils@5.0.0-beta.49
10
+ - @ai-sdk/provider@4.0.0-beta.19
11
+
12
+ ## 3.0.0-canary.56
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [aeda373]
17
+ - Updated dependencies [375fdd7]
18
+ - Updated dependencies [b4507d5]
19
+ - @ai-sdk/provider-utils@5.0.0-canary.48
20
+
21
+ ## 3.0.0-canary.55
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [bae5e2b]
26
+ - @ai-sdk/provider-utils@5.0.0-canary.47
27
+
28
+ ## 3.0.0-canary.54
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [ce769dd]
33
+ - @ai-sdk/provider@4.0.0-canary.18
34
+ - @ai-sdk/provider-utils@5.0.0-canary.46
35
+
36
+ ## 3.0.0-canary.53
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [ee798eb]
41
+ - Updated dependencies [daf6637]
42
+ - @ai-sdk/provider-utils@5.0.0-canary.45
43
+
44
+ ## 3.0.0-canary.52
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [6c93e36]
49
+ - Updated dependencies [f617ac2]
50
+ - @ai-sdk/provider-utils@5.0.0-canary.44
51
+
52
+ ## 3.0.0-canary.51
53
+
54
+ ### Patch Changes
55
+
56
+ - 9f1e1ba: fix: accept empty string `role` in streaming delta chunks from OpenAI-compatible providers
57
+
58
+ ## 3.0.0-canary.50
59
+
60
+ ### Patch Changes
61
+
62
+ - 7fc6bd6: Raise minimum supported Node.js version to 22. Supported versions: 22, 24, and 26.
63
+ - Updated dependencies [7fc6bd6]
64
+ - @ai-sdk/provider-utils@5.0.0-canary.43
65
+ - @ai-sdk/provider@4.0.0-canary.17
66
+
67
+ ## 3.0.0-canary.49
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies [a6617c5]
72
+ - @ai-sdk/provider-utils@5.0.0-canary.42
73
+
74
+ ## 3.0.0-canary.48
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [28dfa06]
79
+ - Updated dependencies [e93fa91]
80
+ - @ai-sdk/provider-utils@5.0.0-canary.41
81
+
82
+ ## 3.0.0-canary.47
83
+
84
+ ### Patch Changes
85
+
86
+ - Updated dependencies [a7de9c9]
87
+ - @ai-sdk/provider-utils@5.0.0-canary.40
88
+
89
+ ## 3.0.0-canary.46
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [105f95b]
94
+ - @ai-sdk/provider-utils@5.0.0-canary.39
95
+
96
+ ## 3.0.0-canary.45
97
+
98
+ ### Patch Changes
99
+
100
+ - Updated dependencies [ca446f8]
101
+ - @ai-sdk/provider-utils@5.0.0-canary.38
102
+
103
+ ## 3.0.0-canary.44
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [d848405]
108
+ - @ai-sdk/provider-utils@5.0.0-canary.37
109
+
110
+ ## 3.0.0-canary.43
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies [ca39020]
115
+ - @ai-sdk/provider-utils@5.0.0-canary.36
116
+
117
+ ## 3.0.0-canary.42
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [f634bac]
122
+ - @ai-sdk/provider-utils@5.0.0-canary.35
123
+
124
+ ## 3.0.0-canary.41
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies [69254e0]
129
+ - Updated dependencies [3015fc3]
130
+ - @ai-sdk/provider-utils@5.0.0-canary.34
131
+
132
+ ## 3.0.0-canary.40
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [2427d88]
137
+ - @ai-sdk/provider-utils@5.0.0-canary.33
138
+
139
+ ## 3.0.0-canary.39
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [5463d0d]
144
+ - @ai-sdk/provider-utils@5.0.0-canary.32
145
+ - @ai-sdk/provider@4.0.0-canary.16
146
+
147
+ ## 3.0.0-canary.38
148
+
149
+ ### Patch Changes
150
+
151
+ - cd9c311: fix(openai, openai-compatible): only send null content for assistant messages with tool calls
152
+
153
+ ## 3.0.0-canary.37
154
+
155
+ ### Patch Changes
156
+
157
+ - 0c4c275: trigger initial canary release
158
+ - Updated dependencies [0c4c275]
159
+ - @ai-sdk/provider-utils@5.0.0-canary.31
160
+ - @ai-sdk/provider@4.0.0-canary.15
161
+
162
+ ## 3.0.0-beta.36
163
+
164
+ ### Patch Changes
165
+
166
+ - e59c955: feat(vertex): add grok models to vertex provider
167
+
168
+ ## 3.0.0-beta.35
169
+
170
+ ### Major Changes
171
+
172
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
173
+
174
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
175
+
176
+ ### Patch Changes
177
+
178
+ - Updated dependencies [08d2129]
179
+ - @ai-sdk/provider-utils@5.0.0-beta.30
180
+
181
+ ## 3.0.0-beta.34
182
+
183
+ ### Patch Changes
184
+
185
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
186
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
187
+ - Updated dependencies [9bd6512]
188
+ - Updated dependencies [258c093]
189
+ - Updated dependencies [b6783da]
190
+ - @ai-sdk/provider-utils@5.0.0-beta.29
191
+ - @ai-sdk/provider@4.0.0-beta.14
192
+
193
+ ## 3.0.0-beta.33
194
+
195
+ ### Patch Changes
196
+
197
+ - 9f0e36c: trigger release for all packages after provenance setup
198
+ - Updated dependencies [9f0e36c]
199
+ - @ai-sdk/provider@4.0.0-beta.13
200
+ - @ai-sdk/provider-utils@5.0.0-beta.28
201
+
202
+ ## 3.0.0-beta.32
203
+
204
+ ### Patch Changes
205
+
206
+ - ab81968: fix(openai-compatible): buffer tool call deltas until function.name arrives
207
+ - 58a2ad7: fix: more precise default message for tool execution denial
208
+ - Updated dependencies [785fe16]
209
+ - Updated dependencies [67df0a0]
210
+ - Updated dependencies [befb78c]
211
+ - Updated dependencies [0458559]
212
+ - Updated dependencies [5852c0a]
213
+ - Updated dependencies [fc92055]
214
+ - @ai-sdk/provider-utils@5.0.0-beta.27
215
+
216
+ ## 3.0.0-beta.31
217
+
218
+ ### Patch Changes
219
+
220
+ - bfb756d: patch - send content: null instead of empty string for tool-only assistant messages
221
+ - Updated dependencies [2e98477]
222
+ - @ai-sdk/provider-utils@5.0.0-beta.26
223
+
224
+ ## 3.0.0-beta.30
225
+
226
+ ### Patch Changes
227
+
228
+ - Updated dependencies [eea8d98]
229
+ - @ai-sdk/provider-utils@5.0.0-beta.25
230
+
231
+ ## 3.0.0-beta.29
232
+
233
+ ### Patch Changes
234
+
235
+ - 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.
236
+ - Updated dependencies [f807e45]
237
+ - @ai-sdk/provider-utils@5.0.0-beta.24
238
+
239
+ ## 3.0.0-beta.28
240
+
241
+ ### Patch Changes
242
+
243
+ - Updated dependencies [350ea38]
244
+ - @ai-sdk/provider-utils@5.0.0-beta.23
245
+
246
+ ## 3.0.0-beta.27
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies [083947b]
251
+ - @ai-sdk/provider-utils@5.0.0-beta.22
252
+
253
+ ## 3.0.0-beta.26
254
+
255
+ ### Patch Changes
256
+
257
+ - Updated dependencies [add1126]
258
+ - @ai-sdk/provider-utils@5.0.0-beta.21
259
+
260
+ ## 3.0.0-beta.25
261
+
262
+ ### Patch Changes
263
+
264
+ - b3976a2: Add workflow serialization support to all provider models.
265
+
266
+ **`@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.
267
+
268
+ **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.
269
+
270
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
271
+
272
+ - Updated dependencies [b3976a2]
273
+ - Updated dependencies [ff5eba1]
274
+ - @ai-sdk/provider-utils@5.0.0-beta.20
275
+ - @ai-sdk/provider@4.0.0-beta.12
276
+
277
+ ## 3.0.0-beta.24
278
+
279
+ ### Major Changes
280
+
281
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
282
+
283
+ ### Patch Changes
284
+
285
+ - Updated dependencies [ef992f8]
286
+ - @ai-sdk/provider@4.0.0-beta.11
287
+ - @ai-sdk/provider-utils@5.0.0-beta.19
288
+
289
+ ## 3.0.0-beta.23
290
+
291
+ ### Patch Changes
292
+
293
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
294
+ - Updated dependencies [90e2d8a]
295
+ - @ai-sdk/provider-utils@5.0.0-beta.18
296
+
297
+ ## 3.0.0-beta.22
298
+
299
+ ### Patch Changes
300
+
301
+ - Updated dependencies [3ae1786]
302
+ - @ai-sdk/provider-utils@5.0.0-beta.17
303
+
304
+ ## 3.0.0-beta.21
305
+
306
+ ### Patch Changes
307
+
308
+ - Updated dependencies [176466a]
309
+ - @ai-sdk/provider@4.0.0-beta.10
310
+ - @ai-sdk/provider-utils@5.0.0-beta.16
311
+
312
+ ## 3.0.0-beta.20
313
+
314
+ ### Patch Changes
315
+
316
+ - Updated dependencies [e311194]
317
+ - @ai-sdk/provider@4.0.0-beta.9
318
+ - @ai-sdk/provider-utils@5.0.0-beta.15
319
+
320
+ ## 3.0.0-beta.19
321
+
322
+ ### Patch Changes
323
+
324
+ - 008271d: feat(openai-compatible): emit warning when using kebab-case instead of camelCase
325
+ - Updated dependencies [34bd95d]
326
+ - Updated dependencies [008271d]
327
+ - @ai-sdk/provider@4.0.0-beta.8
328
+ - @ai-sdk/provider-utils@5.0.0-beta.14
329
+
330
+ ## 3.0.0-beta.18
331
+
332
+ ### Patch Changes
333
+
334
+ - Updated dependencies [b0c2869]
335
+ - Updated dependencies [7e26e81]
336
+ - @ai-sdk/provider-utils@5.0.0-beta.13
337
+
338
+ ## 3.0.0-beta.17
339
+
340
+ ### Patch Changes
341
+
342
+ - 816ff67: fix(openai-compatible): honor camelCase providerOptions key in chat and completion models
343
+
344
+ ## 3.0.0-beta.16
345
+
346
+ ### Patch Changes
347
+
348
+ - Updated dependencies [46d1149]
349
+ - @ai-sdk/provider-utils@5.0.0-beta.12
350
+
351
+ ## 3.0.0-beta.15
352
+
353
+ ### Patch Changes
354
+
355
+ - 6fd51c0: fix(provider): preserve error type prefix in getErrorMessage
356
+ - Updated dependencies [6fd51c0]
357
+ - @ai-sdk/provider-utils@5.0.0-beta.11
358
+ - @ai-sdk/provider@4.0.0-beta.7
359
+
360
+ ## 3.0.0-beta.14
361
+
362
+ ### Patch Changes
363
+
364
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
365
+ - Updated dependencies [c29a26f]
366
+ - @ai-sdk/provider-utils@5.0.0-beta.10
367
+ - @ai-sdk/provider@4.0.0-beta.6
368
+
369
+ ## 3.0.0-beta.13
370
+
371
+ ### Patch Changes
372
+
373
+ - 38fc777: Add AI Gateway hint to provider READMEs
374
+
375
+ ## 3.0.0-beta.12
376
+
377
+ ### Patch Changes
378
+
379
+ - Updated dependencies [2e17091]
380
+ - @ai-sdk/provider-utils@5.0.0-beta.9
381
+
382
+ ## 3.0.0-beta.11
383
+
384
+ ### Patch Changes
385
+
386
+ - Updated dependencies [986c6fd]
387
+ - Updated dependencies [493295c]
388
+ - @ai-sdk/provider-utils@5.0.0-beta.8
389
+
390
+ ## 3.0.0-beta.10
391
+
392
+ ### Patch Changes
393
+
394
+ - Updated dependencies [1f509d4]
395
+ - @ai-sdk/provider-utils@5.0.0-beta.7
396
+ - @ai-sdk/provider@4.0.0-beta.5
397
+
398
+ ## 3.0.0-beta.9
399
+
400
+ ### Patch Changes
401
+
402
+ - 74d520f: feat: migrate providers to support new top-level `reasoning` parameter
403
+
404
+ ## 3.0.0-beta.8
405
+
406
+ ### Patch Changes
407
+
408
+ - Updated dependencies [3887c70]
409
+ - @ai-sdk/provider-utils@5.0.0-beta.6
410
+ - @ai-sdk/provider@4.0.0-beta.4
411
+
412
+ ## 3.0.0-beta.7
413
+
414
+ ### Patch Changes
415
+
416
+ - Updated dependencies [776b617]
417
+ - @ai-sdk/provider-utils@5.0.0-beta.5
418
+ - @ai-sdk/provider@4.0.0-beta.3
419
+
420
+ ## 3.0.0-beta.6
421
+
422
+ ### Patch Changes
423
+
424
+ - Updated dependencies [61753c3]
425
+ - @ai-sdk/provider-utils@5.0.0-beta.4
426
+
3
427
  ## 3.0.0-beta.5
4
428
 
5
429
  ### Patch Changes
@@ -309,13 +733,13 @@
309
733
  Before
310
734
 
311
735
  ```ts
312
- model.textEmbeddingModel('my-model-id');
736
+ model.textEmbeddingModel("my-model-id");
313
737
  ```
314
738
 
315
739
  After
316
740
 
317
741
  ```ts
318
- model.embeddingModel('my-model-id');
742
+ model.embeddingModel("my-model-id");
319
743
  ```
320
744
 
321
745
  - 2625a04: feat(openai); update spec for mcp approval
@@ -530,13 +954,13 @@
530
954
  Before
531
955
 
532
956
  ```ts
533
- model.textEmbeddingModel('my-model-id');
957
+ model.textEmbeddingModel("my-model-id");
534
958
  ```
535
959
 
536
960
  After
537
961
 
538
962
  ```ts
539
- model.embeddingModel('my-model-id');
963
+ model.embeddingModel("my-model-id");
540
964
  ```
541
965
 
542
966
  - Updated dependencies [8d9e8ad]
@@ -972,7 +1396,7 @@
972
1396
 
973
1397
  ```js
974
1398
  await generateImage({
975
- model: luma.image('photon-flash-1', {
1399
+ model: luma.image("photon-flash-1", {
976
1400
  maxImagesPerCall: 5,
977
1401
  pollIntervalMillis: 500,
978
1402
  }),
@@ -985,7 +1409,7 @@
985
1409
 
986
1410
  ```js
987
1411
  await generateImage({
988
- model: luma.image('photon-flash-1'),
1412
+ model: luma.image("photon-flash-1"),
989
1413
  prompt,
990
1414
  n: 10,
991
1415
  maxImagesPerCall: 5,
@@ -1254,7 +1678,7 @@
1254
1678
 
1255
1679
  ```js
1256
1680
  await generateImage({
1257
- model: luma.image('photon-flash-1', {
1681
+ model: luma.image("photon-flash-1", {
1258
1682
  maxImagesPerCall: 5,
1259
1683
  pollIntervalMillis: 500,
1260
1684
  }),
@@ -1267,7 +1691,7 @@
1267
1691
 
1268
1692
  ```js
1269
1693
  await generateImage({
1270
- model: luma.image('photon-flash-1'),
1694
+ model: luma.image("photon-flash-1"),
1271
1695
  prompt,
1272
1696
  n: 10,
1273
1697
  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.