@llmgateway/ai-sdk-provider 3.5.0 → 3.7.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';
@@ -133,7 +133,9 @@ type LLMGatewayCompletionSettings = {
133
133
  } & LLMGatewaySharedSettings;
134
134
 
135
135
  type LLMGatewayImageModelId = string;
136
- type LLMGatewayImageSettings = {};
136
+ type LLMGatewayImageSettings = {
137
+ extraBody?: Record<string, unknown>;
138
+ };
137
139
 
138
140
  type LLMGatewayChatConfig = {
139
141
  provider: string;
@@ -146,45 +148,17 @@ type LLMGatewayChatConfig = {
146
148
  fetch?: typeof fetch;
147
149
  extraBody?: Record<string, unknown>;
148
150
  };
149
- declare class LLMGatewayChatLanguageModel implements LanguageModelV2 {
150
- readonly specificationVersion: "v2";
151
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
152
+ readonly specificationVersion: "v3";
151
153
  readonly provider = "llmgateway";
152
- readonly defaultObjectGenerationMode: "tool";
153
154
  readonly modelId: LLMGatewayChatModelId;
154
155
  readonly supportedUrls: Record<string, RegExp[]>;
155
156
  readonly settings: LLMGatewayChatSettings;
156
157
  private readonly config;
157
158
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
158
159
  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
- }>;
160
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
161
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
188
162
  }
189
163
 
190
164
  type LLMGatewayCompletionConfig = {
@@ -198,18 +172,17 @@ type LLMGatewayCompletionConfig = {
198
172
  fetch?: typeof fetch;
199
173
  extraBody?: Record<string, unknown>;
200
174
  };
201
- declare class LLMGatewayCompletionLanguageModel implements LanguageModelV2 {
202
- readonly specificationVersion: "v2";
175
+ declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
176
+ readonly specificationVersion: "v3";
203
177
  readonly provider = "llmgateway";
204
178
  readonly modelId: LLMGatewayChatModelId;
205
179
  readonly supportedUrls: Record<string, RegExp[]>;
206
- readonly defaultObjectGenerationMode: undefined;
207
180
  readonly settings: LLMGatewayCompletionSettings;
208
181
  private readonly config;
209
182
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
210
183
  private getArgs;
211
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
212
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
184
+ doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
185
+ doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
213
186
  }
214
187
 
215
188
  type LLMGatewayImageConfig = {
@@ -220,6 +193,10 @@ type LLMGatewayImageConfig = {
220
193
  path: string;
221
194
  }) => string;
222
195
  fetch?: typeof fetch;
196
+ extraBody?: Record<string, unknown>;
197
+ };
198
+ type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
199
+ quality?: string;
223
200
  };
