sarvam-ai-sdk 0.3.0 → 0.3.4

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
@@ -1,5 +1,5 @@
1
- <a href="https://github.com/rajatsandeepsen/sarvam-ai-sdk">
2
- <img alt="cover" src="https://github.com/rajatsandeepsen/sarvam-ai-sdk/blob/master/cover.png?raw=true" />
1
+ <a href="https://github.com/sarvamai/sarvam-ai-sdk">
2
+ <img alt="cover" src="https://github.com/sarvamai/sarvam-ai-sdk/blob/master/cover.png?raw=true" />
3
3
  </a>
4
4
 
5
5
  # AI SDK - Sarvam Provider
@@ -18,6 +18,15 @@ npm i sarvam-ai-sdk ai@6
18
18
  > [!WARNING]
19
19
  > This package only works with Vercel AI-SDK v6, not v7. Make sure to install `ai@6` in your project.
20
20
 
21
+ ### Version Compatibility
22
+
23
+ | Sarvam AI SDK Version | Vercel AI SDK Version |
24
+ |-----------------------|-----------------------|
25
+ | 0.4.x (beta) | 7.x.x (beta) |
26
+ | 0.3.x (current) | 6.x.x (current) |
27
+ | 0.2.x | 5.x.x |
28
+ | 0.1.x | 4.x.x |
29
+
21
30
  ## Provider Instance
22
31
 
23
32
  You can import the default provider instance `sarvam` from `sarvam-ai-sdk`:
@@ -160,29 +169,56 @@ console.log(result.toolResults);
160
169
  ```
161
170
 
162
171
  ## Generate JSON object
172
+ > NB: `generateObject` is deprecated, use `generateText` with `Output` tool.
163
173
 
164
174
  ```ts
165
175
  import { z } from "zod";
166
176
  import { sarvam } from "sarvam-ai-sdk";
167
- import { generateObject } from 'ai';
177
+ import { generateObject } from "ai";
168
178
 
169
179
  const { object } = await generateObject({
170
- model: sarvam("sarvam-30b"),
171
- schemaName: "Recipe",
172
- schemaDescription: "A recipe with a name, ingredients and steps",
173
- schema: z.object({
174
- recipe: z.object({
175
- name: z.string(),
176
- ingredients: z.array(z.string()),
177
- steps: z.array(z.string()),
178
- }),
179
- }),
180
- prompt: 'Generate a South Indian recipe, in Malayalam',
180
+ model: sarvam("sarvam-30b"),
181
+ schemaName: "Recipe",
182
+ schemaDescription: "A recipe with a name, ingredients and steps",
183
+ schema: z.object({
184
+ recipe: z.object({
185
+ name: z.string(),
186
+ ingredients: z.array(z.string()),
187
+ steps: z.array(z.string()),
188
+ }),
189
+ }),
190
+ prompt: "Generate a South Indian recipe, in Malayalam",
181
191
  });
182
192
 
183
193
  console.log(object);
184
194
  ```
185
195
 
196
+ ## Generating Structured Outputs
197
+
198
+ ```ts
199
+ import { z } from "zod";
200
+ import { sarvam } from "sarvam-ai-sdk";
201
+ import { generateText, Output } from "ai";
202
+
203
+ const { output } = await generateText({
204
+ model: sarvam("sarvam-105b"),
205
+ output: Output.object({
206
+ name: "Recipe",
207
+ description: "A recipe with a name, ingredients and steps",
208
+ schema: z.object({
209
+ recipe: z.object({
210
+ name: z.string(),
211
+ ingredients: z.array(z.string()),
212
+ steps: z.array(z.string()),
213
+ }),
214
+ }),
215
+ }),
216
+ prompt: "Generate a South Indian recipe, in Malayalam",
217
+ });
218
+
219
+ console.log(output);
220
+ ```
221
+
186
222
  ## All APIs
187
223
 
188
224
  ```ts
