sarvamai 1.1.11-alpha.2 → 1.1.11
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 +19 -0
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +3 -0
- package/dist/cjs/Client.js +5 -0
- package/dist/cjs/api/errors/GatewayTimeoutError.d.ts +6 -0
- package/dist/cjs/api/errors/GatewayTimeoutError.js +54 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +1 -0
- package/dist/cjs/api/resources/chat/client/requests/CreateChatCompletionV2Request.d.ts +17 -24
- package/dist/cjs/api/resources/chatCompletion/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/chatCompletion/client/Client.js +1 -4
- package/dist/cjs/api/resources/index.d.ts +2 -0
- package/dist/cjs/api/resources/index.js +3 -1
- package/dist/cjs/api/resources/pronunciationDictionary/client/Client.d.ts +1 -1
- package/dist/cjs/api/resources/pronunciationDictionary/client/Client.js +1 -1
- package/dist/cjs/api/resources/responses/client/Client.d.ts +20 -1
- package/dist/cjs/api/resources/responses/client/Client.js +136 -28
- package/dist/cjs/api/resources/responses/client/requests/ResponsesCreateRequest.d.ts +59 -0
- package/dist/cjs/api/resources/responses/client/requests/ResponsesCreateStreamRequest.d.ts +59 -0
- package/dist/cjs/api/resources/responses/client/requests/ResponsesCreateStreamRequest.js +3 -0
- package/dist/cjs/api/resources/responses/client/requests/index.d.ts +2 -1
- package/dist/cjs/api/resources/speechToTextRealtimeStreaming/client/Client.d.ts +1 -0
- package/dist/cjs/api/resources/speechToTextRealtimeStreaming/client/Client.js +2 -1
- package/dist/cjs/api/resources/speechToTextStreaming/types/SpeechToTextStreamingModel.d.ts +2 -2
- package/dist/cjs/api/resources/speechToTextStreaming/types/SpeechToTextStreamingModel.js +2 -2
- package/dist/cjs/api/resources/text/client/Client.d.ts +24 -0
- package/dist/cjs/api/resources/text/client/Client.js +24 -0
- package/dist/cjs/api/resources/textToSpeech/client/Client.d.ts +4 -3
- package/dist/cjs/api/resources/textToSpeech/client/Client.js +4 -3
- package/dist/cjs/api/resources/textToSpeech/client/requests/TextToSpeechRequest.d.ts +20 -10
- package/dist/cjs/api/resources/textToSpeech/client/requests/TextToSpeechStreamRequest.d.ts +4 -3
- package/dist/cjs/api/resources/textToSpeechStreaming/types/TextToSpeechStreamingModel.d.ts +3 -1
- package/dist/cjs/api/resources/textToSpeechStreaming/types/TextToSpeechStreamingModel.js +3 -1
- package/dist/cjs/api/resources/voiceCloning/client/Client.d.ts +147 -0
- package/dist/cjs/api/resources/voiceCloning/client/Client.js +468 -0
- package/dist/cjs/api/resources/voiceCloning/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/voiceCloning/client/index.js +17 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/CreateVoiceRequest.d.ts +39 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/CreateVoiceRequest.js +17 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/ListVoicesRequest.d.ts +22 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/ListVoicesRequest.js +3 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/VoiceCloningTextToSpeechRequest.d.ts +63 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/VoiceCloningTextToSpeechRequest.js +3 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/index.d.ts +3 -0
- package/dist/cjs/api/resources/voiceCloning/client/requests/index.js +5 -0
- package/dist/cjs/api/resources/voiceCloning/exports.d.ts +2 -0
- package/dist/cjs/api/resources/voiceCloning/exports.js +21 -0
- package/dist/cjs/api/resources/voiceCloning/index.d.ts +1 -0
- package/dist/cjs/api/resources/voiceCloning/index.js +17 -0
- package/dist/cjs/api/types/ChatCompletionMessageToolCall.d.ts +1 -1
- package/dist/cjs/api/types/ChatCompletionResponseMessage.d.ts +2 -2
- package/dist/cjs/api/types/ChatStreamOptions.d.ts +1 -1
- package/dist/cjs/api/types/Choice.d.ts +1 -0
- package/dist/cjs/api/types/CompletionUsage.d.ts +10 -1
- package/dist/cjs/api/types/ConfigureConnection.d.ts +240 -12
- package/dist/cjs/api/types/ConfigureConnection.js +227 -2
- package/dist/cjs/api/types/CreateChatCompletionV2Response.d.ts +1 -0
- package/dist/cjs/api/types/CreateResponseV2Request.d.ts +54 -0
- package/dist/cjs/api/types/CreateResponseV2Request.js +3 -0
- package/dist/cjs/api/types/CreateResponseV2Response.d.ts +61 -1
- package/dist/cjs/api/types/ErrorCode.d.ts +3 -0
- package/dist/cjs/api/types/ErrorCode.js +3 -0
- package/dist/cjs/api/types/ImageUrl.d.ts +1 -0
- package/dist/cjs/api/types/ReasoningEffort.d.ts +1 -5
- package/dist/cjs/api/types/ReasoningEffort.js +1 -5
- package/dist/cjs/api/types/ResponseConversation.d.ts +4 -0
- package/dist/cjs/api/types/ResponseConversation.js +3 -0
- package/dist/cjs/api/types/ResponseInput.d.ts +5 -0
- package/dist/cjs/api/types/ResponseInput.js +3 -0
- package/dist/cjs/api/types/ResponseInputTextPart.d.ts +3 -0
- package/dist/cjs/api/types/ResponseReasoning.d.ts +2 -2
- package/dist/cjs/api/types/ResponseReasoningEffort.d.ts +2 -5
- package/dist/cjs/api/types/ResponseReasoningEffort.js +2 -5
- package/dist/cjs/api/types/ResponseStreamEvent.d.ts +9 -0
- package/dist/cjs/api/types/ResponseStreamEvent.js +3 -0
- package/dist/cjs/api/types/ResponseUsage.d.ts +7 -1
- package/dist/cjs/api/types/ResponsesModelIds.d.ts +15 -0
- package/dist/cjs/api/types/ResponsesModelIds.js +18 -0
- package/dist/cjs/api/types/SpeechToTextBatchModel.d.ts +2 -2
- package/dist/cjs/api/types/SpeechToTextBatchModel.js +2 -2
- package/dist/cjs/api/types/SpeechToTextModel.d.ts +2 -2
- package/dist/cjs/api/types/SpeechToTextModel.js +2 -2
- package/dist/cjs/api/types/StopConfiguration.d.ts +1 -2
- package/dist/cjs/api/types/TextToSpeechModel.d.ts +1 -0
- package/dist/cjs/api/types/TextToSpeechModel.js +1 -0
- package/dist/cjs/api/types/TextToSpeechSpeaker.d.ts +222 -0
- package/dist/cjs/api/types/TextToSpeechSpeaker.js +222 -0
- package/dist/cjs/api/types/V2ModelIds.d.ts +4 -6
- package/dist/cjs/api/types/V2ModelIds.js +4 -6
- package/dist/cjs/api/types/VoiceCloningLanguage.d.ts +15 -0
- package/dist/cjs/api/types/VoiceCloningLanguage.js +18 -0
- package/dist/cjs/api/types/VoiceCloningOutputAudioCodec.d.ts +12 -0
- package/dist/cjs/api/types/VoiceCloningOutputAudioCodec.js +15 -0
- package/dist/cjs/api/types/VoiceCloningResponse.d.ts +8 -0
- package/dist/cjs/api/types/VoiceCloningResponse.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryCreateData.d.ts +8 -0
- package/dist/cjs/api/types/VoiceLibraryCreateData.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryCreateResponse.d.ts +6 -0
- package/dist/cjs/api/types/VoiceLibraryCreateResponse.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryDetail.d.ts +15 -0
- package/dist/cjs/api/types/VoiceLibraryDetail.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryDetailResponse.d.ts +6 -0
- package/dist/cjs/api/types/VoiceLibraryDetailResponse.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryListData.d.ts +6 -0
- package/dist/cjs/api/types/VoiceLibraryListData.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryListResponse.d.ts +6 -0
- package/dist/cjs/api/types/VoiceLibraryListResponse.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryPreviewItem.d.ts +7 -0
- package/dist/cjs/api/types/VoiceLibraryPreviewItem.js +3 -0
- package/dist/cjs/api/types/VoiceLibraryVoice.d.ts +21 -0
- package/dist/cjs/api/types/VoiceLibraryVoice.js +3 -0
- package/dist/cjs/api/types/index.d.ts +16 -0
- package/dist/cjs/api/types/index.js +16 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +1 -0
- package/dist/cjs/core/stream/Stream.d.ts +56 -0
- package/dist/cjs/core/stream/Stream.js +267 -0
- package/dist/cjs/core/stream/index.d.ts +1 -0
- package/dist/cjs/core/stream/index.js +5 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +3 -0
- package/dist/esm/Client.mjs +5 -0
- package/dist/esm/api/errors/GatewayTimeoutError.d.mts +6 -0
- package/dist/esm/api/errors/GatewayTimeoutError.mjs +17 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/resources/chat/client/requests/CreateChatCompletionV2Request.d.mts +17 -24
- package/dist/esm/api/resources/chatCompletion/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/chatCompletion/client/Client.mjs +1 -4
- package/dist/esm/api/resources/index.d.mts +2 -0
- package/dist/esm/api/resources/index.mjs +2 -0
- package/dist/esm/api/resources/pronunciationDictionary/client/Client.d.mts +1 -1
- package/dist/esm/api/resources/pronunciationDictionary/client/Client.mjs +1 -1
- package/dist/esm/api/resources/responses/client/Client.d.mts +20 -1
- package/dist/esm/api/resources/responses/client/Client.mjs +136 -28
- package/dist/esm/api/resources/responses/client/requests/ResponsesCreateRequest.d.mts +59 -0
- package/dist/esm/api/resources/responses/client/requests/ResponsesCreateStreamRequest.d.mts +59 -0
- package/dist/esm/api/resources/responses/client/requests/ResponsesCreateStreamRequest.mjs +2 -0
- package/dist/esm/api/resources/responses/client/requests/index.d.mts +2 -1
- package/dist/esm/api/resources/speechToTextRealtimeStreaming/client/Client.d.mts +1 -0
- package/dist/esm/api/resources/speechToTextRealtimeStreaming/client/Client.mjs +2 -1
- package/dist/esm/api/resources/speechToTextStreaming/types/SpeechToTextStreamingModel.d.mts +2 -2
- package/dist/esm/api/resources/speechToTextStreaming/types/SpeechToTextStreamingModel.mjs +2 -2
- package/dist/esm/api/resources/text/client/Client.d.mts +24 -0
- package/dist/esm/api/resources/text/client/Client.mjs +24 -0
- package/dist/esm/api/resources/textToSpeech/client/Client.d.mts +4 -3
- package/dist/esm/api/resources/textToSpeech/client/Client.mjs +4 -3
- package/dist/esm/api/resources/textToSpeech/client/requests/TextToSpeechRequest.d.mts +20 -10
- package/dist/esm/api/resources/textToSpeech/client/requests/TextToSpeechStreamRequest.d.mts +4 -3
- package/dist/esm/api/resources/textToSpeechStreaming/types/TextToSpeechStreamingModel.d.mts +3 -1
- package/dist/esm/api/resources/textToSpeechStreaming/types/TextToSpeechStreamingModel.mjs +3 -1
- package/dist/esm/api/resources/voiceCloning/client/Client.d.mts +147 -0
- package/dist/esm/api/resources/voiceCloning/client/Client.mjs +431 -0
- package/dist/esm/api/resources/voiceCloning/client/index.d.mts +1 -0
- package/dist/esm/api/resources/voiceCloning/client/index.mjs +1 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/CreateVoiceRequest.d.mts +39 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/CreateVoiceRequest.mjs +14 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/ListVoicesRequest.d.mts +22 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/ListVoicesRequest.mjs +2 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/VoiceCloningTextToSpeechRequest.d.mts +63 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/VoiceCloningTextToSpeechRequest.mjs +2 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/index.d.mts +3 -0
- package/dist/esm/api/resources/voiceCloning/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/voiceCloning/exports.d.mts +2 -0
- package/dist/esm/api/resources/voiceCloning/exports.mjs +3 -0
- package/dist/esm/api/resources/voiceCloning/index.d.mts +1 -0
- package/dist/esm/api/resources/voiceCloning/index.mjs +1 -0
- package/dist/esm/api/types/ChatCompletionMessageToolCall.d.mts +1 -1
- package/dist/esm/api/types/ChatCompletionResponseMessage.d.mts +2 -2
- package/dist/esm/api/types/ChatStreamOptions.d.mts +1 -1
- package/dist/esm/api/types/Choice.d.mts +1 -0
- package/dist/esm/api/types/CompletionUsage.d.mts +10 -1
- package/dist/esm/api/types/ConfigureConnection.d.mts +240 -12
- package/dist/esm/api/types/ConfigureConnection.mjs +227 -2
- package/dist/esm/api/types/CreateChatCompletionV2Response.d.mts +1 -0
- package/dist/esm/api/types/CreateResponseV2Request.d.mts +54 -0
- package/dist/esm/api/types/CreateResponseV2Request.mjs +2 -0
- package/dist/esm/api/types/CreateResponseV2Response.d.mts +61 -1
- package/dist/esm/api/types/ErrorCode.d.mts +3 -0
- package/dist/esm/api/types/ErrorCode.mjs +3 -0
- package/dist/esm/api/types/ImageUrl.d.mts +1 -0
- package/dist/esm/api/types/ReasoningEffort.d.mts +1 -5
- package/dist/esm/api/types/ReasoningEffort.mjs +1 -5
- package/dist/esm/api/types/ResponseConversation.d.mts +4 -0
- package/dist/esm/api/types/ResponseConversation.mjs +2 -0
- package/dist/esm/api/types/ResponseInput.d.mts +5 -0
- package/dist/esm/api/types/ResponseInput.mjs +2 -0
- package/dist/esm/api/types/ResponseInputTextPart.d.mts +3 -0
- package/dist/esm/api/types/ResponseReasoning.d.mts +2 -2
- package/dist/esm/api/types/ResponseReasoningEffort.d.mts +2 -5
- package/dist/esm/api/types/ResponseReasoningEffort.mjs +2 -5
- package/dist/esm/api/types/ResponseStreamEvent.d.mts +9 -0
- package/dist/esm/api/types/ResponseStreamEvent.mjs +2 -0
- package/dist/esm/api/types/ResponseUsage.d.mts +7 -1
- package/dist/esm/api/types/ResponsesModelIds.d.mts +15 -0
- package/dist/esm/api/types/ResponsesModelIds.mjs +15 -0
- package/dist/esm/api/types/SpeechToTextBatchModel.d.mts +2 -2
- package/dist/esm/api/types/SpeechToTextBatchModel.mjs +2 -2
- package/dist/esm/api/types/SpeechToTextModel.d.mts +2 -2
- package/dist/esm/api/types/SpeechToTextModel.mjs +2 -2
- package/dist/esm/api/types/StopConfiguration.d.mts +1 -2
- package/dist/esm/api/types/TextToSpeechModel.d.mts +1 -0
- package/dist/esm/api/types/TextToSpeechModel.mjs +1 -0
- package/dist/esm/api/types/TextToSpeechSpeaker.d.mts +222 -0
- package/dist/esm/api/types/TextToSpeechSpeaker.mjs +222 -0
- package/dist/esm/api/types/V2ModelIds.d.mts +4 -6
- package/dist/esm/api/types/V2ModelIds.mjs +4 -6
- package/dist/esm/api/types/VoiceCloningLanguage.d.mts +15 -0
- package/dist/esm/api/types/VoiceCloningLanguage.mjs +15 -0
- package/dist/esm/api/types/VoiceCloningOutputAudioCodec.d.mts +12 -0
- package/dist/esm/api/types/VoiceCloningOutputAudioCodec.mjs +12 -0
- package/dist/esm/api/types/VoiceCloningResponse.d.mts +8 -0
- package/dist/esm/api/types/VoiceCloningResponse.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryCreateData.d.mts +8 -0
- package/dist/esm/api/types/VoiceLibraryCreateData.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryCreateResponse.d.mts +6 -0
- package/dist/esm/api/types/VoiceLibraryCreateResponse.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryDetail.d.mts +15 -0
- package/dist/esm/api/types/VoiceLibraryDetail.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryDetailResponse.d.mts +6 -0
- package/dist/esm/api/types/VoiceLibraryDetailResponse.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryListData.d.mts +6 -0
- package/dist/esm/api/types/VoiceLibraryListData.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryListResponse.d.mts +6 -0
- package/dist/esm/api/types/VoiceLibraryListResponse.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryPreviewItem.d.mts +7 -0
- package/dist/esm/api/types/VoiceLibraryPreviewItem.mjs +2 -0
- package/dist/esm/api/types/VoiceLibraryVoice.d.mts +21 -0
- package/dist/esm/api/types/VoiceLibraryVoice.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +16 -0
- package/dist/esm/api/types/index.mjs +16 -0
- package/dist/esm/core/index.d.mts +1 -0
- package/dist/esm/core/index.mjs +1 -0
- package/dist/esm/core/stream/Stream.d.mts +56 -0
- package/dist/esm/core/stream/Stream.mjs +262 -0
- package/dist/esm/core/stream/index.d.mts +1 -0
- package/dist/esm/core/stream/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +13 -1
- package/reference.md +493 -13
- package/dist/cjs/api/resources/responses/client/requests/CreateResponseV2Request.d.ts +0 -60
- package/dist/esm/api/resources/responses/client/requests/CreateResponseV2Request.d.mts +0 -60
- /package/dist/cjs/api/resources/responses/client/requests/{CreateResponseV2Request.js → ResponsesCreateRequest.js} +0 -0
- /package/dist/esm/api/resources/responses/client/requests/{CreateResponseV2Request.mjs → ResponsesCreateRequest.mjs} +0 -0
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ The Sarvam TypeScript library provides convenient access to the Sarvam APIs from
|
|
|
13
13
|
- [Usage](#usage)
|
|
14
14
|
- [Request and Response Types](#request-and-response-types)
|
|
15
15
|
- [Exception Handling](#exception-handling)
|
|
16
|
+
- [Streaming Response](#streaming-response)
|
|
16
17
|
- [File Uploads](#file-uploads)
|
|
17
18
|
- [Binary Response](#binary-response)
|
|
18
19
|
- [Advanced](#advanced)
|
|
@@ -94,6 +95,24 @@ try {
|
|
|
94
95
|
}
|
|
95
96
|
```
|
|
96
97
|
|
|
98
|
+
## Streaming Response
|
|
99
|
+
|
|
100
|
+
Some endpoints return streaming responses instead of returning the full response at once.
|
|
101
|
+
The SDK uses async iterators, so you can consume the responses using a `for await...of` loop.
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { SarvamAIClient } from "sarvamai";
|
|
105
|
+
|
|
106
|
+
const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_API_SUBSCRIPTION_KEY" });
|
|
107
|
+
const response = await client.responses.createStream({
|
|
108
|
+
model: "sarvam-105b",
|
|
109
|
+
input: "input"
|
|
110
|
+
});
|
|
111
|
+
for await (const item of response) {
|
|
112
|
+
console.log(item);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
97
116
|
## File Uploads
|
|
98
117
|
|
|
99
118
|
You can upload files using the client:
|
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "sarvamai",
|
|
46
|
-
"X-Fern-SDK-Version": "1.1.11
|
|
47
|
-
"User-Agent": "sarvamai/1.1.11
|
|
46
|
+
"X-Fern-SDK-Version": "1.1.11",
|
|
47
|
+
"User-Agent": "sarvamai/1.1.11",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/cjs/Client.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { SpeechToTextTranslateStreamingClient } from "./api/resources/speechToTe
|
|
|
15
15
|
import { TextClient } from "./api/resources/text/client/Client.js";
|
|
16
16
|
import { TextToSpeechClient } from "./api/resources/textToSpeech/client/Client.js";
|
|
17
17
|
import { TextToSpeechStreamingClient } from "./api/resources/textToSpeechStreaming/client/Client.js";
|
|
18
|
+
import { VoiceCloningClient } from "./api/resources/voiceCloning/client/Client.js";
|
|
18
19
|
import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
|
|
19
20
|
import { type NormalizedClientOptionsWithAuth } from "./BaseClient.js";
|
|
20
21
|
export declare namespace SarvamAIClient {
|
|
@@ -29,6 +30,7 @@ export declare class SarvamAIClient {
|
|
|
29
30
|
protected _text: TextClient | undefined;
|
|
30
31
|
protected _speechToText: SpeechToTextClient | undefined;
|
|
31
32
|
protected _textToSpeech: TextToSpeechClient | undefined;
|
|
33
|
+
protected _voiceCloning: VoiceCloningClient | undefined;
|
|
32
34
|
protected _pronunciationDictionary: PronunciationDictionaryClient | undefined;
|
|
33
35
|
protected _chat: ChatClient | undefined;
|
|
34
36
|
protected _speechToTextJob: SpeechToTextJobClient | undefined;
|
|
@@ -47,6 +49,7 @@ export declare class SarvamAIClient {
|
|
|
47
49
|
get text(): TextClient;
|
|
48
50
|
get speechToText(): SpeechToTextClient;
|
|
49
51
|
get textToSpeech(): TextToSpeechClient;
|
|
52
|
+
get voiceCloning(): VoiceCloningClient;
|
|
50
53
|
get pronunciationDictionary(): PronunciationDictionaryClient;
|
|
51
54
|
get chat(): ChatClient;
|
|
52
55
|
get speechToTextJob(): SpeechToTextJobClient;
|
package/dist/cjs/Client.js
CHANGED
|
@@ -19,6 +19,7 @@ const Client_js_14 = require("./api/resources/speechToTextTranslateStreaming/cli
|
|
|
19
19
|
const Client_js_15 = require("./api/resources/text/client/Client.js");
|
|
20
20
|
const Client_js_16 = require("./api/resources/textToSpeech/client/Client.js");
|
|
21
21
|
const Client_js_17 = require("./api/resources/textToSpeechStreaming/client/Client.js");
|
|
22
|
+
const Client_js_18 = require("./api/resources/voiceCloning/client/Client.js");
|
|
22
23
|
const BaseClient_js_1 = require("./BaseClient.js");
|
|
23
24
|
class SarvamAIClient {
|
|
24
25
|
constructor(options = {}) {
|
|
@@ -44,6 +45,10 @@ class SarvamAIClient {
|
|
|
44
45
|
var _a;
|
|
45
46
|
return ((_a = this._textToSpeech) !== null && _a !== void 0 ? _a : (this._textToSpeech = new Client_js_16.TextToSpeechClient(this._options)));
|
|
46
47
|
}
|
|
48
|
+
get voiceCloning() {
|
|
49
|
+
var _a;
|
|
50
|
+
return ((_a = this._voiceCloning) !== null && _a !== void 0 ? _a : (this._voiceCloning = new Client_js_18.VoiceCloningClient(this._options)));
|
|
51
|
+
}
|
|
47
52
|
get pronunciationDictionary() {
|
|
48
53
|
var _a;
|
|
49
54
|
return ((_a = this._pronunciationDictionary) !== null && _a !== void 0 ? _a : (this._pronunciationDictionary = new Client_js_7.PronunciationDictionaryClient(this._options)));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as core from "../../core/index.js";
|
|
2
|
+
import * as errors from "../../errors/index.js";
|
|
3
|
+
import type * as SarvamAI from "../index.js";
|
|
4
|
+
export declare class GatewayTimeoutError extends errors.SarvamAIError {
|
|
5
|
+
constructor(body: SarvamAI.ErrorMessage, rawResponse?: core.RawResponse);
|
|
6
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.GatewayTimeoutError = void 0;
|
|
38
|
+
const errors = __importStar(require("../../errors/index.js"));
|
|
39
|
+
class GatewayTimeoutError extends errors.SarvamAIError {
|
|
40
|
+
constructor(body, rawResponse) {
|
|
41
|
+
super({
|
|
42
|
+
message: "GatewayTimeoutError",
|
|
43
|
+
statusCode: 504,
|
|
44
|
+
body: body,
|
|
45
|
+
rawResponse: rawResponse,
|
|
46
|
+
});
|
|
47
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
48
|
+
if (Error.captureStackTrace) {
|
|
49
|
+
Error.captureStackTrace(this, this.constructor);
|
|
50
|
+
}
|
|
51
|
+
this.name = this.constructor.name;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.GatewayTimeoutError = GatewayTimeoutError;
|
|
@@ -3,6 +3,7 @@ export * from "./BadRequestError.js";
|
|
|
3
3
|
export * from "./ConflictError.js";
|
|
4
4
|
export * from "./ContentTooLargeError.js";
|
|
5
5
|
export * from "./ForbiddenError.js";
|
|
6
|
+
export * from "./GatewayTimeoutError.js";
|
|
6
7
|
export * from "./InternalServerError.js";
|
|
7
8
|
export * from "./NotFoundError.js";
|
|
8
9
|
export * from "./PaymentRequiredError.js";
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./BadRequestError.js"), exports);
|
|
|
19
19
|
__exportStar(require("./ConflictError.js"), exports);
|
|
20
20
|
__exportStar(require("./ContentTooLargeError.js"), exports);
|
|
21
21
|
__exportStar(require("./ForbiddenError.js"), exports);
|
|
22
|
+
__exportStar(require("./GatewayTimeoutError.js"), exports);
|
|
22
23
|
__exportStar(require("./InternalServerError.js"), exports);
|
|
23
24
|
__exportStar(require("./NotFoundError.js"), exports);
|
|
24
25
|
__exportStar(require("./PaymentRequiredError.js"), exports);
|
|
@@ -10,34 +10,23 @@ import type * as SarvamAI from "../../../../index.js";
|
|
|
10
10
|
* }
|
|
11
11
|
*/
|
|
12
12
|
export interface CreateChatCompletionV2Request {
|
|
13
|
-
/**
|
|
13
|
+
/** Non-empty conversation history. Roles: `system`, `developer`, `user`, `assistant`, `tool`. Content is a string or an array of parts (`text`, `image_url`). Images must use inline `data:image/…;base64,…` URLs — remote HTTP(S) image URLs are rejected. */
|
|
14
14
|
messages: SarvamAI.ChatCompletionRequestMessage[];
|
|
15
15
|
model: SarvamAI.V2ModelIds;
|
|
16
|
-
/**
|
|
17
|
-
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
|
|
18
|
-
* We generally recommend altering this or `top_p` but not both.
|
|
19
|
-
*/
|
|
16
|
+
/** Sampling temperature from `0` to `2`. Higher values increase variation; lower values focus the output. Output is not guaranteed to be identical across requests, even at `0`. Prefer changing either `temperature` or `top_p`, not both. */
|
|
20
17
|
temperature?: number;
|
|
21
|
-
/**
|
|
22
|
-
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
|
|
23
|
-
*
|
|
24
|
-
* Must be greater than 0 and at most 1. `0` is invalid; current serving returns `503 model_overloaded` rather than a clean `400`. Prefer altering this or `temperature` but not both.
|
|
25
|
-
*/
|
|
18
|
+
/** Nucleus sampling: greater than `0` and at most `1`. On `glm5.3`, `top_p: 0` is rejected. Prefer changing either `top_p` or `temperature`, not both. */
|
|
26
19
|
top_p?: number;
|
|
27
|
-
/**
|
|
20
|
+
/** On reasoning models (`glm5.3`, `deepseekv4-flash`): **`low`**, **`high`**, or **`max`**. Default when omitted is **`max`** — omit this field or set **`max`** for maximum reasoning. Trace in `message.reasoning_content`; billed as completion tokens and counts toward `max_tokens`. Ignored on non-reasoning models such as `gemma4`. */
|
|
28
21
|
reasoning_effort?: SarvamAI.ReasoningEffort;
|
|
29
|
-
/**
|
|
22
|
+
/** Maximum tokens to generate in the completion, including reasoning tokens on reasoning models. Default `2048`. Set explicitly when you need longer answers — a low limit can yield `finish_reason: "length"` with little or no visible `content` if reasoning consumes the budget. */
|
|
30
23
|
max_tokens?: number;
|
|
31
|
-
/**
|
|
24
|
+
/** Optional. Default `false` — omit or `false` for one JSON response. If `true`, the response is streamed as server-sent events and ends with a `[DONE]` line. Use `stream_options.include_usage: true` to receive a final usage chunk (including `reasoning_tokens`). That chunk has an empty `choices` array — do not assume `choices[0]` is present on every event. */
|
|
32
25
|
stream?: boolean;
|
|
33
26
|
stop?: SarvamAI.StopConfiguration;
|
|
34
|
-
/**
|
|
27
|
+
/** Number of chat completion choices to generate per request. You are billed for tokens across all choices. Default `1`. On `glm5.3`, only `n: 1` is accepted; higher values return `400 invalid_request_error`. */
|
|
35
28
|
n?: number;
|
|
36
|
-
/**
|
|
37
|
-
* This feature is in Beta.
|
|
38
|
-
* If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
39
|
-
* Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
40
|
-
*/
|
|
29
|
+
/** Optional integer seed for OpenAI SDK compatibility. */
|
|
41
30
|
seed?: number;
|
|
42
31
|
/**
|
|
43
32
|
* Number between -2.0 and 2.0. Positive values penalize new tokens based on
|
|
@@ -53,20 +42,24 @@ export interface CreateChatCompletionV2Request {
|
|
|
53
42
|
presence_penalty?: number;
|
|
54
43
|
/** A list of tools the model may call. Currently, only functions are supported as a tool. */
|
|
55
44
|
tools?: SarvamAI.ChatCompletionTool[];
|
|
56
|
-
/** Controls
|
|
45
|
+
/** Controls tool calling: `auto`, `none`, `required`, or a named function object. `required` with an empty `tools` array returns `400`. A named function that is not listed in `tools` returns `400`. */
|
|
57
46
|
tool_choice?: SarvamAI.ToolChoiceOption;
|
|
58
47
|
/** An object specifying the format that the model must output. Setting `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees the model generates output matching the supplied JSON Schema. Setting `{ "type": "json_object" }` enables the older JSON mode, which guarantees valid JSON but not a specific schema. */
|
|
59
48
|
response_format?: SarvamAI.ResponseFormat;
|
|
60
|
-
/**
|
|
49
|
+
/** Additional model-specific options merged into the request. Must not duplicate a top-level field documented on this endpoint; duplicates return `400 invalid_request_error`. */
|
|
61
50
|
extra_body?: Record<string, unknown>;
|
|
62
|
-
/** Top-k sampling.
|
|
51
|
+
/** Top-k sampling. Omit or set to `-1` to disable. Values `>= 1` enable top-k; `0` is rejected. There is no documented upper bound. */
|
|
63
52
|
top_k?: number;
|
|
64
53
|
/** Minimum probability mass. Must be between 0 and 1 inclusive. Outside that range is `400`. */
|
|
65
54
|
min_p?: number;
|
|
66
55
|
/** Repetition penalty. Must be greater than 0 and at most 2. `0` and values above 2 are `400`. */
|
|
67
56
|
repetition_penalty?: number;
|
|
68
|
-
/**
|
|
57
|
+
/** **`false`** is correctly enforced (a single tool call) on **`gemma4`** and **`deepseekv4-flash`**. On **`glm5.3`** and **`sarvam-105b`**, **`false`** is accepted without error but is **not** enforced — the model may still return multiple tool calls in one turn. */
|
|
69
58
|
parallel_tool_calls?: boolean;
|
|
70
|
-
/** Only valid with `stream: true` (otherwise `400`).
|
|
59
|
+
/** Only valid with `stream: true` (otherwise `400`). Must be a top-level field, not inside `extra_body`. Use `{"include_usage": true}` to receive token usage in the final SSE chunk. */
|
|
71
60
|
stream_options?: SarvamAI.ChatStreamOptions;
|
|
61
|
+
/** If `true`, return log probabilities for output tokens (use with `top_logprobs`). Supported on **`sarvam-105b`** and **`gemma4`**. Not supported on **`glm5.3`** (`400` if enabled) or **`deepseekv4-flash`** (returns `503 model_overloaded` instead of a clean rejection — omit this field for that model). */
|
|
62
|
+
logprobs?: boolean;
|
|
63
|
+
/** How many top token log probabilities to return at each position when `logprobs` is `true` (otherwise **`400`**). Same model support as `logprobs`: works on `sarvam-105b` and `gemma4`; on `glm5.3` and `deepseekv4-flash`, omit entirely — do not send `0`, since many SDKs add it by default. */
|
|
64
|
+
top_logprobs?: number;
|
|
72
65
|
}
|
|
@@ -11,7 +11,7 @@ export declare class ChatCompletionClient {
|
|
|
11
11
|
protected readonly _options: NormalizedClientOptionsWithAuth<ChatCompletionClient.Options>;
|
|
12
12
|
constructor(options?: ChatCompletionClient.Options);
|
|
13
13
|
/**
|
|
14
|
-
* Lists the model IDs
|
|
14
|
+
* Lists the model IDs available for the V2 Chat Completion API.
|
|
15
15
|
*
|
|
16
16
|
* @param {ChatCompletionClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
17
17
|
*
|
|
@@ -27,7 +27,6 @@ export declare class ChatCompletionClient {
|
|
|
27
27
|
* @param {ChatCompletionClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
28
28
|
*
|
|
29
29
|
* @throws {@link SarvamAI.NotFoundError}
|
|
30
|
-
* @throws {@link SarvamAI.UnprocessableEntityError}
|
|
31
30
|
*
|
|
32
31
|
* @example
|
|
33
32
|
* await client.chatCompletion.getModelV2("model_id")
|
|
@@ -56,7 +56,7 @@ class ChatCompletionClient {
|
|
|
56
56
|
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Lists the model IDs
|
|
59
|
+
* Lists the model IDs available for the V2 Chat Completion API.
|
|
60
60
|
*
|
|
61
61
|
* @param {ChatCompletionClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
62
62
|
*
|
|
@@ -102,7 +102,6 @@ class ChatCompletionClient {
|
|
|
102
102
|
* @param {ChatCompletionClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
103
103
|
*
|
|
104
104
|
* @throws {@link SarvamAI.NotFoundError}
|
|
105
|
-
* @throws {@link SarvamAI.UnprocessableEntityError}
|
|
106
105
|
*
|
|
107
106
|
* @example
|
|
108
107
|
* await client.chatCompletion.getModelV2("model_id")
|
|
@@ -133,8 +132,6 @@ class ChatCompletionClient {
|
|
|
133
132
|
switch (_response.error.statusCode) {
|
|
134
133
|
case 404:
|
|
135
134
|
throw new SarvamAI.NotFoundError(_response.error.body, _response.rawResponse);
|
|
136
|
-
case 422:
|
|
137
|
-
throw new SarvamAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
138
135
|
default:
|
|
139
136
|
throw new errors.SarvamAIError({
|
|
140
137
|
statusCode: _response.error.statusCode,
|
|
@@ -32,3 +32,5 @@ export * from "./textToSpeech/client/requests/index.js";
|
|
|
32
32
|
export * as textToSpeech from "./textToSpeech/index.js";
|
|
33
33
|
export * as textToSpeechStreaming from "./textToSpeechStreaming/index.js";
|
|
34
34
|
export * from "./textToSpeechStreaming/types/index.js";
|
|
35
|
+
export * from "./voiceCloning/client/requests/index.js";
|
|
36
|
+
export * as voiceCloning from "./voiceCloning/index.js";
|
|
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.textToSpeechStreaming = exports.textToSpeech = exports.text = exports.speechToTextTranslateStreaming = exports.speechToTextTranslateJob = exports.speechToTextStreaming = exports.speechToTextRealtimeStreaming = exports.speechToTextJob = exports.speechToText = exports.responses = exports.pronunciationDictionary = exports.dubbing = exports.documentTranslation = exports.documentIntelligence = exports.docAi = exports.chatCompletion = exports.chat = void 0;
|
|
39
|
+
exports.voiceCloning = exports.textToSpeechStreaming = exports.textToSpeech = exports.text = exports.speechToTextTranslateStreaming = exports.speechToTextTranslateJob = exports.speechToTextStreaming = exports.speechToTextRealtimeStreaming = exports.speechToTextJob = exports.speechToText = exports.responses = exports.pronunciationDictionary = exports.dubbing = exports.documentTranslation = exports.documentIntelligence = exports.docAi = exports.chatCompletion = exports.chat = void 0;
|
|
40
40
|
__exportStar(require("./chat/client/requests/index.js"), exports);
|
|
41
41
|
exports.chat = __importStar(require("./chat/index.js"));
|
|
42
42
|
exports.chatCompletion = __importStar(require("./chatCompletion/index.js"));
|
|
@@ -71,3 +71,5 @@ __exportStar(require("./textToSpeech/client/requests/index.js"), exports);
|
|
|
71
71
|
exports.textToSpeech = __importStar(require("./textToSpeech/index.js"));
|
|
72
72
|
exports.textToSpeechStreaming = __importStar(require("./textToSpeechStreaming/index.js"));
|
|
73
73
|
__exportStar(require("./textToSpeechStreaming/types/index.js"), exports);
|
|
74
|
+
__exportStar(require("./voiceCloning/client/requests/index.js"), exports);
|
|
75
|
+
exports.voiceCloning = __importStar(require("./voiceCloning/index.js"));
|
|
@@ -27,7 +27,7 @@ export declare class PronunciationDictionaryClient {
|
|
|
27
27
|
list(requestOptions?: PronunciationDictionaryClient.RequestOptions): core.HttpResponsePromise<SarvamAI.PronunciationDictionaryGetResponse>;
|
|
28
28
|
private __list;
|
|
29
29
|
/**
|
|
30
|
-
* Upload a `.json` file to create a new pronunciation dictionary. Only supported by **bulbul:v3**.
|
|
30
|
+
* Upload a `.json` file to create a new pronunciation dictionary. Only supported by **bulbul:v3** and **bulbul:v4-flash**.
|
|
31
31
|
*
|
|
32
32
|
* The file should contain a JSON object with a `pronunciations` key mapping language codes to word-pronunciation pairs. See the [Pronunciation Dictionary guide](/api-reference-docs/api-guides-tutorials/text-to-speech/pronunciation-dictionary) for format details and examples.
|
|
33
33
|
*
|
|
@@ -118,7 +118,7 @@ class PronunciationDictionaryClient {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
* Upload a `.json` file to create a new pronunciation dictionary. Only supported by **bulbul:v3**.
|
|
121
|
+
* Upload a `.json` file to create a new pronunciation dictionary. Only supported by **bulbul:v3** and **bulbul:v4-flash**.
|
|
122
122
|
*
|
|
123
123
|
* The file should contain a JSON object with a `pronunciations` key mapping language codes to word-pronunciation pairs. See the [Pronunciation Dictionary guide](/api-reference-docs/api-guides-tutorials/text-to-speech/pronunciation-dictionary) for format details and examples.
|
|
124
124
|
*
|
|
@@ -2,10 +2,15 @@ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClie
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
|
|
3
3
|
import * as core from "../../../../core/index.js";
|
|
4
4
|
import * as SarvamAI from "../../../index.js";
|
|
5
|
+
import type { ResponsesCreateStreamRequest } from "./requests/ResponsesCreateStreamRequest.js";
|
|
5
6
|
export declare namespace ResponsesClient {
|
|
6
7
|
type Options = BaseClientOptions;
|
|
7
8
|
interface RequestOptions extends BaseRequestOptions {
|
|
8
9
|
}
|
|
10
|
+
interface StreamEvent {
|
|
11
|
+
type: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
15
|
export declare class ResponsesClient {
|
|
11
16
|
protected readonly _options: NormalizedClientOptionsWithAuth<ResponsesClient.Options>;
|
|
@@ -37,6 +42,20 @@ export declare class ResponsesClient {
|
|
|
37
42
|
* store: false
|
|
38
43
|
* })
|
|
39
44
|
*/
|
|
40
|
-
create(request: SarvamAI.CreateResponseV2Request
|
|
45
|
+
create(request: SarvamAI.CreateResponseV2Request & {
|
|
46
|
+
stream: true;
|
|
47
|
+
}, requestOptions?: ResponsesClient.RequestOptions): Promise<AsyncIterable<ResponsesClient.StreamEvent>>;
|
|
48
|
+
create(request: SarvamAI.CreateResponseV2Request & {
|
|
49
|
+
stream?: false | undefined;
|
|
50
|
+
}, requestOptions?: ResponsesClient.RequestOptions): core.HttpResponsePromise<SarvamAI.CreateResponseV2Response>;
|
|
51
|
+
create(request: SarvamAI.CreateResponseV2Request, requestOptions?: ResponsesClient.RequestOptions): core.HttpResponsePromise<SarvamAI.CreateResponseV2Response> | Promise<AsyncIterable<ResponsesClient.StreamEvent>>;
|
|
52
|
+
/**
|
|
53
|
+
* Create a streaming response. Prefer `create({ ..., stream: true })`; this
|
|
54
|
+
* alias is retained for parity with Fern-generated streaming clients.
|
|
55
|
+
*/
|
|
56
|
+
createStream(request: ResponsesCreateStreamRequest, requestOptions?: ResponsesClient.RequestOptions): Promise<AsyncIterable<ResponsesClient.StreamEvent>>;
|
|
57
|
+
private __createStream;
|
|
58
|
+
private _parseSSEStream;
|
|
59
|
+
private _throwStatusCodeError;
|
|
41
60
|
private __create;
|
|
42
61
|
}
|
|
@@ -42,9 +42,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
46
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
47
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
48
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
49
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
50
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
51
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
52
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
53
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
54
|
+
function fulfill(value) { resume("next", value); }
|
|
55
|
+
function reject(value) { resume("throw", value); }
|
|
56
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
57
|
+
};
|
|
45
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
59
|
exports.ResponsesClient = void 0;
|
|
47
60
|
const BaseClient_js_1 = require("../../../../BaseClient.js");
|
|
61
|
+
const RawResponse_js_1 = require("../../../../core/fetcher/RawResponse.js");
|
|
48
62
|
const headers_js_1 = require("../../../../core/headers.js");
|
|
49
63
|
const core = __importStar(require("../../../../core/index.js"));
|
|
50
64
|
const environments = __importStar(require("../../../../environments.js"));
|
|
@@ -55,36 +69,130 @@ class ResponsesClient {
|
|
|
55
69
|
constructor(options = {}) {
|
|
56
70
|
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
|
|
57
71
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates a model response using the OpenAI Responses protocol.
|
|
60
|
-
*
|
|
61
|
-
* Create-only and stateless: replay `input` every turn, and omit `store` or pass `false` (OpenAI SDKs default it to `true`, which is `400`).
|
|
62
|
-
*
|
|
63
|
-
* Same models, auth, beta gate, and quota as [`POST /v2/chat/completions`](/api-reference/chat/chat-completions-v2).
|
|
64
|
-
*
|
|
65
|
-
* @param {SarvamAI.CreateResponseV2Request} request
|
|
66
|
-
* @param {ResponsesClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
67
|
-
*
|
|
68
|
-
* @throws {@link SarvamAI.BadRequestError}
|
|
69
|
-
* @throws {@link SarvamAI.UnauthorizedError}
|
|
70
|
-
* @throws {@link SarvamAI.ForbiddenError}
|
|
71
|
-
* @throws {@link SarvamAI.NotFoundError}
|
|
72
|
-
* @throws {@link SarvamAI.ContentTooLargeError}
|
|
73
|
-
* @throws {@link SarvamAI.UnprocessableEntityError}
|
|
74
|
-
* @throws {@link SarvamAI.TooManyRequestsError}
|
|
75
|
-
* @throws {@link SarvamAI.BadGatewayError}
|
|
76
|
-
* @throws {@link SarvamAI.ServiceUnavailableError}
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* await client.responses.create({
|
|
80
|
-
* model: "glm5.3",
|
|
81
|
-
* input: "Summarise the causes of the 2008 financial crisis.",
|
|
82
|
-
* store: false
|
|
83
|
-
* })
|
|
84
|
-
*/
|
|
85
72
|
create(request, requestOptions) {
|
|
73
|
+
if (request.stream === true) {
|
|
74
|
+
return this.__createStream(request, requestOptions);
|
|
75
|
+
}
|
|
86
76
|
return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
|
|
87
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a streaming response. Prefer `create({ ..., stream: true })`; this
|
|
80
|
+
* alias is retained for parity with Fern-generated streaming clients.
|
|
81
|
+
*/
|
|
82
|
+
createStream(request, requestOptions) {
|
|
83
|
+
return this.__createStream(Object.assign(Object.assign({}, request), { stream: true }), requestOptions);
|
|
84
|
+
}
|
|
85
|
+
__createStream(request, requestOptions) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b, _c, _d, _e, _f;
|
|
88
|
+
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
89
|
+
const _headers = {};
|
|
90
|
+
for (const headers of [_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers]) {
|
|
91
|
+
if (!headers)
|
|
92
|
+
continue;
|
|
93
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
94
|
+
if (value != null) {
|
|
95
|
+
_headers[key] = String(value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_headers["Content-Type"] = "application/json";
|
|
100
|
+
_headers.Accept = "text/event-stream";
|
|
101
|
+
const baseUrl = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.SarvamAIEnvironment.Production).base;
|
|
102
|
+
const url = core.url.join(baseUrl, "v2/responses");
|
|
103
|
+
const fetchFn = (_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.fetch) !== null && _e !== void 0 ? _e : (typeof fetch !== "undefined" ? fetch : undefined);
|
|
104
|
+
if (!fetchFn) {
|
|
105
|
+
throw new Error("No fetch function available. Please provide a fetch function in client options.");
|
|
106
|
+
}
|
|
107
|
+
const response = yield fetchFn(url, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: _headers,
|
|
110
|
+
body: JSON.stringify(Object.assign(Object.assign({}, request), { stream: true })),
|
|
111
|
+
signal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
112
|
+
});
|
|
113
|
+
const contentType = (_f = response.headers.get("content-type")) !== null && _f !== void 0 ? _f : "";
|
|
114
|
+
if (!response.ok && !contentType.includes("text/event-stream")) {
|
|
115
|
+
const errorText = yield response.text();
|
|
116
|
+
let errorBody = errorText;
|
|
117
|
+
try {
|
|
118
|
+
errorBody = JSON.parse(errorText);
|
|
119
|
+
}
|
|
120
|
+
catch (_g) {
|
|
121
|
+
// Keep the raw text when the error body is not JSON.
|
|
122
|
+
}
|
|
123
|
+
this._throwStatusCodeError(response.status, errorBody, (0, RawResponse_js_1.toRawResponse)(response));
|
|
124
|
+
}
|
|
125
|
+
if (!response.body) {
|
|
126
|
+
throw new errors.SarvamAIError({ message: "Response body is null for streaming request." });
|
|
127
|
+
}
|
|
128
|
+
return this._parseSSEStream(response.body);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
_parseSSEStream(body) {
|
|
132
|
+
return __asyncGenerator(this, arguments, function* _parseSSEStream_1() {
|
|
133
|
+
var _a;
|
|
134
|
+
const reader = body.getReader();
|
|
135
|
+
const decoder = new TextDecoder();
|
|
136
|
+
let buffer = "";
|
|
137
|
+
try {
|
|
138
|
+
while (true) {
|
|
139
|
+
const { done, value } = yield __await(reader.read());
|
|
140
|
+
if (done)
|
|
141
|
+
break;
|
|
142
|
+
buffer += decoder.decode(value, { stream: true });
|
|
143
|
+
const lines = buffer.split("\n");
|
|
144
|
+
buffer = (_a = lines.pop()) !== null && _a !== void 0 ? _a : "";
|
|
145
|
+
for (const line of lines) {
|
|
146
|
+
const trimmed = line.trim();
|
|
147
|
+
if (!trimmed.startsWith("data: "))
|
|
148
|
+
continue;
|
|
149
|
+
try {
|
|
150
|
+
yield yield __await(JSON.parse(trimmed.slice(6)));
|
|
151
|
+
}
|
|
152
|
+
catch (_b) {
|
|
153
|
+
// Ignore malformed SSE data frames.
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const trailing = buffer.trim();
|
|
158
|
+
if (trailing.startsWith("data: ")) {
|
|
159
|
+
try {
|
|
160
|
+
yield yield __await(JSON.parse(trailing.slice(6)));
|
|
161
|
+
}
|
|
162
|
+
catch (_c) {
|
|
163
|
+
// Ignore malformed trailing data.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
reader.releaseLock();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
_throwStatusCodeError(statusCode, body, rawResponse) {
|
|
173
|
+
switch (statusCode) {
|
|
174
|
+
case 400:
|
|
175
|
+
throw new SarvamAI.BadRequestError(body, rawResponse);
|
|
176
|
+
case 401:
|
|
177
|
+
throw new SarvamAI.UnauthorizedError(body, rawResponse);
|
|
178
|
+
case 403:
|
|
179
|
+
throw new SarvamAI.ForbiddenError(body, rawResponse);
|
|
180
|
+
case 404:
|
|
181
|
+
throw new SarvamAI.NotFoundError(body, rawResponse);
|
|
182
|
+
case 413:
|
|
183
|
+
throw new SarvamAI.ContentTooLargeError(body, rawResponse);
|
|
184
|
+
case 422:
|
|
185
|
+
throw new SarvamAI.UnprocessableEntityError(body, rawResponse);
|
|
186
|
+
case 429:
|
|
187
|
+
throw new SarvamAI.TooManyRequestsError(body, rawResponse);
|
|
188
|
+
case 502:
|
|
189
|
+
throw new SarvamAI.BadGatewayError(body, rawResponse);
|
|
190
|
+
case 503:
|
|
191
|
+
throw new SarvamAI.ServiceUnavailableError(body, rawResponse);
|
|
192
|
+
default:
|
|
193
|
+
throw new errors.SarvamAIError({ statusCode, body, rawResponse });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
88
196
|
__create(request, requestOptions) {
|
|
89
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
198
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -97,7 +205,7 @@ class ResponsesClient {
|
|
|
97
205
|
contentType: "application/json",
|
|
98
206
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
99
207
|
requestType: "json",
|
|
100
|
-
body: request,
|
|
208
|
+
body: Object.assign(Object.assign({}, request), { stream: false }),
|
|
101
209
|
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
102
210
|
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
103
211
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type * as SarvamAI from "../../../../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @example
|
|
4
|
+
* {
|
|
5
|
+
* model: "sarvam-105b",
|
|
6
|
+
* input: "input"
|
|
7
|
+
* }
|
|
8
|
+
*/
|
|
9
|
+
export interface ResponsesCreateRequest {
|
|
10
|
+
model: SarvamAI.ResponsesModelIds;
|
|
11
|
+
input: SarvamAI.ResponseInput;
|
|
12
|
+
/** Maximum output tokens to generate, including reasoning tokens on reasoning models. If omitted, there is no default cap — generation is unbounded and continues until the model stops on its own or the context window fills. Always set this explicitly in production. Values above the model context window return `400`. */
|
|
13
|
+
max_output_tokens?: number;
|
|
14
|
+
/** Sampling temperature between 0 and 2. Default **`1`** on `glm5.3` when omitted. Output is not bit-reproducible, even at `0`. */
|
|
15
|
+
temperature?: number;
|
|
16
|
+
/** Must be `false` or omitted (omitting is `200` and echoed as `false`). `true` is `400 invalid_request_error` — nothing created here is retrievable. OpenAI SDKs default this to `true`, so a default `client.responses.create(...)` fails. */
|
|
17
|
+
store?: boolean;
|
|
18
|
+
/** Function tools use the **flat** Responses shape (`type`, `name`, `parameters`, `strict`) — the nested chat-completions tool shape is **`400`**. `tool_choice: required` with no tools returns **`400`**. Function `arguments` in output are a JSON **string** (parse before use). Multiple tool calls per turn are supported; use **`parallel_tool_calls: true`** or omit (see that field). */
|
|
19
|
+
tools?: SarvamAI.ResponseFunctionTool[];
|
|
20
|
+
/** Forwarded exactly as written: `none`, `auto`, `required`, `{ "type": "function", "name": "..." }`, or another object. */
|
|
21
|
+
tool_choice?: ResponsesCreateRequest.ToolChoice;
|
|
22
|
+
/** Optional reasoning config for `glm5.3` and `deepseekv4-flash`. On `glm5.3`, a reasoning item is always in `output` — read `summary[0].text`. **`effort`:** on `glm5.3`, `low` or `high` only — omit for `max`-level reasoning (the literal string `max` returns `400`); on `deepseekv4-flash`, `low`, `high`, or `max` all work directly. Optional **`summary`:** `auto` or `detailed`. */
|
|
23
|
+
reasoning?: SarvamAI.ResponseReasoning;
|
|
24
|
+
/** Merged into the outbound body. Must not overwrite any modelled field (`400`). `max_tool_calls` and `prompt` are `400` here and in `extra_body` — not supported by any serving deployment. */
|
|
25
|
+
extra_body?: Record<string, unknown>;
|
|
26
|
+
/** System-style instructions. Echoed back on the response object when set. */
|
|
27
|
+
instructions?: string;
|
|
28
|
+
/** Nucleus sampling. Default **`0.95`** on `glm5.3` when omitted. Must be greater than **`0`** and at most **`1`** (`0` is rejected on `glm5.3`). */
|
|
29
|
+
top_p?: number;
|
|
30
|
+
/** Top-k sampling on `glm5.3`. Omit or use **`-1`** to disable; values **`≥ 1`** enable top-k. **`0`** is rejected. */
|
|
31
|
+
top_k?: number;
|
|
32
|
+
/** Optional. Range `-2` to `2`. May be accepted and echoed on Responses without changing model output. */
|
|
33
|
+
frequency_penalty?: number;
|
|
34
|
+
/** Optional. Range `-2` to `2`. May be accepted and echoed on Responses without changing model output. */
|
|
35
|
+
presence_penalty?: number;
|
|
36
|
+
/** Output format. If you send `text`, `format` is required (`400` when missing). `json_object` and strict `json_schema` are honoured on `glm5.3` and skip the reasoning item. */
|
|
37
|
+
text?: SarvamAI.ResponseTextConfig;
|
|
38
|
+
/** Not currently enforced on this route for any model that supports tool calling here (`glm5.3`, `gemma4`, `deepseekv4-flash`). Setting **`false`** is accepted without error, but the model may still return multiple tool calls in one turn. */
|
|
39
|
+
parallel_tool_calls?: boolean;
|
|
40
|
+
/** **Ignored** on this route — Responses always returns one output. Accepted for OpenAI SDK compatibility only; omit or leave at `1`. */
|
|
41
|
+
n?: number;
|
|
42
|
+
/** **Ignored** on Responses. Accepted for SDK compatibility only. */
|
|
43
|
+
seed?: number;
|
|
44
|
+
/** `400 invalid_request_error`. This endpoint holds no state — replay the conversation in `input`. OpenAI and Fireworks use this to continue a chat; we do not. */
|
|
45
|
+
previous_response_id?: string;
|
|
46
|
+
conversation?: SarvamAI.ResponseConversation;
|
|
47
|
+
/** `true` is `400 invalid_request_error`. This endpoint is synchronous only. */
|
|
48
|
+
background?: boolean;
|
|
49
|
+
/** `400 invalid_request_error` — not supported by any serving deployment, top-level or via `extra_body`. */
|
|
50
|
+
max_tool_calls?: number;
|
|
51
|
+
/** Accepts any additional properties */
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
export declare namespace ResponsesCreateRequest {
|
|
55
|
+
/**
|
|
56
|
+
* Forwarded exactly as written: `none`, `auto`, `required`, `{ "type": "function", "name": "..." }`, or another object.
|
|
57
|
+
*/
|
|
58
|
+
type ToolChoice = SarvamAI.ToolChoiceOption | Record<string, unknown>;
|
|
59
|
+
}
|