224
201
  declare class LLMGatewayImageModel implements ImageModelV3 {
225
202
  readonly specificationVersion: "v3";
@@ -229,7 +206,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
229
206
  readonly settings: LLMGatewayImageSettings;
230
207
  private readonly config;
231
208
  constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
232
- doGenerate(options: ImageModelV3CallOptions): Promise<{
209
+ doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
233
210
  images: Array<string>;
234
211
  warnings: Array<SharedV3Warning>;
235
212
  response: {
@@ -240,7 +217,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
240
217
  }>;
241
218
  }
242
219
 
243
- interface LLMGatewayProvider extends LanguageModelV2 {
220
+ interface LLMGatewayProvider {
244
221
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
245
222
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
246
223
  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';
@@ -133,7 +133,9 @@ type LLMGatewayCompletionSettings = {
133
133
  } & LLMGatewaySharedSettings;
134
134
 
135
135
  type LLMGatewayImageModelId = string;
136
- type LLMGatewayImageSettings = {};
136
+ type LLMGatewayImageSettings = {
137
+ extraBody?: Record<string, unknown>;
138
+ };
137
139
 
138
140
  type LLMGatewayChatConfig = {
139
141
  provider: string;
@@ -146,45 +148,17 @@ type LLMGatewayChatConfig = {
146
148
  fetch?: typeof fetch;
147
149
  extraBody?: Record<string, unknown>;
148
150
  };
149
- declare class LLMGatewayChatLanguageModel implements LanguageModelV2 {
150
- readonly specificationVersion: "v2";
151
+ declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
152
+ readonly specificationVersion: "v3";
151
153
  readonly provider = "llmgateway";
152
- readonly defaultObjectGenerationMode: "tool";
153
154
  readonly modelId: LLMGatewayChatModelId;
154
155
  readonly supportedUrls: Record<string, RegExp[]>;
155
156
  readonly settings: LLMGatewayChatSettings;
156
157
  private readonly config;
157
158
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
158
159
  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
- }>;
160
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
161
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
188
162
  }
189
163
 
190
164
  type LLMGatewayCompletionConfig = {
@@ -198,18 +172,17 @@ type LLMGatewayCompletionConfig = {
198
172
  fetch?: typeof fetch;
199
173
  extraBody?: Record<string, unknown>;
200
174
  };
201
- declare class LLMGatewayCompletionLanguageModel implements LanguageModelV2 {
202
- readonly specificationVersion: "v2";
175
+ declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
176
+ readonly specificationVersion: "v3";
203
177
  readonly provider = "llmgateway";
204
178
  readonly modelId: LLMGatewayChatModelId;
205
179
  readonly supportedUrls: Record<string, RegExp[]>;
206
- readonly defaultObjectGenerationMode: undefined;
207
180
  readonly settings: LLMGatewayCompletionSettings;
208
181
  private readonly config;
209
182
  constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
210
183
  private getArgs;
211
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
212
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
184
+ doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
185
+ doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
213
186
  }
214
187
 
215
188
  type LLMGatewayImageConfig = {
@@ -220,6 +193,10 @@ type LLMGatewayImageConfig = {
220
193
  path: string;
221
194
  }) => string;
222
195
  fetch?: typeof fetch;
196
+ extraBody?: Record<string, unknown>;
197
+ };
198
+ type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
199
+ quality?: string;
223
200
  };
224
201
  declare class LLMGatewayImageModel implements ImageModelV3 {
225
202
  readonly specificationVersion: "v3";
@@ -229,7 +206,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
229
206
  readonly settings: LLMGatewayImageSettings;
230
207
  private readonly config;
231
208
  constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
232
- doGenerate(options: ImageModelV3CallOptions): Promise<{
209
+ doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
233
210
  images: Array<string>;
234
211
  warnings: Array<SharedV3Warning>;
235
212
  response: {
@@ -240,7 +217,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
240
217
  }>;
241
218
  }
242
219
 
243
- interface LLMGatewayProvider extends LanguageModelV2 {
220
+ interface LLMGatewayProvider {
244
221
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
245
222
  (modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
246
223
  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
@@ -2652,9 +2660,8 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
2652
2660
  // src/chat/index.ts
2653
2661
  var LLMGatewayChatLanguageModel = class {
2654
2662
  constructor(modelId, settings, config) {
2655
- this.specificationVersion = "v2";
2663
+ this.specificationVersion = "v3";
2656
2664
  this.provider = "llmgateway";
2657
- this.defaultObjectGenerationMode = "tool";
2658
2665
  this.supportedUrls = {
2659
2666
  "image/*": [
2660
2667
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -2743,7 +2750,7 @@ var LLMGatewayChatLanguageModel = class {
2743
2750
  return baseArgs;
2744
2751
  }
2745
2752
  async doGenerate(options) {
2746
- 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;
2747
2754
  const providerOptions = options.providerOptions || {};
2748
2755
  const llmgatewayOptions = providerOptions.llmgateway || {};
2749
2756
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
@@ -2767,19 +2774,31 @@ var LLMGatewayChatLanguageModel = class {
2767
2774
  throw new Error("No choice in response");
2768
2775
  }
2769
2776
  const usageInfo = response.usage ? {
2770
- inputTokens: (_b16 = response.usage.prompt_tokens) != null ? _b16 : 0,
2771
- outputTokens: (_c = response.usage.completion_tokens) != null ? _c : 0,
2772
- totalTokens: ((_d = response.usage.prompt_tokens) != null ? _d : 0) + ((_e = response.usage.completion_tokens) != null ? _e : 0),
2773
- reasoningTokens: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : 0,
2774
- 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
+ }
2775
2788
  } : {
2776
- inputTokens: 0,
2777
- outputTokens: 0,
2778
- totalTokens: 0,
2779
- reasoningTokens: 0,
2780
- 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
+ }
2781
2800
  };
2782
- const reasoningDetails = (_j = choice.message.reasoning_details) != null ? _j : [];
2801
+ const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
2783
2802
  const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
2784
2803
  switch (detail.type) {
2785
2804
  case "reasoning.text" /* Text */: {
@@ -2835,7 +2854,7 @@ var LLMGatewayChatLanguageModel = class {
2835
2854
  for (const toolCall of choice.message.tool_calls) {
2836
2855
  content.push({
2837
2856
  type: "tool-call",
2838
- toolCallId: (_k = toolCall.id) != null ? _k : generateId(),
2857
+ toolCallId: (_i = toolCall.id) != null ? _i : generateId(),
2839
2858
  toolName: toolCall.function.name,
2840
2859
  input: toolCall.function.arguments
2841
2860
  });
@@ -2876,18 +2895,18 @@ var LLMGatewayChatLanguageModel = class {
2876
2895
  providerMetadata: includeUsageAccounting ? {
2877
2896
  llmgateway: {
2878
2897
  usage: {
2879
- promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
2880
- completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
2881
- totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
2882
- 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,
2883
2902
  promptTokensDetails: {
2884
- 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
2885
2904
  },
2886
2905
  completionTokensDetails: {
2887
- 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
2888
2907
  },
2889
2908
  costDetails: {
2890
- 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
2891
2910
  }
2892
2911
  }
2893
2912
  }
@@ -2923,13 +2942,19 @@ var LLMGatewayChatLanguageModel = class {
2923
2942
  fetch: this.config.fetch
2924
2943
  });
2925
2944
  const toolCalls = [];
2926
- let finishReason = "other";
2945
+ let finishReason = { unified: "other", raw: void 0 };
2927
2946
  const usage = {
2928
- inputTokens: Number.NaN,
2929
- outputTokens: Number.NaN,
2930
- totalTokens: Number.NaN,
2931
- reasoningTokens: Number.NaN,
2932
- 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
+ }
2933
2958
  };
2934
2959
  const llmgatewayUsage = {};
2935
2960
  let textStarted = false;
@@ -2943,13 +2968,13 @@ var LLMGatewayChatLanguageModel = class {
2943
2968
  transform(chunk, controller) {
2944
2969
  var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2945
2970
  if (!chunk.success) {
2946
- finishReason = "error";
2971
+ finishReason = { unified: "error", raw: void 0 };
2947
2972
  controller.enqueue({ type: "error", error: chunk.error });
2948
2973
  return;
2949
2974
  }
2950
2975
  const value = chunk.value;
2951
2976
  if ("error" in value) {
2952
- finishReason = "error";
2977
+ finishReason = { unified: "error", raw: void 0 };
2953
2978
  controller.enqueue({ type: "error", error: value.error });
2954
2979
  return;
2955
2980
  }
@@ -2967,13 +2992,12 @@ var LLMGatewayChatLanguageModel = class {
2967
2992
  });
2968
2993
  }
2969
2994
  if (value.usage != null) {
2970
- usage.inputTokens = value.usage.prompt_tokens;
2971
- usage.outputTokens = value.usage.completion_tokens;
2972
- 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;
2973
2997
  llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
2974
2998
  if (value.usage.prompt_tokens_details) {
2975
2999
  const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
2976
- usage.cachedInputTokens = cachedInputTokens;
3000
+ usage.inputTokens.cacheRead = cachedInputTokens;
2977
3001
  llmgatewayUsage.promptTokensDetails = {
2978
3002
  cachedTokens: cachedInputTokens
2979
3003
  };
@@ -2981,7 +3005,7 @@ var LLMGatewayChatLanguageModel = class {
2981
3005
  llmgatewayUsage.completionTokens = value.usage.completion_tokens;
2982
3006
  if (value.usage.completion_tokens_details) {
2983
3007
  const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
2984
- usage.reasoningTokens = reasoningTokens;
3008
+ usage.outputTokens.reasoning = reasoningTokens;
2985
3009
  llmgatewayUsage.completionTokensDetails = {
2986
3010
  reasoningTokens
2987
3011
  };
@@ -3164,7 +3188,7 @@ var LLMGatewayChatLanguageModel = class {
3164
3188
  },
3165
3189
  flush(controller) {
3166
3190
  var _a16;
3167
- if (finishReason === "tool-calls") {
3191
+ if (finishReason.unified === "tool-calls") {
3168
3192
  for (const toolCall of toolCalls) {
3169
3193
  if (toolCall && !toolCall.sent) {
3170
3194
  controller.enqueue({
@@ -3203,7 +3227,6 @@ var LLMGatewayChatLanguageModel = class {
3203
3227
  }
3204
3228
  })
3205
3229
  ),
3206
- warnings: [],
3207
3230
  request: { body: args },
3208
3231
  response: { headers: responseHeaders }
3209
3232
  };
@@ -3355,7 +3378,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
3355
3378
  // src/completion/index.ts
3356
3379
  var LLMGatewayCompletionLanguageModel = class {
3357
3380
  constructor(modelId, settings, config) {
3358
- this.specificationVersion = "v2";
3381
+ this.specificationVersion = "v3";
3359
3382
  this.provider = "llmgateway";
3360
3383
  this.supportedUrls = {
3361
3384
  "image/*": [
@@ -3365,7 +3388,6 @@ var LLMGatewayCompletionLanguageModel = class {
3365
3388
  "text/*": [/^data:text\//, /^https?:\/\/.+$/],
3366
3389
  "application/*": [/^data:application\//, /^https?:\/\/.+$/]
3367
3390
  };
3368
- this.defaultObjectGenerationMode = void 0;
3369
3391
  this.modelId = modelId;
3370
3392
  this.settings = settings;
3371
3393
  this.config = config;
@@ -3425,7 +3447,7 @@ var LLMGatewayCompletionLanguageModel = class {
3425
3447
  }, this.config.extraBody), this.settings.extraBody);
3426
3448
  }
3427
3449
  async doGenerate(options) {
3428
- 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;
3429
3451
  const providerOptions = options.providerOptions || {};
3430
3452
  const llmgatewayOptions = providerOptions.llmgateway || {};
3431
3453
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
@@ -3459,11 +3481,17 @@ var LLMGatewayCompletionLanguageModel = class {
3459
3481
  ],
3460
3482
  finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
3461
3483
  usage: {
3462
- inputTokens: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : 0,
3463
- outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
3464
- 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),
3465
- reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
3466
- 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
+ }
3467
3495
  },
3468
3496
  warnings: [],
3469
3497
  response: {
@@ -3493,13 +3521,19 @@ var LLMGatewayCompletionLanguageModel = class {
3493
3521
  abortSignal: options.abortSignal,
3494
3522
  fetch: this.config.fetch
3495
3523
  });
3496
- let finishReason = "other";
3524
+ let finishReason = { unified: "other", raw: void 0 };
3497
3525
  const usage = {
3498
- inputTokens: Number.NaN,
3499
- outputTokens: Number.NaN,
3500
- totalTokens: Number.NaN,
3501
- reasoningTokens: Number.NaN,
3502
- 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
+ }
3503
3537
  };
3504
3538
  const llmgatewayUsage = {};
3505
3539
  return {
@@ -3508,24 +3542,23 @@ var LLMGatewayCompletionLanguageModel = class {
3508
3542
  transform(chunk, controller) {
3509
3543
  var _a16, _b16, _c;
3510
3544
  if (!chunk.success) {
3511
- finishReason = "error";
3545
+ finishReason = { unified: "error", raw: void 0 };
3512
3546
  controller.enqueue({ type: "error", error: chunk.error });
3513
3547
  return;
3514
3548
  }
3515
3549
  const value = chunk.value;
3516
3550
  if ("error" in value) {
3517
- finishReason = "error";
3551
+ finishReason = { unified: "error", raw: void 0 };
3518
3552
  controller.enqueue({ type: "error", error: value.error });
3519
3553
  return;
3520
3554
  }
3521
3555
  if (value.usage != null) {
3522
- usage.inputTokens = value.usage.prompt_tokens;
3523
- usage.outputTokens = value.usage.completion_tokens;
3524
- 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;
3525
3558
  llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
3526
3559
  if (value.usage.prompt_tokens_details) {
3527
3560
  const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
3528
- usage.cachedInputTokens = cachedInputTokens;
3561
+ usage.inputTokens.cacheRead = cachedInputTokens;
3529
3562
  llmgatewayUsage.promptTokensDetails = {
3530
3563
  cachedTokens: cachedInputTokens
3531
3564
  };
@@ -3533,7 +3566,7 @@ var LLMGatewayCompletionLanguageModel = class {
3533
3566
  llmgatewayUsage.completionTokens = value.usage.completion_tokens;
3534
3567
  if (value.usage.completion_tokens_details) {
3535
3568
  const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
3536
- usage.reasoningTokens = reasoningTokens;
3569
+ usage.outputTokens.reasoning = reasoningTokens;
3537
3570
  llmgatewayUsage.completionTokensDetails = {
3538
3571
  reasoningTokens
3539
3572
  };
@@ -3667,13 +3700,19 @@ var LLMGatewayImageModel = class {
3667
3700
  if (options.aspectRatio != null) {
3668
3701
  body.aspect_ratio = options.aspectRatio;
3669
3702
  }
3703
+ if (options.quality != null) {
3704
+ body.quality = options.quality;
3705
+ }
3706
+ const providerOptions = options.providerOptions || {};
3707
+ const llmgatewayOptions = providerOptions.llmgateway || {};
3708
+ const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, body), this.config.extraBody), this.settings.extraBody), llmgatewayOptions);
3670
3709
  const { value: response, responseHeaders } = await postJsonToApi({
3671
3710
  url: this.config.url({
3672
3711
  path: hasFiles ? "/images/edits" : "/images/generations",
3673
3712
  modelId: this.modelId
3674
3713
  }),
3675
3714
  headers: combineHeaders(this.config.headers(), options.headers),
3676
- body,
3715
+ body: requestBody,
3677
3716
  failedResponseHandler: llmgatewayFailedResponseHandler,
3678
3717
  successfulResponseHandler: createJsonResponseHandler(
3679
3718
  LLMGatewayImageResponseSchema
@@ -3732,7 +3771,8 @@ function createLLMGateway(options = {}) {
3732
3771
  provider: "llmgateway.image",
3733
3772
  url: ({ path }) => `${baseURL}${path}`,
3734
3773
  headers: getHeaders,
3735
- fetch: options.fetch
3774
+ fetch: options.fetch,
3775
+ extraBody: options.extraBody
3736
3776
  });
3737
3777
  const createLanguageModel = (modelId, settings) => {
3738
3778
  if (new.target) {