package/dist/index.cjs CHANGED
@@ -41,6 +41,20 @@ const sarvamFailedResponseHandler = (0, __ai_sdk_provider_utils.createJsonErrorR
41
41
 
42
42
  //#endregion
43
43
  //#region src/chat/convert-to-chat-messages.ts
44
+ function getToolResultContent(output) {
45
+ switch (output.type) {
46
+ case "text":
47
+ case "error-text": return output.value;
48
+ case "json":
49
+ case "error-json":
50
+ case "content": return JSON.stringify(output.value);
51
+ case "execution-denied": return output.reason ?? "Tool execution was denied.";
52
+ default: {
53
+ const _exhaustiveCheck = output;
54
+ return JSON.stringify(_exhaustiveCheck);
55
+ }
56
+ }
57
+ }
44
58
  function convertToChatMessages(prompt) {
45
59
  const messages = [];
46
60
  for (const message of prompt) switch (message.role) {
@@ -112,7 +126,7 @@ function convertToChatMessages(prompt) {
112
126
  for (const part of message.content) if (part.type === "tool-result") messages.push({
113
127
  role: "tool",
114
128
  tool_call_id: part.toolCallId,
115
- content: JSON.stringify(part.output)
129
+ content: getToolResultContent(part.output)
116
130
  });
117
131
  break;
118
132
  default: {
@@ -135,8 +149,8 @@ function prepareTools({ tools, toolChoice }) {
135
149
  };
136
150
  const sarvamTools = [];
137
151
  for (const tool of finalTools) if (tool.type === "provider") toolWarnings.push({
138
- type: "unsupported-tool",
139
- tool
152
+ type: "unsupported",
153
+ feature: tool.name
140
154
  });
141
155
  else sarvamTools.push({
142
156
  type: "function",
@@ -196,7 +210,6 @@ const chatResponseSchema = zod.default.object({
196
210
  logprobs: zod.default.object({}).nullish(),
197
211
  message: zod.default.object({
198
212
  content: zod.default.string().nullish(),
199
- reasoning: zod.default.string().nullish(),
200
213
  reasoning_content: zod.default.string().nullish(),
201
214
  refusal: zod.default.string().nullish(),
202
215
  tool_calls: zod.default.array(zod.default.object({
@@ -341,7 +354,7 @@ var SarvamChatLanguageModel = class {
341
354
  ...options,
342
355
  stream: false
343
356
  });
344
- const body = JSON.stringify(args);
357
+ const isJSON = options.responseFormat?.type === "json";
345
358
  const { responseHeaders, value: response, rawValue: rawResponse } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
346
359
  url: this.config.url({
347
360
  path: "/chat/completions",
@@ -364,27 +377,24 @@ var SarvamChatLanguageModel = class {
364
377
  type: "text",
365
378
  text: choice.message.content
366
379
  });
367
- const reasoningText = choice.message.reasoning ?? choice.message.reasoning_content;
368
- if (reasoningText) content.push({
380
+ if (choice.message.reasoning_content) content.push({
369
381
  type: "reasoning",
370
- text: reasoningText
382
+ text: choice.message.reasoning_content
383
+ });
384
+ if (choice.message.tool_calls && choice.message.tool_calls.length > 0) for (const toolCall of choice.message.tool_calls) if (isJSON) content.push({
385
+ type: "text",
386
+ text: toolCall.function.arguments
387
+ });
388
+ else content.push({
389
+ type: "tool-call",
390
+ toolCallId: toolCall.id ?? (this.config.generateId ?? __ai_sdk_provider_utils.generateId)(),
391
+ toolName: toolCall.function.name,
392
+ input: toolCall.function.arguments
371
393
  });
372
- if (choice.message.tool_calls && choice.message.tool_calls.length > 0) {
373
- if (options.responseFormat?.type === "json") content.push({
374
- type: "text",
375
- text: choice.message.tool_calls[0].function.arguments
376
- });
377
- for (const toolCall of choice.message.tool_calls) content.push({
378
- type: "tool-call",
379
- toolCallId: toolCall.id ?? (this.config.generateId ?? __ai_sdk_provider_utils.generateId)(),
380
- toolName: toolCall.function.name,
381
- input: toolCall.function.arguments
382
- });
383
- }
384
394
  return {
385
395
  content,
386
396
  finishReason: {
387
- unified: mapFinishReason(choice.finish_reason),
397
+ unified: isJSON ? "stop" : mapFinishReason(choice.finish_reason),
388
398
  raw: choice.finish_reason ?? void 0
389
399
  },
390
400
  usage: {
@@ -400,11 +410,18 @@ var SarvamChatLanguageModel = class {
400
410
  reasoning: void 0
401
411
  }
402
412
  },
413
+ providerMetadata: { sarvam: {
414
+ system_fingerprint: response.system_fingerprint,
415
+ service_tier: response.service_tier
416
+ } },
403
417
  warnings,
404
- request: { body },
418
+ request: { body: args },
405
419
  response: {
406
420
  headers: responseHeaders,
407
- body: rawResponse
421
+ body: rawResponse,
422
+ id: response.id ?? void 0,
423
+ modelId: response.model ?? void 0,
424
+ timestamp: response.created ? /* @__PURE__ */ new Date(response.created * 1e3) : void 0
408
425
  }
409
426
  };
410
427
  }
@@ -413,10 +430,6 @@ var SarvamChatLanguageModel = class {
413
430
  ...options,
414
431
  stream: true
415
432
  });
416
- const body = JSON.stringify({
417
- ...args,
418
- stream: true
419
- });
420
433
  const { responseHeaders, value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
421
434
  url: this.config.url({
422
435
  path: "/chat/completions",
@@ -538,12 +551,21 @@ var SarvamChatLanguageModel = class {
538
551
  };
539
552
  const toolCall$1 = toolCalls[index];
540
553
  if (toolCall$1.name != null && toolCall$1.arguments != null) {
554
+ controller.enqueue({
555
+ type: "tool-input-start",
556
+ id: toolCall$1.id,
557
+ toolName: toolCall$1.name
558
+ });
541
559
  if (toolCall$1.arguments.length > 0) controller.enqueue({
542
560
  type: "tool-input-delta",
543
561
  id: toolCall$1.id,
544
562
  delta: toolCall$1.arguments
545
563
  });
546
564
  if ((0, __ai_sdk_provider_utils.isParsableJson)(toolCall$1.arguments)) {
565
+ controller.enqueue({
566
+ type: "tool-input-end",
567
+ id: toolCall$1.id
568
+ });
547
569
  controller.enqueue({
548
570
  type: "tool-call",
549
571
  toolCallId: toolCall$1.id,
@@ -564,6 +586,10 @@ var SarvamChatLanguageModel = class {
564
586
  delta: toolCallDelta.function.arguments ?? ""
565
587
  });
566
588
  if (toolCall.name != null && toolCall.arguments != null && (0, __ai_sdk_provider_utils.isParsableJson)(toolCall.arguments)) {
589
+ controller.enqueue({
590
+ type: "tool-input-end",
591
+ id: toolCall.id
592
+ });
567
593
  controller.enqueue({
568
594
  type: "tool-call",
569
595
  toolCallId: toolCall.id,
@@ -582,7 +608,7 @@ var SarvamChatLanguageModel = class {
582
608
  });
583
609
  }
584
610
  })),
585
- request: { body },
611
+ request: { body: args },
586
612
  response: { headers: responseHeaders }
587
613
  };
588
614
  }
@@ -731,7 +757,12 @@ var SarvamTranscriptionModel = class {
731
757
  language: response.language_code ?? void 0,
732
758
  durationInSeconds: response.timestamps?.end_time_seconds[response.timestamps.end_time_seconds.length - 1] ?? void 0,
733
759
  warnings,
734
- providerMetadata: { sarvam: { languageProbability: response.language_probability ?? void 0 } },
760
+ providerMetadata: { sarvam: {
761
+ request_id: response.request_id,
762
+ transcript: response.transcript,
763
+ language_code: response.language_code,
764
+ language_probability: response.language_probability
765
+ } },
735
766
  response: {
736
767
  timestamp: currentDate,
737
768
  modelId: this.modelId,
@@ -880,7 +911,8 @@ var SarvamSpeechModel = class {
880
911
  return {
881
912
  audio,
882
913
  warnings,
883
- request: { body: JSON.stringify(requestBody) },
914
+ providerMetadata: { sarvam: { request_id: value.request_id } },
915
+ request: { body: requestBody },
884
916
  response: {
885
917
  timestamp: currentDate,
886
918
  modelId: this.modelId,
@@ -931,7 +963,7 @@ var SarvamLidModel = class {
931
963
  ...options,
932
964
  stream: false
933
965
  });
934
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
966
+ const { responseHeaders, value: response, rawValue: rawResponse } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
935
967
  url: this.config.url({
936
968
  path: "/text-lid",
937
969
  modelId: this.modelId
@@ -965,6 +997,17 @@ var SarvamLidModel = class {
965
997
  reasoning: void 0
966
998
  }
967
999
  },
1000
+ request: { body: args },
1001
+ response: {
1002
+ id: response.request_id ?? void 0,
1003
+ headers: responseHeaders,
1004
+ body: rawResponse
1005
+ },
1006
+ providerMetadata: { sarvam: {
1007
+ request_id: response.request_id,
1008
+ script_code: response.script_code,
1009
+ language_code: response.language_code
1010
+ } },
968
1011
  warnings: []
969
1012
  };
970
1013
  }
@@ -1029,8 +1072,7 @@ var SarvamTranslationModel = class {
1029
1072
  schema: translationSettingsSchema
1030
1073
  });
1031
1074
  if (!sarvamOptions) throw new Error("Translation Settings is not provided");
1032
- const from = sarvamOptions.from ?? "auto";
1033
- const to = sarvamOptions.to;
1075
+ const { from = "auto", to,...restOptions } = sarvamOptions;
1034
1076
  if (from === to) throw new Error("Source and target languages code must be different.");
1035
1077
  if (this.modelId === "sarvam-translate:v1") {
1036
1078
  if ((sarvamOptions.mode ?? "formal") !== "formal") throw new Error("Sarvam 'sarvam-translate:v1' only support mode formal.");
@@ -1040,7 +1082,7 @@ var SarvamTranslationModel = class {
1040
1082
  args: {
1041
1083
  input: convertPromptToInput(prompt),
1042
1084
  model: this.modelId,
1043
- ...sarvamOptions,
1085
+ ...restOptions,
1044
1086
  source_language_code: from,
1045
1087
  target_language_code: to
1046
1088
  },
@@ -1052,7 +1094,7 @@ var SarvamTranslationModel = class {
1052
1094
  ...options,
1053
1095
  stream: false
1054
1096
  });
1055
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1097
+ const { responseHeaders, value: response, rawValue: rawResponse } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1056
1098
  url: this.config.url({
1057
1099
  path: "/translate",
1058
1100
  modelId: this.modelId
@@ -1086,6 +1128,17 @@ var SarvamTranslationModel = class {
1086
1128
  reasoning: void 0
1087
1129
  }
1088
1130
  },
1131
+ request: { body: args },
1132
+ response: {
1133
+ id: response.request_id ?? void 0,
1134
+ headers: responseHeaders,
1135
+ body: rawResponse
1136
+ },
1137
+ providerMetadata: { sarvam: {
1138
+ request_id: response.request_id,
1139
+ source_language_code: response.source_language_code,
1140
+ translated_text: response.translated_text
1141
+ } },
1089
1142
  warnings: []
1090
1143
  };
1091
1144
  }
@@ -1135,8 +1188,7 @@ var SarvamTransliterateModel = class {
1135
1188
  schema: transliterateSettingsSchema
1136
1189
  });
1137
1190
  if (!sarvamOptions) throw new Error("Transliterate Settings is not provided");
1138
- const from = sarvamOptions.from ?? "auto";
1139
- const to = sarvamOptions.to;
1191
+ const { from = "auto", to,...restOptions } = sarvamOptions;
1140
1192
  if (from !== "auto") {
1141
1193
  if (to !== "en-IN" && from !== "en-IN") {
1142
1194
  if (to !== from) throw new Error("Sarvam doesn't support Indic-Indic Transliteration yet");
@@ -1145,7 +1197,7 @@ var SarvamTransliterateModel = class {
1145
1197
  return {
1146
1198
  args: {
1147
1199
  input: convertPromptToInput(prompt),
1148
- ...sarvamOptions,
1200
+ ...restOptions,
1149
1201
  source_language_code: from,
1150
1202
  target_language_code: to,
1151
1203
  spoken_form_numerals_language: sarvamOptions.spoken_form ? sarvamOptions.spoken_form_numerals_language ?? "english" : void 0
@@ -1158,7 +1210,7 @@ var SarvamTransliterateModel = class {
1158
1210
  ...options,
1159
1211
  stream: false
1160
1212
  });
1161
- const { value: response } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1213
+ const { responseHeaders, value: response, rawValue: rawResponse } = await (0, __ai_sdk_provider_utils.postJsonToApi)({
1162
1214
  url: this.config.url({
1163
1215
  path: "/transliterate",
1164
1216
  modelId: this.modelId
@@ -1192,6 +1244,17 @@ var SarvamTransliterateModel = class {
1192
1244
  reasoning: void 0
1193
1245
  }
1194
1246
  },
1247
+ request: { body: args },
1248
+ response: {
1249
+ id: response.request_id ?? void 0,
1250
+ headers: responseHeaders,
1251
+ body: rawResponse
1252
+ },
1253
+ providerMetadata: { sarvam: {
1254
+ request_id: response.request_id,
1255
+ source_language_code: response.source_language_code,
1256
+ transliterated_text: response.transliterated_text
1257
+ } },
1195
1258
  warnings: []
1196
1259
  };
1197
1260
  }
package/dist/index.js CHANGED
@@ -15,6 +15,20 @@ const sarvamFailedResponseHandler = createJsonErrorResponseHandler({
15
15
 
16
16
  //#endregion
17
17
  //#region src/chat/convert-to-chat-messages.ts
18
+ function getToolResultContent(output) {
19
+ switch (output.type) {
20
+ case "text":
21
+ case "error-text": return output.value;
22
+ case "json":
23
+ case "error-json":
24
+ case "content": return JSON.stringify(output.value);
25
+ case "execution-denied": return output.reason ?? "Tool execution was denied.";
26
+ default: {
27
+ const _exhaustiveCheck = output;
28
+ return JSON.stringify(_exhaustiveCheck);
29
+ }
30
+ }
31
+ }
18
32
  function convertToChatMessages(prompt) {
19
33
  const messages = [];
20
34
  for (const message of prompt) switch (message.role) {
@@ -86,7 +100,7 @@ function convertToChatMessages(prompt) {
86
100
  for (const part of message.content) if (part.type === "tool-result") messages.push({
87
101
  role: "tool",
88
102
  tool_call_id: part.toolCallId,
89
- content: JSON.stringify(part.output)
103
+ content: getToolResultContent(part.output)
90
104
  });
91
105
  break;
92
106
  default: {
@@ -109,8 +123,8 @@ function prepareTools({ tools, toolChoice }) {
109
123
  };
110
124
  const sarvamTools = [];
111
125
  for (const tool of finalTools) if (tool.type === "provider") toolWarnings.push({
112
- type: "unsupported-tool",
113
- tool
126
+ type: "unsupported",
127
+ feature: tool.name
114
128
  });
115
129
  else sarvamTools.push({
116
130
  type: "function",
@@ -170,7 +184,6 @@ const chatResponseSchema = z$1.object({
170
184
  logprobs: z$1.object({}).nullish(),
171
185
  message: z$1.object({
172
186
  content: z$1.string().nullish(),
173
- reasoning: z$1.string().nullish(),
174
187
  reasoning_content: z$1.string().nullish(),
175
188
  refusal: z$1.string().nullish(),
176
189
  tool_calls: z$1.array(z$1.object({
@@ -315,7 +328,7 @@ var SarvamChatLanguageModel = class {
315
328
  ...options,
316
329
  stream: false
317
330
  });
318
- const body = JSON.stringify(args);
331
+ const isJSON = options.responseFormat?.type === "json";
319
332
  const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
320
333
  url: this.config.url({
321
334
  path: "/chat/completions",
@@ -338,27 +351,24 @@ var SarvamChatLanguageModel = class {
338
351
  type: "text",
339
352
  text: choice.message.content
340
353
  });
341
- const reasoningText = choice.message.reasoning ?? choice.message.reasoning_content;
342
- if (reasoningText) content.push({
354
+ if (choice.message.reasoning_content) content.push({
343
355
  type: "reasoning",
344
- text: reasoningText
356
+ text: choice.message.reasoning_content
357
+ });
358
+ if (choice.message.tool_calls && choice.message.tool_calls.length > 0) for (const toolCall of choice.message.tool_calls) if (isJSON) content.push({
359
+ type: "text",
360
+ text: toolCall.function.arguments
361
+ });
362
+ else content.push({
363
+ type: "tool-call",
364
+ toolCallId: toolCall.id ?? (this.config.generateId ?? generateId)(),
365
+ toolName: toolCall.function.name,
366
+ input: toolCall.function.arguments
345
367
  });
346
- if (choice.message.tool_calls && choice.message.tool_calls.length > 0) {
347
- if (options.responseFormat?.type === "json") content.push({
348
- type: "text",
349
- text: choice.message.tool_calls[0].function.arguments
350
- });
351
- for (const toolCall of choice.message.tool_calls) content.push({
352
- type: "tool-call",
353
- toolCallId: toolCall.id ?? (this.config.generateId ?? generateId)(),
354
- toolName: toolCall.function.name,
355
- input: toolCall.function.arguments
356
- });
357
- }
358
368
  return {
359
369
  content,
360
370
  finishReason: {
361
- unified: mapFinishReason(choice.finish_reason),
371
+ unified: isJSON ? "stop" : mapFinishReason(choice.finish_reason),
362
372
  raw: choice.finish_reason ?? void 0
363
373
  },
364
374
  usage: {
@@ -374,11 +384,18 @@ var SarvamChatLanguageModel = class {
374
384
  reasoning: void 0
375
385
  }
376
386
  },
387
+ providerMetadata: { sarvam: {
388
+ system_fingerprint: response.system_fingerprint,
389
+ service_tier: response.service_tier
390
+ } },
377
391
  warnings,
378
- request: { body },
392
+ request: { body: args },
379
393
  response: {
380
394
  headers: responseHeaders,
381
- body: rawResponse
395
+ body: rawResponse,
396
+ id: response.id ?? void 0,
397
+ modelId: response.model ?? void 0,
398
+ timestamp: response.created ? /* @__PURE__ */ new Date(response.created * 1e3) : void 0
382
399
  }
383
400
  };
384
401
  }
@@ -387,10 +404,6 @@ var SarvamChatLanguageModel = class {
387
404
  ...options,
388
405
  stream: true
389
406
  });
390
- const body = JSON.stringify({
391
- ...args,
392
- stream: true
393
- });
394
407
  const { responseHeaders, value: response } = await postJsonToApi({
395
408
  url: this.config.url({
396
409
  path: "/chat/completions",
@@ -512,12 +525,21 @@ var SarvamChatLanguageModel = class {
512
525
  };
513
526
  const toolCall$1 = toolCalls[index];
514
527
  if (toolCall$1.name != null && toolCall$1.arguments != null) {
528
+ controller.enqueue({
529
+ type: "tool-input-start",
530
+ id: toolCall$1.id,
531
+ toolName: toolCall$1.name
532
+ });
515
533
  if (toolCall$1.arguments.length > 0) controller.enqueue({
516
534
  type: "tool-input-delta",
517
535
  id: toolCall$1.id,
518
536
  delta: toolCall$1.arguments
519
537
  });
520
538
  if (isParsableJson(toolCall$1.arguments)) {
539
+ controller.enqueue({
540
+ type: "tool-input-end",
541
+ id: toolCall$1.id
542
+ });
521
543
  controller.enqueue({
522
544
  type: "tool-call",
523
545
  toolCallId: toolCall$1.id,
@@ -538,6 +560,10 @@ var SarvamChatLanguageModel = class {
538
560
  delta: toolCallDelta.function.arguments ?? ""
539
561
  });
540
562
  if (toolCall.name != null && toolCall.arguments != null && isParsableJson(toolCall.arguments)) {
563
+ controller.enqueue({
564
+ type: "tool-input-end",
565
+ id: toolCall.id
566
+ });
541
567
  controller.enqueue({
542
568
  type: "tool-call",
543
569
  toolCallId: toolCall.id,
@@ -556,7 +582,7 @@ var SarvamChatLanguageModel = class {
556
582
  });
557
583
  }
558
584
  })),
559
- request: { body },
585
+ request: { body: args },
560
586
  response: { headers: responseHeaders }
561
587
  };
562
588
  }
@@ -705,7 +731,12 @@ var SarvamTranscriptionModel = class {
705
731
  language: response.language_code ?? void 0,
706
732
  durationInSeconds: response.timestamps?.end_time_seconds[response.timestamps.end_time_seconds.length - 1] ?? void 0,
707
733
  warnings,
708
- providerMetadata: { sarvam: { languageProbability: response.language_probability ?? void 0 } },
734
+ providerMetadata: { sarvam: {
735
+ request_id: response.request_id,
736
+ transcript: response.transcript,
737
+ language_code: response.language_code,
738
+ language_probability: response.language_probability
739
+ } },
709
740
  response: {
710
741
  timestamp: currentDate,
711
742
  modelId: this.modelId,
@@ -854,7 +885,8 @@ var SarvamSpeechModel = class {
854
885
  return {
855
886
  audio,
856
887
  warnings,
857
- request: { body: JSON.stringify(requestBody) },
888
+ providerMetadata: { sarvam: { request_id: value.request_id } },
889
+ request: { body: requestBody },
858
890
  response: {
859
891
  timestamp: currentDate,
860
892
  modelId: this.modelId,
@@ -905,7 +937,7 @@ var SarvamLidModel = class {
905
937
  ...options,
906
938
  stream: false
907
939
  });
908
- const { value: response } = await postJsonToApi({
940
+ const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
909
941
  url: this.config.url({
910
942
  path: "/text-lid",
911
943
  modelId: this.modelId
@@ -939,6 +971,17 @@ var SarvamLidModel = class {
939
971
  reasoning: void 0
940
972
  }
941
973
  },
974
+ request: { body: args },
975
+ response: {
976
+ id: response.request_id ?? void 0,
977
+ headers: responseHeaders,
978
+ body: rawResponse
979
+ },
980
+ providerMetadata: { sarvam: {
981
+ request_id: response.request_id,
982
+ script_code: response.script_code,
983
+ language_code: response.language_code
984
+ } },
942
985
  warnings: []
943
986
  };
944
987
  }
@@ -1003,8 +1046,7 @@ var SarvamTranslationModel = class {
1003
1046
  schema: translationSettingsSchema
1004
1047
  });
1005
1048
  if (!sarvamOptions) throw new Error("Translation Settings is not provided");
1006
- const from = sarvamOptions.from ?? "auto";
1007
- const to = sarvamOptions.to;
1049
+ const { from = "auto", to,...restOptions } = sarvamOptions;
1008
1050
  if (from === to) throw new Error("Source and target languages code must be different.");
1009
1051
  if (this.modelId === "sarvam-translate:v1") {
1010
1052
  if ((sarvamOptions.mode ?? "formal") !== "formal") throw new Error("Sarvam 'sarvam-translate:v1' only support mode formal.");
@@ -1014,7 +1056,7 @@ var SarvamTranslationModel = class {
1014
1056
  args: {
1015
1057
  input: convertPromptToInput(prompt),
1016
1058
  model: this.modelId,
1017
- ...sarvamOptions,
1059
+ ...restOptions,
1018
1060
  source_language_code: from,
1019
1061
  target_language_code: to
1020
1062
  },
@@ -1026,7 +1068,7 @@ var SarvamTranslationModel = class {
1026
1068
  ...options,
1027
1069
  stream: false
1028
1070
  });
1029
- const { value: response } = await postJsonToApi({
1071
+ const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
1030
1072
  url: this.config.url({
1031
1073
  path: "/translate",
1032
1074
  modelId: this.modelId
@@ -1060,6 +1102,17 @@ var SarvamTranslationModel = class {
1060
1102
  reasoning: void 0
1061
1103
  }
1062
1104
  },
1105
+ request: { body: args },
1106
+ response: {
1107
+ id: response.request_id ?? void 0,
1108
+ headers: responseHeaders,
1109
+ body: rawResponse
1110
+ },
1111
+ providerMetadata: { sarvam: {
1112
+ request_id: response.request_id,
1113
+ source_language_code: response.source_language_code,
1114
+ translated_text: response.translated_text
1115
+ } },
1063
1116
  warnings: []
1064
1117
  };
1065
1118
  }
@@ -1109,8 +1162,7 @@ var SarvamTransliterateModel = class {
1109
1162
  schema: transliterateSettingsSchema
1110
1163
  });
1111
1164
  if (!sarvamOptions) throw new Error("Transliterate Settings is not provided");
1112
- const from = sarvamOptions.from ?? "auto";
1113
- const to = sarvamOptions.to;
1165
+ const { from = "auto", to,...restOptions } = sarvamOptions;
1114
1166
  if (from !== "auto") {
1115
1167
  if (to !== "en-IN" && from !== "en-IN") {
1116
1168
  if (to !== from) throw new Error("Sarvam doesn't support Indic-Indic Transliteration yet");
@@ -1119,7 +1171,7 @@ var SarvamTransliterateModel = class {
1119
1171
  return {
1120
1172
  args: {
1121
1173
  input: convertPromptToInput(prompt),
1122
- ...sarvamOptions,
1174
+ ...restOptions,
1123
1175
  source_language_code: from,
1124
1176
  target_language_code: to,
1125
1177
  spoken_form_numerals_language: sarvamOptions.spoken_form ? sarvamOptions.spoken_form_numerals_language ?? "english" : void 0
@@ -1132,7 +1184,7 @@ var SarvamTransliterateModel = class {
1132
1184
  ...options,
1133
1185
  stream: false
1134
1186
  });
1135
- const { value: response } = await postJsonToApi({
1187
+ const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
1136
1188
  url: this.config.url({
1137
1189
  path: "/transliterate",
1138
1190
  modelId: this.modelId
@@ -1166,6 +1218,17 @@ var SarvamTransliterateModel = class {
1166
1218
  reasoning: void 0
1167
1219
  }
1168
1220
  },
1221
+ request: { body: args },
1222
+ response: {
1223
+ id: response.request_id ?? void 0,
1224
+ headers: responseHeaders,
1225
+ body: rawResponse
1226
+ },
1227
+ providerMetadata: { sarvam: {
1228
+ request_id: response.request_id,
1229
+ source_language_code: response.source_language_code,
1230
+ transliterated_text: response.transliterated_text
1231
+ } },
1169
1232
  warnings: []
1170
1233
  };
1171
1234
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "sarvam-ai-sdk",
3
3
  "type": "module",
4
4
  "description": "Sarvam provider support for Vercel's AI-SDK",
5
- "version": "0.3.0",
5
+ "version": "0.3.4",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "build:watch": "tsdown --watch",
15
15
  "type-check": "tsc --noEmit",
16
16
  "check": "biome check",
17
- "test": "tsx --env-file=.env test/index.ts"
17
+ "test": "bun test"
18
18
  },
19
19
  "exports": {
20
20
  "./package.json": "./package.json",