@llmgateway/ai-sdk-provider 3.4.0 → 3.6.0

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/README.md CHANGED
@@ -13,12 +13,12 @@ The [LLMGateway](https://llmgateway.io/) provider for the [Vercel AI SDK](https:
13
13
  ## Setup
14
14
 
15
15
  ```bash
16
- # For pnpm
17
- pnpm add @llmgateway/ai-sdk-provider
18
-
19
16
  # For npm
20
17
  npm install @llmgateway/ai-sdk-provider
21
18
 
19
+ # For pnpm
20
+ pnpm add @llmgateway/ai-sdk-provider
21
+
22
22
  # For yarn
23
23
  yarn add @llmgateway/ai-sdk-provider
24
24
  ```
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
2
- export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
2
+ export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
3
  import { models, Provider } from '@llmgateway/models';
4
4
 
5
5
  type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
@@ -146,45 +146,17 @@ type LLMGatewayChatConfig = {
146
146
  fetch?: typeof fetch;
147
147
  extraBody?: Record<string, unknown>;
148
148
  };
149
- declare class LLMGatewayChatLanguageModel implements LanguageModelV2 {
150
- readonly specificationVersion: "v2";
149
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
150
+ readonly specificationVersion: "v3";
151
151
  readonly provider = "llmgateway";
152
- readonly defaultObjectGenerationMode: "tool";
153
152
  readonly modelId: LLMGatewayChatModelId;
154
153
  readonly supportedUrls: Record<string, RegExp[]>;
155
154
  readonly settings: LLMGatewayChatSettings;
156
155
  private readonly config;
157
156
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
158
157
  private getArgs;
159
- doGenerate(options: LanguageModelV2CallOptions): Promise<{
160
- content: Array<LanguageModelV2Content>;
161
- finishReason: LanguageModelV2FinishReason;
162
- usage: LanguageModelV2Usage;
163
- warnings: Array<LanguageModelV2CallWarning>;
164
- providerMetadata?: {
165
- llmgateway: {
166
- usage: LLMGatewayUsageAccounting;
167
- };
168
- };
169
- request?: {
170
- body?: unknown;
171
- };
172
- response?: LanguageModelV2ResponseMetadata & {
173
- headers?: SharedV2Headers;
174
- body?: unknown;
175
- };
176
- }>;
177
- doStream(options: LanguageModelV2CallOptions): Promise<{
178
- stream: ReadableStream<LanguageModelV2StreamPart>;
179
- warnings: Array<LanguageModelV2CallWarning>;
180
- request?: {
181
- body?: unknown;
182
- };
183
- response?: LanguageModelV2ResponseMetadata & {
184
- headers?: SharedV2Headers;
185
- body?: unknown;
186
- };
187
- }>;
158
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
159
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
188
160
  }
189
161
 
190
162
  type LLMGatewayCompletionConfig = {
@@ -198,18 +170,17 @@ type LLMGatewayCompletionConfig = {
198
170
  fetch?: typeof fetch;
199
171
  extraBody?: Record<string, unknown>;
200
172
  };
201
- declare class LLMGatewayCompletionLanguageModel implements LanguageModelV2 {
202
- readonly specificationVersion: "v2";
173
+ declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
174
+ readonly specificationVersion: "v3";
203
175
  readonly provider = "llmgateway";
204
176
  readonly modelId: LLMGatewayChatModelId;
205
177
  readonly supportedUrls: Record<string, RegExp[]>;
206
- readonly defaultObjectGenerationMode: undefined;
207
178
  readonly settings: LLMGatewayCompletionSettings;
208
179
  private readonly config;
209
180
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
210
181
  private getArgs;
211
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
212
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
182
+ doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
183
+ doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
213
184
  }
214
185
 
215
186
  type LLMGatewayImageConfig = {
@@ -240,7 +211,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
240
211
  }>;
241
212
  }
242
213
 
243
- interface LLMGatewayProvider extends LanguageModelV2 {
214
+ interface LLMGatewayProvider {
244
215
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
245
216
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
246
217
  languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
2
- export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
2
+ export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
3
  import { models, Provider } from '@llmgateway/models';
4
4
 
5
5
  type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
@@ -146,45 +146,17 @@ type LLMGatewayChatConfig = {
146
146
  fetch?: typeof fetch;
147
147
  extraBody?: Record<string, unknown>;
148
148
  };
149
- declare class LLMGatewayChatLanguageModel implements LanguageModelV2 {
150
- readonly specificationVersion: "v2";
149
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
150
+ readonly specificationVersion: "v3";
151
151
  readonly provider = "llmgateway";
152
- readonly defaultObjectGenerationMode: "tool";
153
152
  readonly modelId: LLMGatewayChatModelId;
154
153
  readonly supportedUrls: Record<string, RegExp[]>;
155
154
  readonly settings: LLMGatewayChatSettings;
156
155
  private readonly config;
157
156
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
158
157
  private getArgs;
159
- doGenerate(options: LanguageModelV2CallOptions): Promise<{
160
- content: Array<LanguageModelV2Content>;
161
- finishReason: LanguageModelV2FinishReason;
162
- usage: LanguageModelV2Usage;
163
- warnings: Array<LanguageModelV2CallWarning>;
164
- providerMetadata?: {
165
- llmgateway: {
166
- usage: LLMGatewayUsageAccounting;
167
- };
168
- };
169
- request?: {
170
- body?: unknown;
171
- };
172
- response?: LanguageModelV2ResponseMetadata & {
173
- headers?: SharedV2Headers;
174
- body?: unknown;
175
- };
176
- }>;
177
- doStream(options: LanguageModelV2CallOptions): Promise<{
178
- stream: ReadableStream<LanguageModelV2StreamPart>;
179
- warnings: Array<LanguageModelV2CallWarning>;
180
- request?: {
181
- body?: unknown;
182
- };
183
- response?: LanguageModelV2ResponseMetadata & {
184
- headers?: SharedV2Headers;
185
- body?: unknown;
186
- };
187
- }>;
158
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
159
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
188
160
  }
189
161
 
190
162
  type LLMGatewayCompletionConfig = {
@@ -198,18 +170,17 @@ type LLMGatewayCompletionConfig = {
198
170
  fetch?: typeof fetch;
199
171
  extraBody?: Record<string, unknown>;
200
172
  };
201
- declare class LLMGatewayCompletionLanguageModel implements LanguageModelV2 {
202
- readonly specificationVersion: "v2";
173
+ declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
174
+ readonly specificationVersion: "v3";
203
175
  readonly provider = "llmgateway";
204
176
  readonly modelId: LLMGatewayChatModelId;
205
177
  readonly supportedUrls: Record<string, RegExp[]>;
206
- readonly defaultObjectGenerationMode: undefined;
207
178
  readonly settings: LLMGatewayCompletionSettings;
208
179
  private readonly config;
209
180
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
210
181
  private getArgs;
211
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
212
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
182
+ doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
183
+ doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
213
184
  }
214
185
 
215
186
  type LLMGatewayImageConfig = {
@@ -240,7 +211,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
240
211
  }>;
241
212
  }
242
213
 
243
- interface LLMGatewayProvider extends LanguageModelV2 {
214
+ interface LLMGatewayProvider {
244
215
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
245
216
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
246
217
  languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
package/dist/index.js CHANGED
@@ -2252,16 +2252,16 @@ var llmgatewayFailedResponseHandler = createJsonErrorResponseHandler({
2252
2252
  function mapLLMGatewayFinishReason(finishReason) {
2253
2253
  switch (finishReason) {
2254
2254
  case "stop":
2255
- return "stop";
2255
+ return { unified: "stop", raw: finishReason };
2256
2256
  case "length":
2257
- return "length";
2257
+ return { unified: "length", raw: finishReason };
2258
2258
  case "content_filter":
2259
- return "content-filter";
2259
+ return { unified: "content-filter", raw: finishReason };
2260
2260
  case "function_call":
2261
2261
  case "tool_calls":
2262
- return "tool-calls";
2262
+ return { unified: "tool-calls", raw: finishReason };
2263
2263
  default:
2264
- return "unknown";
2264
+ return { unified: "other", raw: finishReason != null ? finishReason : void 0 };
2265
2265
  }
2266
2266
  }
2267
2267
 
@@ -2464,6 +2464,7 @@ function convertToLLMGatewayChatMessages(prompt) {
2464
2464
  }
2465
2465
  case "tool": {
2466
2466
  for (const toolResponse of content) {
2467
+ if (toolResponse.type !== "tool-result") continue;
2467
2468
  const content2 = getToolResultContent(toolResponse);
2468
2469
  messages.push({
2469
2470
  role: "tool",
@@ -2482,7 +2483,14 @@ function convertToLLMGatewayChatMessages(prompt) {
2482
2483
  return messages;
2483
2484
  }
2484
2485
  function getToolResultContent(input) {
2485
- return input.output.type === "text" ? input.output.value : JSON.stringify(input.output.value);
2486
+ switch (input.output.type) {
2487
+ case "text":
2488
+ return input.output.value;
2489
+ case "json":
2490
+ return JSON.stringify(input.output.value);
2491
+ default:
2492
+ return JSON.stringify(input.output);
2493
+ }
2486
2494
  }
2487
2495
 
2488
2496
  // src/chat/get-tool-choice.ts
@@ -2548,10 +2556,7 @@ var LLMGatewayChatCompletionBaseResponseSchema = import_v45.z.object({
2548
2556
  reasoning_tokens: import_v45.z.number()
2549
2557
  }).nullish(),
2550
2558
  total_tokens: import_v45.z.number(),
2551
- cost: import_v45.z.union([
2552
- import_v45.z.number(),
2553
- import_v45.z.object({ total_cost: import_v45.z.number() }).passthrough()
2554
- ]).optional(),
2559
+ cost: import_v45.z.union([import_v45.z.number(), import_v45.z.object({ total_cost: import_v45.z.number() }).passthrough()]).optional(),
2555
2560
  cost_details: import_v45.z.object({
2556
2561
  upstream_inference_cost: import_v45.z.number().nullish()
2557
2562
  }).nullish()
@@ -2655,9 +2660,8 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
2655
2660
  // src/chat/index.ts
2656
2661
  var LLMGatewayChatLanguageModel = class {
2657
2662
  constructor(modelId, settings, config) {
2658
- this.specificationVersion = "v2";
2663
+ this.specificationVersion = "v3";
2659
2664
  this.provider = "llmgateway";
2660
- this.defaultObjectGenerationMode = "tool";
2661
2665
  this.supportedUrls = {
2662
2666
  "image/*": [
2663
2667
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -2746,7 +2750,7 @@ var LLMGatewayChatLanguageModel = class {
2746
2750
  return baseArgs;
2747
2751
  }
2748
2752
  async doGenerate(options) {
2749
- var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
2753
+ var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
2750
2754
  const providerOptions = options.providerOptions || {};
2751
2755
  const llmgatewayOptions = providerOptions.llmgateway || {};
2752
2756
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
@@ -2770,19 +2774,31 @@ var LLMGatewayChatLanguageModel = class {
2770
2774
  throw new Error("No choice in response");
2771
2775
  }
2772
2776
  const usageInfo = response.usage ? {
2773
- inputTokens: (_b16 = response.usage.prompt_tokens) != null ? _b16 : 0,
2774
- outputTokens: (_c = response.usage.completion_tokens) != null ? _c : 0,
2775
- totalTokens: ((_d = response.usage.prompt_tokens) != null ? _d : 0) + ((_e = response.usage.completion_tokens) != null ? _e : 0),
2776
- reasoningTokens: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : 0,
2777
- cachedInputTokens: (_i = (_h = response.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
2777
+ inputTokens: {
2778
+ total: (_b16 = response.usage.prompt_tokens) != null ? _b16 : void 0,
2779
+ noCache: void 0,
2780
+ cacheRead: (_d = (_c = response.usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : void 0,
2781
+ cacheWrite: void 0
2782
+ },
2783
+ outputTokens: {
2784
+ total: (_e = response.usage.completion_tokens) != null ? _e : void 0,
2785
+ text: void 0,
2786
+ reasoning: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0
2787
+ }
2778
2788
  } : {
2779
- inputTokens: 0,
2780
- outputTokens: 0,
2781
- totalTokens: 0,
2782
- reasoningTokens: 0,
2783
- cachedInputTokens: 0
2789
+ inputTokens: {
2790
+ total: void 0,
2791
+ noCache: void 0,
2792
+ cacheRead: void 0,
2793
+ cacheWrite: void 0
2794
+ },
2795
+ outputTokens: {
2796
+ total: void 0,
2797
+ text: void 0,
2798
+ reasoning: void 0
2799
+ }
2784
2800
  };
2785
- const reasoningDetails = (_j = choice.message.reasoning_details) != null ? _j : [];
2801
+ const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
2786
2802
  const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
2787
2803
  switch (detail.type) {
2788
2804
  case "reasoning.text" /* Text */: {
@@ -2838,7 +2854,7 @@ var LLMGatewayChatLanguageModel = class {
2838
2854
  for (const toolCall of choice.message.tool_calls) {
2839
2855
  content.push({
2840
2856
  type: "tool-call",
2841
- toolCallId: (_k = toolCall.id) != null ? _k : generateId(),
2857
+ toolCallId: (_i = toolCall.id) != null ? _i : generateId(),
2842
2858
  toolName: toolCall.function.name,
2843
2859
  input: toolCall.function.arguments
2844
2860
  });
@@ -2879,18 +2895,18 @@ var LLMGatewayChatLanguageModel = class {
2879
2895
  providerMetadata: includeUsageAccounting ? {
2880
2896
  llmgateway: {
2881
2897
  usage: {
2882
- promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
2883
- completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
2884
- totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
2885
- cost: typeof ((_o = response.usage) == null ? void 0 : _o.cost) === "number" ? response.usage.cost : (_q = (_p = response.usage) == null ? void 0 : _p.cost) == null ? void 0 : _q.total_cost,
2898
+ promptTokens: (_j = usageInfo.inputTokens.total) != null ? _j : 0,
2899
+ completionTokens: (_k = usageInfo.outputTokens.total) != null ? _k : 0,
2900
+ totalTokens: ((_l = usageInfo.inputTokens.total) != null ? _l : 0) + ((_m = usageInfo.outputTokens.total) != null ? _m : 0),
2901
+ cost: typeof ((_n = response.usage) == null ? void 0 : _n.cost) === "number" ? response.usage.cost : (_p = (_o = response.usage) == null ? void 0 : _o.cost) == null ? void 0 : _p.total_cost,
2886
2902
  promptTokensDetails: {
2887
- cachedTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? _t : 0
2903
+ cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
2888
2904
  },
2889
2905
  completionTokensDetails: {
2890
- reasoningTokens: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.completion_tokens_details) == null ? void 0 : _v.reasoning_tokens) != null ? _w : 0
2906
+ reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
2891
2907
  },
2892
2908
  costDetails: {
2893
- upstreamInferenceCost: (_z = (_y = (_x = response.usage) == null ? void 0 : _x.cost_details) == null ? void 0 : _y.upstream_inference_cost) != null ? _z : 0
2909
+ upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
2894
2910
  }
2895
2911
  }
2896
2912
  }
@@ -2926,13 +2942,19 @@ var LLMGatewayChatLanguageModel = class {
2926
2942
  fetch: this.config.fetch
2927
2943
  });
2928
2944
  const toolCalls = [];
2929
- let finishReason = "other";
2945
+ let finishReason = { unified: "other", raw: void 0 };
2930
2946
  const usage = {
2931
- inputTokens: Number.NaN,
2932
- outputTokens: Number.NaN,
2933
- totalTokens: Number.NaN,
2934
- reasoningTokens: Number.NaN,
2935
- cachedInputTokens: Number.NaN
2947
+ inputTokens: {
2948
+ total: void 0,
2949
+ noCache: void 0,
2950
+ cacheRead: void 0,
2951
+ cacheWrite: void 0
2952
+ },
2953
+ outputTokens: {
2954
+ total: void 0,
2955
+ text: void 0,
2956
+ reasoning: void 0
2957
+ }
2936
2958
  };
2937
2959
  const llmgatewayUsage = {};
2938
2960
  let textStarted = false;
@@ -2946,13 +2968,13 @@ var LLMGatewayChatLanguageModel = class {
2946
2968
  transform(chunk, controller) {
2947
2969
  var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2948
2970
  if (!chunk.success) {
2949
- finishReason = "error";
2971
+ finishReason = { unified: "error", raw: void 0 };
2950
2972
  controller.enqueue({ type: "error", error: chunk.error });
2951
2973
  return;
2952
2974
  }
2953
2975
  const value = chunk.value;
2954
2976
  if ("error" in value) {
2955
- finishReason = "error";
2977
+ finishReason = { unified: "error", raw: void 0 };
2956
2978
  controller.enqueue({ type: "error", error: value.error });
2957
2979
  return;
2958
2980
  }
@@ -2970,13 +2992,12 @@ var LLMGatewayChatLanguageModel = class {
2970
2992
  });
2971
2993
  }
2972
2994
  if (value.usage != null) {
2973
- usage.inputTokens = value.usage.prompt_tokens;
2974
- usage.outputTokens = value.usage.completion_tokens;
2975
- usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
2995
+ usage.inputTokens.total = value.usage.prompt_tokens;
2996
+ usage.outputTokens.total = value.usage.completion_tokens;
2976
2997
  llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
2977
2998
  if (value.usage.prompt_tokens_details) {
2978
2999
  const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
2979
- usage.cachedInputTokens = cachedInputTokens;
3000
+ usage.inputTokens.cacheRead = cachedInputTokens;
2980
3001
  llmgatewayUsage.promptTokensDetails = {
2981
3002
  cachedTokens: cachedInputTokens
2982
3003
  };
@@ -2984,7 +3005,7 @@ var LLMGatewayChatLanguageModel = class {
2984
3005
  llmgatewayUsage.completionTokens = value.usage.completion_tokens;
2985
3006
  if (value.usage.completion_tokens_details) {
2986
3007
  const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
2987
- usage.reasoningTokens = reasoningTokens;
3008
+ usage.outputTokens.reasoning = reasoningTokens;
2988
3009
  llmgatewayUsage.completionTokensDetails = {
2989
3010
  reasoningTokens
2990
3011
  };
@@ -3167,7 +3188,7 @@ var LLMGatewayChatLanguageModel = class {
3167
3188
  },
3168
3189
  flush(controller) {
3169
3190
  var _a16;
3170
- if (finishReason === "tool-calls") {
3191
+ if (finishReason.unified === "tool-calls") {
3171
3192
  for (const toolCall of toolCalls) {
3172
3193
  if (toolCall && !toolCall.sent) {
3173
3194
  controller.enqueue({
@@ -3206,7 +3227,6 @@ var LLMGatewayChatLanguageModel = class {
3206
3227
  }
3207
3228
  })
3208
3229
  ),
3209
- warnings: [],
3210
3230
  request: { body: args },
3211
3231
  response: { headers: responseHeaders }
3212
3232
  };
@@ -3358,7 +3378,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
3358
3378
  // src/completion/index.ts
3359
3379
  var LLMGatewayCompletionLanguageModel = class {
3360
3380
  constructor(modelId, settings, config) {
3361
- this.specificationVersion = "v2";
3381
+ this.specificationVersion = "v3";
3362
3382
  this.provider = "llmgateway";
3363
3383
  this.supportedUrls = {
3364
3384
  "image/*": [
@@ -3368,7 +3388,6 @@ var LLMGatewayCompletionLanguageModel = class {
3368
3388
  "text/*": [/^data:text\//, /^https?:\/\/.+$/],
3369
3389
  "application/*": [/^data:application\//, /^https?:\/\/.+$/]
3370
3390
  };
3371
- this.defaultObjectGenerationMode = void 0;
3372
3391
  this.modelId = modelId;
3373
3392
  this.settings = settings;
3374
3393
  this.config = config;
@@ -3428,7 +3447,7 @@ var LLMGatewayCompletionLanguageModel = class {
3428
3447
  }, this.config.extraBody), this.settings.extraBody);
3429
3448
  }
3430
3449
  async doGenerate(options) {
3431
- var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
3450
+ var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3432
3451
  const providerOptions = options.providerOptions || {};
3433
3452
  const llmgatewayOptions = providerOptions.llmgateway || {};
3434
3453
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
@@ -3462,11 +3481,17 @@ var LLMGatewayCompletionLanguageModel = class {
3462
3481
  ],
3463
3482
  finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
3464
3483
  usage: {
3465
- inputTokens: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : 0,
3466
- outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
3467
- totalTokens: ((_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : 0) + ((_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : 0),
3468
- reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
3469
- cachedInputTokens: (_o = (_n = (_m = response.usage) == null ? void 0 : _m.prompt_tokens_details) == null ? void 0 : _n.cached_tokens) != null ? _o : 0
3484
+ inputTokens: {
3485
+ total: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : void 0,
3486
+ noCache: void 0,
3487
+ cacheRead: (_f = (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
3488
+ cacheWrite: void 0
3489
+ },
3490
+ outputTokens: {
3491
+ total: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
3492
+ text: void 0,
3493
+ reasoning: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
3494
+ }
3470
3495
  },
3471
3496
  warnings: [],
3472
3497
  response: {
@@ -3496,13 +3521,19 @@ var LLMGatewayCompletionLanguageModel = class {
3496
3521
  abortSignal: options.abortSignal,
3497
3522
  fetch: this.config.fetch
3498
3523
  });
3499
- let finishReason = "other";
3524
+ let finishReason = { unified: "other", raw: void 0 };
3500
3525
  const usage = {
3501
- inputTokens: Number.NaN,
3502
- outputTokens: Number.NaN,
3503
- totalTokens: Number.NaN,
3504
- reasoningTokens: Number.NaN,
3505
- cachedInputTokens: Number.NaN
3526
+ inputTokens: {
3527
+ total: void 0,
3528
+ noCache: void 0,
3529
+ cacheRead: void 0,
3530
+ cacheWrite: void 0
3531
+ },
3532
+ outputTokens: {
3533
+ total: void 0,
3534
+ text: void 0,
3535
+ reasoning: void 0
3536
+ }
3506
3537
  };
3507
3538
  const llmgatewayUsage = {};
3508
3539
  return {
@@ -3511,24 +3542,23 @@ var LLMGatewayCompletionLanguageModel = class {
3511
3542
  transform(chunk, controller) {
3512
3543
  var _a16, _b16, _c;
3513
3544
  if (!chunk.success) {
3514
- finishReason = "error";
3545
+ finishReason = { unified: "error", raw: void 0 };
3515
3546
  controller.enqueue({ type: "error", error: chunk.error });
3516
3547
  return;
3517
3548
  }
3518
3549
  const value = chunk.value;
3519
3550
  if ("error" in value) {
3520
- finishReason = "error";
3551
+ finishReason = { unified: "error", raw: void 0 };
3521
3552
  controller.enqueue({ type: "error", error: value.error });
3522
3553
  return;
3523
3554
  }
3524
3555
  if (value.usage != null) {
3525
- usage.inputTokens = value.usage.prompt_tokens;
3526
- usage.outputTokens = value.usage.completion_tokens;
3527
- usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
3556
+ usage.inputTokens.total = value.usage.prompt_tokens;
3557
+ usage.outputTokens.total = value.usage.completion_tokens;
3528
3558
  llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
3529
3559
  if (value.usage.prompt_tokens_details) {
3530
3560
  const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
3531
- usage.cachedInputTokens = cachedInputTokens;
3561
+ usage.inputTokens.cacheRead = cachedInputTokens;
3532
3562
  llmgatewayUsage.promptTokensDetails = {
3533
3563
  cachedTokens: cachedInputTokens
3534
3564
  };
@@ -3536,7 +3566,7 @@ var LLMGatewayCompletionLanguageModel = class {
3536
3566
  llmgatewayUsage.completionTokens = value.usage.completion_tokens;
3537
3567
  if (value.usage.completion_tokens_details) {
3538
3568
  const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
3539
- usage.reasoningTokens = reasoningTokens;
3569
+ usage.outputTokens.reasoning = reasoningTokens;
3540
3570
  llmgatewayUsage.completionTokensDetails = {
3541
3571
  reasoningTokens
3542
3572
  };
@@ -3646,12 +3676,24 @@ var LLMGatewayImageModel = class {
3646
3676
  feature: "seed"
3647
3677
  });
3648
3678
  }
3679
+ const hasFiles = options.files != null && options.files.length > 0;
3649
3680
  const body = {
3650
3681
  model: this.modelId,
3651
3682
  prompt: options.prompt,
3652
3683
  n: options.n,
3653
3684
  response_format: "b64_json"
3654
3685
  };
3686
+ if (hasFiles) {
3687
+ body.images = options.files.map((file) => {
3688
+ var _a16;
3689
+ if (file.type === "url") {
3690
+ return { image_url: file.url };
3691
+ }
3692
+ const base64 = typeof file.data === "string" ? file.data : Buffer.from(file.data).toString("base64");
3693
+ const mediaType = (_a16 = file.mediaType) != null ? _a16 : "image/png";
3694
+ return { image_url: `data:${mediaType};base64,${base64}` };
3695
+ });
3696
+ }
3655
3697
  if (options.size != null) {
3656
3698
  body.size = options.size;
3657
3699
  }
@@ -3660,7 +3702,7 @@ var LLMGatewayImageModel = class {
3660
3702
  }
3661
3703
  const { value: response, responseHeaders } = await postJsonToApi({
3662
3704
  url: this.config.url({
3663
- path: "/images/generations",
3705
+ path: hasFiles ? "/images/edits" : "/images/generations",
3664
3706
  modelId: this.modelId
3665
3707
  }),
3666
3708
  headers: combineHeaders(this.config.headers(), options.headers),