| Name | sarvamai JSON |
| Version |
0.1.21
JSON |
| download |
| home_page | None |
| Summary | None |
| upload_time | 2025-10-07 07:37:47 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | <4.0,>=3.8 |
| license | None |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Sarvam Python Library
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsarvamai%2Fsarvam-python-sdk)
[](https://pypi.python.org/pypi/sarvamai)
The Sarvam Python library provides convenient access to the Sarvam API from Python.
## Documentation
API reference documentation is available [here](https://docs.sarvam.ai/api-reference-docs/speech-to-text/).
## Installation
```sh
pip install sarvamai
```
## Reference
A full reference for this library is available [here](#References).
## Usage
Instantiate and use the client with the following:
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.text.translate(
input="input",
source_language_code="auto",
target_language_code="bn-IN",
)
```
## Async Client
The SDK also exports an `async` client so that you can make non-blocking calls to our API.
```python
import asyncio
from sarvamai import AsyncSarvamAI
client = AsyncSarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
async def main() -> None:
await client.text.translate(
input="input",
source_language_code="auto",
target_language_code="bn-IN",
)
asyncio.run(main())
```
## Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.
```python
from sarvamai.core.api_error import ApiError
try:
client.text.translate(...)
except ApiError as e:
print(e.status_code)
print(e.body)
```
## Advanced
### Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
Use the `max_retries` request option to configure this behavior.
```python
client.text.translate(..., request_options={
"max_retries": 1
})
```
### Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
```python
from sarvamai import SarvamAI
client = SarvamAI(
...,
timeout=20.0,
)
# Override timeout for a specific method
client.text.translate(..., request_options={
"timeout_in_seconds": 1
})
```
### Custom Client
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
```python
import httpx
from sarvamai import SarvamAI
client = SarvamAI(
...,
httpx_client=httpx.Client(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
```
## Contributing
While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
---
## References
### Text
<details><summary><code>client.text.<a href="src/sarvamai/text/client.py">translate</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
**Translation** converts text from one language to another while preserving its meaning.
For Example: **'मैं ऑफिस जा रहा हूँ'** translates to **'I am going to the office'** in English, where the script and language change, but the original meaning remains the same.
Available languages:
- **`bn-IN`**: Bengali
- **`en-IN`**: English
- **`gu-IN`**: Gujarati
- **`hi-IN`**: Hindi
- **`kn-IN`**: Kannada
- **`ml-IN`**: Malayalam
- **`mr-IN`**: Marathi
- **`od-IN`**: Odia
- **`pa-IN`**: Punjabi
- **`ta-IN`**: Tamil
- **`te-IN`**: Telugu
#### Newly added languages:
- **`as-IN`**: Assamese
- **`brx-IN`**: Bodo
- **`doi-IN`**: Dogri
- **`kok-IN`**: Konkani
- **`ks-IN`**: Kashmiri
- **`mai-IN`**: Maithili
- **`mni-IN`**: Manipuri (Meiteilon)
- **`ne-IN`**: Nepali
- **`sa-IN`**: Sanskrit
- **`sat-IN`**: Santali
- **`sd-IN`**: Sindhi
- **`ur-IN`**: Urdu
For hands-on practice, you can explore the notebook tutorial on [Translate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/translate/Translate_API_Tutorial.ipynb).
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.text.translate(
input="input",
source_language_code="auto",
target_language_code="bn-IN",
)
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**input:** `str` — The text you want to translate is the input text that will be processed by the translation model. The maximum is 1000 characters for Mayura:v1 and 2000 characters for Sarvam-Translate:v1.
</dd>
</dl>
<dl>
<dd>
**source_language_code:** `TranslateSourceLanguage`
Source language code for translation input.
**mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu
**sarvam-translate:v1 Languages:** All mayura:v1 languages and Assamese, Bodo, Dogri, Konkani, Kashmiri, Maithili, Manipuri, Nepali, Sanskrit, Santali, Sindhi, Urdu
**Note:** mayura:v1 supports automatic language detection using 'auto' as the source language code.
</dd>
</dl>
<dl>
<dd>
**target_language_code:** `TranslateTargetLanguage`
The language code of the translated text. This specifies the target language for translation.
**mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu
**sarvam-translate:v1 Languages:** All mayura:v1 and Assamese, Bodo, Dogri, Konkani, Kashmiri, Maithili, Manipuri, Nepali, Sanskrit, Santali, Sindhi, Urdu
</dd>
</dl>
<dl>
<dd>
**speaker_gender:** `typing.Optional[TranslateSpeakerGender]` — Please specify the gender of the speaker for better translations.
</dd>
</dl>
<dl>
<dd>
**mode:** `typing.Optional[TranslateMode]`
Specifies the tone or style of the translation.
**Model Support:**
- **mayura:v1**: Supports formal, classic-colloquial, and modern-colloquial modes
- **sarvam-translate:v1**: Only formal mode is supported
**Default:** formal
</dd>
</dl>
<dl>
<dd>
**model:** `typing.Optional[TranslateModel]`
Specifies the translation model to use.
- mayura:v1: Supports 12 languages with all modes, output scripts, and automatic language detection.
- sarvam-translate:v1: Supports all 22 scheduled languages of India, formal mode only.
</dd>
</dl>
<dl>
<dd>
**enable_preprocessing:** `typing.Optional[bool]`
This will enable custom preprocessing of the input text which can result in better translations.
Recommendation- You can switch on whenever there is some complex text with difficult vocabulary and sentences, for which you want simple translations that people can understand.
</dd>
</dl>
<dl>
<dd>
**output_script:** `typing.Optional[TransliterateMode]`
**output_script**: This is an optional parameter which controls the transliteration style applied to the output text.
**Transliteration**: Converting text from one script to another while preserving pronunciation.
For mayura:v1 - We support transliteration with four options:
- **`null`**(default): No transliteration applied.
- **`roman`**: Transliteration in Romanized script.
- **`fully-native`**: Transliteration in the native script with formal style.
- **`spoken-form-in-native`**: Transliteration in the native script with spoken style.
For sarvam-translate:v1 - Transliteration is not supported.
#### Example:
English: Your EMI of Rs. 3000 is pending.
Default modern translation: आपका Rs. 3000 का EMI pending है (when `null` is passed).
With postprocessing enabled:
- **roman output**: aapka Rs. 3000 ka EMI pending hai.
</dd>
</dl>
<dl>
<dd>
**numerals_format:** `typing.Optional[NumeralsFormat]`
`numerals_format` is an optional parameter with two options (supported for both mayura:v1 and sarvam-translate:v1):
- **`international`** (default): Uses regular numerals (0-9).
- **`native`**: Uses language-specific native numerals.
#### Example:
- If `international` format is selected, we use regular numerals (0-9). For example: `मेरा phone number है: 9840950950`.
- If `native` format is selected, we use language-specific native numerals, like: `मेरा phone number है: ९८४०९५०९५०`.
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
<details><summary><code>client.text.<a href="src/sarvamai/text/client.py">identify_language</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
Identifies the language (e.g., en-IN, hi-IN) and script (e.g., Latin, Devanagari) of the input text, supporting multiple languages.
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.text.identify_language(
input="input",
)
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**input:** `str` — The text input for language and script identification.
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
<details><summary><code>client.text.<a href="src/sarvamai/text/client.py">transliterate</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
**Transliteration** converts text from one script to another while preserving the original pronunciation. For example, **'नमस्ते'** becomes **'namaste'** in English, and **'how are you'** can be written as **'हाउ आर यू'** in Devanagari. This process ensures that the sound of the original text remains intact, even when written in a different script.
Transliteration is useful when you want to represent words phonetically across different writing systems, such as converting **'मैं ऑफिस जा रहा हूँ'** to **'main office ja raha hun'** in English letters.
**Translation**, on the other hand, converts text from one language to another while preserving the meaning rather than pronunciation. For example, **'मैं ऑफिस जा रहा हूँ'** translates to **'I am going to the office'** in English, changing both the script and the language while conveying the intended message.
#### Examples of **Transliteration**:
- **'Good morning'** becomes **'गुड मॉर्निंग'** in Hindi, where the pronunciation is preserved but the meaning is not translated.
- **'सुप्रभात'** becomes **'suprabhat'** in English.
Available languages:
- **`en-IN`**: English
- **`hi-IN`**: Hindi
- **`bn-IN`**: Bengali
- **`gu-IN`**: Gujarati
- **`kn-IN`**: Kannada
- **`ml-IN`**: Malayalam
- **`mr-IN`**: Marathi
- **`od-IN`**: Odia
- **`pa-IN`**: Punjabi
- **`ta-IN`**: Tamil
- **`te-IN`**: Telugu
For hands-on practice, you can explore the notebook tutorial on [Transliterate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/transliterate/Transliterate_API_Tutorial.ipynb).
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.text.transliterate(
input="input",
source_language_code="auto",
target_language_code="bn-IN",
)
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**input:** `str` — The text you want to transliterate.
</dd>
</dl>
<dl>
<dd>
**source_language_code:** `TransliterateSourceLanguage`
The language code of the input text. This specifies the source language for transliteration.
Note: The source language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration.
</dd>
</dl>
<dl>
<dd>
**target_language_code:** `TranslatiterateTargetLanguage`
The language code of the transliteration text. This specifies the target language for transliteration.
Note:The target language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration.
</dd>
</dl>
<dl>
<dd>
**numerals_format:** `typing.Optional[NumeralsFormat]`
`numerals_format` is an optional parameter with two options:
- **`international`** (default): Uses regular numerals (0-9).
- **`native`**: Uses language-specific native numerals.
#### Example:
- If `international` format is selected, we use regular numerals (0-9). For example: `मेरा phone number है: 9840950950`.
- If `native` format is selected, we use language-specific native numerals, like: `मेरा phone number है: ९८४०९५०९५०`.
</dd>
</dl>
<dl>
<dd>
**spoken_form_numerals_language:** `typing.Optional[SpokenFormNumeralsFormat]`
`spoken_form_numerals_language` is an optional parameter with two options and only works when spoken_form is true:
- **`english`** : Numbers in the text will be spoken in English.
- **`native(default)`**: Numbers in the text will be spoken in the native language.
#### Examples:
- **Input:** "मेरे पास ₹200 है"
- If `english` format is selected: "मेरे पास टू हन्डर्ड रूपीस है"
- If `native` format is selected: "मेरे पास दो सौ रुपये है"
</dd>
</dl>
<dl>
<dd>
**spoken_form:** `typing.Optional[bool]`
- Default: `False`
- Converts text into a natural spoken form when `True`.
- **Note:** No effect if output language is `en-IN`.
#### Example:
- **Input:** `मुझे कल 9:30am को appointment है`
- **Output:** `मुझे कल सुबह साढ़े नौ बजे को अपॉइंटमेंट है`
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
### SpeechToText
<details><summary><code>client.speech_to_text.<a href="src/sarvamai/speech_to_text/client.py">transcribe</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
### Real-Time Speech to Text API
This API transcribes speech to text in multiple Indian languages and English. Supports real-time transcription for interactive applications.
#### Available Options:
- **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results
- **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt/stt-batch-api)
- Supports diarization (speaker identification)
#### Note:
- Pricing differs for Real-Time and Batch APIs
- Diarization is only available in Batch API with separate pricing
- Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.speech_to_text.transcribe()
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**file:** `from __future__ import annotations
core.File` — See core.File for more documentation
</dd>
</dl>
<dl>
<dd>
**model:** `typing.Optional[SpeechToTextModel]`
Specifies the model to use for speech-to-text conversion.
Note:- Default model is `saarika:v2`
</dd>
</dl>
<dl>
<dd>
**language_code:** `typing.Optional[SpeechToTextLanguage]`
Specifies the language of the input audio. This parameter is required to ensure accurate transcription.
For the `saarika:v1` model, this parameter is mandatory.
For the `saarika:v2` model, it is optional.
`unknown`: Use this when the language is not known; the API will detect it automatically.
Note:- that the `saarika:v1` model does not support `unknown` language code.
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
<details><summary><code>client.speech_to_text.<a href="src/sarvamai/speech_to_text/client.py">translate</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
### Real-Time Speech to Text Translation API
This API automatically detects the input language, transcribes the speech, and translates the text to English.
#### Available Options:
- **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results
- **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt-translate/stt-translate-batch-api)
- Supports diarization (speaker identification)
#### Note:
- Pricing differs for Real-Time and Batch APIs
- Diarization is only available in Batch API with separate pricing
- Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.speech_to_text.translate()
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**file:** `from __future__ import annotations
core.File` — See core.File for more documentation
</dd>
</dl>
<dl>
<dd>
**prompt:** `typing.Optional[str]` — Conversation context can be passed as a prompt to boost model accuracy. However, the current system is at an experimentation stage and doesn’t match the prompt performance of large language models.
</dd>
</dl>
<dl>
<dd>
**model:** `typing.Optional[SpeechToTextTranslateModel]` — Model to be used for converting speech to text in target language
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
### TextToSpeech
<details><summary><code>client.text_to_speech.<a href="src/sarvamai/text_to_speech/client.py">convert</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
This is the model to convert text into spoken audio.
The output is a wave file encoded as a base64 string.
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.text_to_speech.convert(
text="text",
target_language_code="bn-IN",
)
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**text:** `str`
</dd>
</dl>
<dl>
<dd>
**target_language_code:** `TextToSpeechLanguage` — The language of the text is BCP-47 format
</dd>
</dl>
<dl>
<dd>
**speaker:** `typing.Optional[TextToSpeechSpeaker]`
The speaker voice to be used for the output audio.
**Default:** Meera
**Model Compatibility (Speakers compatible with respective models):**
- **bulbul:v1:**
- Female: Diya, Maya, Meera, Pavithra, Maitreyi, Misha
- Male: Amol, Arjun, Amartya, Arvind, Neel, Vian
- **bulbul:v2:**
- Female: Anushka, Manisha, Vidya, Arya
- Male: Abhilash, Karun, Hitesh
**Note:** Speaker selection must match the chosen model version.
</dd>
</dl>
<dl>
<dd>
**pitch:** `typing.Optional[float]` — Controls the pitch of the audio. Lower values result in a deeper voice, while higher values make it sharper. The suitable range is between -0.75 and 0.75. Default is 0.0.
</dd>
</dl>
<dl>
<dd>
**pace:** `typing.Optional[float]` — Controls the speed of the audio. Lower values result in slower speech, while higher values make it faster. The suitable range is between 0.5 and 2.0. Default is 1.0.
</dd>
</dl>
<dl>
<dd>
**loudness:** `typing.Optional[float]` — Controls the loudness of the audio. Lower values result in quieter audio, while higher values make it louder. The suitable range is between 0.3 and 3.0. Default is 1.0.
</dd>
</dl>
<dl>
<dd>
**speech_sample_rate:** `typing.Optional[SpeechSampleRate]` — Specifies the sample rate of the output audio. Supported values are 8000, 16000, 22050, 24000 Hz. If not provided, the default is 22050 Hz.
</dd>
</dl>
<dl>
<dd>
**enable_preprocessing:** `typing.Optional[bool]` — Controls whether normalization of English words and numeric entities (e.g., numbers, dates) is performed. Set to true for better handling of mixed-language text. Default is false.
</dd>
</dl>
<dl>
<dd>
**model:** `typing.Optional[TextToSpeechModel]` — Specifies the model to use for text-to-speech conversion. Default is bulbul:v1.
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
### Chat
<details><summary><code>client.chat.<a href="src/sarvamai/chat/client.py">completions</a>(...)</code></summary>
<dl>
<dd>
#### 📝 Description
<dl>
<dd>
<dl>
<dd>
Calls Sarvam LLM API to get the chat completion. Supported model(s): `sarvam-m`.
</dd>
</dl>
</dd>
</dl>
#### 🔌 Usage
<dl>
<dd>
<dl>
<dd>
```python
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
)
client.chat.completions(
messages=[{"content": "content", "role": "assistant"}],
)
```
</dd>
</dl>
</dd>
</dl>
#### ⚙️ Parameters
<dl>
<dd>
<dl>
<dd>
**messages:** `typing.Sequence[ChatCompletionRequestMessageParams]` — A list of messages comprising the conversation so far.
</dd>
</dl>
<dl>
<dd>
**temperature:** `typing.Optional[float]`
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.
We generally recommend altering this or `top_p` but not both.
</dd>
</dl>
<dl>
<dd>
**top_p:** `typing.Optional[float]`
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.
We generally recommend altering this or `temperature` but not both.
</dd>
</dl>
<dl>
<dd>
**reasoning_effort:** `typing.Optional[ReasoningEffort]`
</dd>
</dl>
<dl>
<dd>
**max_tokens:** `typing.Optional[int]` — The maximum number of tokens that can be generated in the chat completion.
</dd>
</dl>
<dl>
<dd>
**stream:** `typing.Optional[bool]`
If set to true, the model response data will be streamed to the client
as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
</dd>
</dl>
<dl>
<dd>
**stop:** `typing.Optional[StopConfigurationParams]`
</dd>
</dl>
<dl>
<dd>
**n:** `typing.Optional[int]` — How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
</dd>
</dl>
<dl>
<dd>
**seed:** `typing.Optional[int]`
This feature is in Beta.
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.
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
</dd>
</dl>
<dl>
<dd>
**frequency_penalty:** `typing.Optional[float]`
Number between -2.0 and 2.0. Positive values penalize new tokens based on
their existing frequency in the text so far, decreasing the model's
likelihood to repeat the same line verbatim.
</dd>
</dl>
<dl>
<dd>
**presence_penalty:** `typing.Optional[float]`
Number between -2.0 and 2.0. Positive values penalize new tokens based on
whether they appear in the text so far, increasing the model's likelihood
to talk about new topics.
</dd>
</dl>
<dl>
<dd>
**wiki_grounding:** `typing.Optional[bool]` — If this parameter is enabled, then the model uses a RAG based approach to retrieve relevant chunks from Wikipedia and uses them to answer the question. This is particularly useful for queries seeking factual information.
</dd>
</dl>
<dl>
<dd>
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</details>
Raw data
{
"_id": null,
"home_page": null,
"name": "sarvamai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/e9/08/e5efcb30818ed220b818319255c22fd91e379489ebaa93efd6f444fb4987/sarvamai-0.1.21.tar.gz",
"platform": null,
"description": "# Sarvam Python Library\n\n[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsarvamai%2Fsarvam-python-sdk)\n[](https://pypi.python.org/pypi/sarvamai)\n\nThe Sarvam Python library provides convenient access to the Sarvam API from Python.\n\n## Documentation\n\nAPI reference documentation is available [here](https://docs.sarvam.ai/api-reference-docs/speech-to-text/).\n\n## Installation\n\n```sh\npip install sarvamai\n```\n\n## Reference\n\nA full reference for this library is available [here](#References).\n\n## Usage\n\nInstantiate and use the client with the following:\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.text.translate(\n input=\"input\",\n source_language_code=\"auto\",\n target_language_code=\"bn-IN\",\n)\n```\n\n## Async Client\n\nThe SDK also exports an `async` client so that you can make non-blocking calls to our API.\n\n```python\nimport asyncio\n\nfrom sarvamai import AsyncSarvamAI\n\nclient = AsyncSarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\n\n\nasync def main() -> None:\n await client.text.translate(\n input=\"input\",\n source_language_code=\"auto\",\n target_language_code=\"bn-IN\",\n )\n\n\nasyncio.run(main())\n```\n\n## Exception Handling\n\nWhen the API returns a non-success status code (4xx or 5xx response), a subclass of the following error\nwill be thrown.\n\n```python\nfrom sarvamai.core.api_error import ApiError\n\ntry:\n client.text.translate(...)\nexcept ApiError as e:\n print(e.status_code)\n print(e.body)\n```\n\n## Advanced\n\n### Retries\n\nThe SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long\nas the request is deemed retryable and the number of retry attempts has not grown larger than the configured\nretry limit (default: 2).\n\nA request is deemed retryable when any of the following HTTP status codes is returned:\n\n- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)\n- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)\n- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)\n\nUse the `max_retries` request option to configure this behavior.\n\n```python\nclient.text.translate(..., request_options={\n \"max_retries\": 1\n})\n```\n\n### Timeouts\n\nThe SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.\n\n```python\n\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n ...,\n timeout=20.0,\n)\n\n\n# Override timeout for a specific method\nclient.text.translate(..., request_options={\n \"timeout_in_seconds\": 1\n})\n```\n\n### Custom Client\n\nYou can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies\nand transports.\n\n```python\nimport httpx\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n ...,\n httpx_client=httpx.Client(\n proxies=\"http://my.test.proxy.example.com\",\n transport=httpx.HTTPTransport(local_address=\"0.0.0.0\"),\n ),\n)\n```\n\n## Contributing\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically.\nAdditions made directly to this library would have to be moved over to our generation code,\notherwise they would be overwritten upon the next generated release. Feel free to open a PR as\na proof of concept, but know that we will not be able to merge it as-is. We suggest opening\nan issue first to discuss with us!\n\nOn the other hand, contributions to the README are always very welcome!\n\n---\n\n## References\n\n### Text\n<details><summary><code>client.text.<a href=\"src/sarvamai/text/client.py\">translate</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**Translation** converts text from one language to another while preserving its meaning.\nFor Example: **'\u092e\u0948\u0902 \u0911\u092b\u093f\u0938 \u091c\u093e \u0930\u0939\u093e \u0939\u0942\u0901'** translates to **'I am going to the office'** in English, where the script and language change, but the original meaning remains the same.\n\nAvailable languages:\n- **`bn-IN`**: Bengali\n- **`en-IN`**: English\n- **`gu-IN`**: Gujarati\n- **`hi-IN`**: Hindi\n- **`kn-IN`**: Kannada\n- **`ml-IN`**: Malayalam\n- **`mr-IN`**: Marathi\n- **`od-IN`**: Odia\n- **`pa-IN`**: Punjabi\n- **`ta-IN`**: Tamil\n- **`te-IN`**: Telugu\n\n#### Newly added languages:\n- **`as-IN`**: Assamese\n- **`brx-IN`**: Bodo\n- **`doi-IN`**: Dogri\n- **`kok-IN`**: Konkani\n- **`ks-IN`**: Kashmiri\n- **`mai-IN`**: Maithili\n- **`mni-IN`**: Manipuri (Meiteilon)\n- **`ne-IN`**: Nepali\n- **`sa-IN`**: Sanskrit\n- **`sat-IN`**: Santali\n- **`sd-IN`**: Sindhi\n- **`ur-IN`**: Urdu\n\nFor hands-on practice, you can explore the notebook tutorial on [Translate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/translate/Translate_API_Tutorial.ipynb).\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.text.translate(\n input=\"input\",\n source_language_code=\"auto\",\n target_language_code=\"bn-IN\",\n)\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**input:** `str` \u2014 The text you want to translate is the input text that will be processed by the translation model. The maximum is 1000 characters for Mayura:v1 and 2000 characters for Sarvam-Translate:v1.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**source_language_code:** `TranslateSourceLanguage` \n\nSource language code for translation input.\n\n**mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu\n\n**sarvam-translate:v1 Languages:** All mayura:v1 languages and Assamese, Bodo, Dogri, Konkani, Kashmiri, Maithili, Manipuri, Nepali, Sanskrit, Santali, Sindhi, Urdu\n\n**Note:** mayura:v1 supports automatic language detection using 'auto' as the source language code.\n\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**target_language_code:** `TranslateTargetLanguage` \n\nThe language code of the translated text. This specifies the target language for translation.\n\n**mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu\n\n**sarvam-translate:v1 Languages:** All mayura:v1 and Assamese, Bodo, Dogri, Konkani, Kashmiri, Maithili, Manipuri, Nepali, Sanskrit, Santali, Sindhi, Urdu\n\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**speaker_gender:** `typing.Optional[TranslateSpeakerGender]` \u2014 Please specify the gender of the speaker for better translations.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**mode:** `typing.Optional[TranslateMode]` \n\nSpecifies the tone or style of the translation.\n\n**Model Support:**\n- **mayura:v1**: Supports formal, classic-colloquial, and modern-colloquial modes\n- **sarvam-translate:v1**: Only formal mode is supported\n\n**Default:** formal\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**model:** `typing.Optional[TranslateModel]` \n\nSpecifies the translation model to use.\n- mayura:v1: Supports 12 languages with all modes, output scripts, and automatic language detection.\n- sarvam-translate:v1: Supports all 22 scheduled languages of India, formal mode only.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**enable_preprocessing:** `typing.Optional[bool]` \n\nThis will enable custom preprocessing of the input text which can result in better translations.\n Recommendation- You can switch on whenever there is some complex text with difficult vocabulary and sentences, for which you want simple translations that people can understand.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**output_script:** `typing.Optional[TransliterateMode]` \n\n**output_script**: This is an optional parameter which controls the transliteration style applied to the output text.\n\n**Transliteration**: Converting text from one script to another while preserving pronunciation.\n\nFor mayura:v1 - We support transliteration with four options:\n- **`null`**(default): No transliteration applied.\n- **`roman`**: Transliteration in Romanized script.\n- **`fully-native`**: Transliteration in the native script with formal style.\n- **`spoken-form-in-native`**: Transliteration in the native script with spoken style.\n\nFor sarvam-translate:v1 - Transliteration is not supported.\n#### Example:\nEnglish: Your EMI of Rs. 3000 is pending.\nDefault modern translation: \u0906\u092a\u0915\u093e Rs. 3000 \u0915\u093e EMI pending \u0939\u0948 (when `null` is passed).\n\nWith postprocessing enabled:\n- **roman output**: aapka Rs. 3000 ka EMI pending hai.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**numerals_format:** `typing.Optional[NumeralsFormat]` \n\n`numerals_format` is an optional parameter with two options (supported for both mayura:v1 and sarvam-translate:v1):\n\n- **`international`** (default): Uses regular numerals (0-9).\n- **`native`**: Uses language-specific native numerals.\n\n#### Example:\n- If `international` format is selected, we use regular numerals (0-9). For example: `\u092e\u0947\u0930\u093e phone number \u0939\u0948: 9840950950`.\n- If `native` format is selected, we use language-specific native numerals, like: `\u092e\u0947\u0930\u093e phone number \u0939\u0948: \u096f\u096e\u096a\u0966\u096f\u096b\u0966\u096f\u096b\u0966`.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n<details><summary><code>client.text.<a href=\"src/sarvamai/text/client.py\">identify_language</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\nIdentifies the language (e.g., en-IN, hi-IN) and script (e.g., Latin, Devanagari) of the input text, supporting multiple languages.\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.text.identify_language(\n input=\"input\",\n)\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**input:** `str` \u2014 The text input for language and script identification.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n<details><summary><code>client.text.<a href=\"src/sarvamai/text/client.py\">transliterate</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**Transliteration** converts text from one script to another while preserving the original pronunciation. For example, **'\u0928\u092e\u0938\u094d\u0924\u0947'** becomes **'namaste'** in English, and **'how are you'** can be written as **'\u0939\u093e\u0909 \u0906\u0930 \u092f\u0942'** in Devanagari. This process ensures that the sound of the original text remains intact, even when written in a different script.\n\nTransliteration is useful when you want to represent words phonetically across different writing systems, such as converting **'\u092e\u0948\u0902 \u0911\u092b\u093f\u0938 \u091c\u093e \u0930\u0939\u093e \u0939\u0942\u0901'** to **'main office ja raha hun'** in English letters.\n\n**Translation**, on the other hand, converts text from one language to another while preserving the meaning rather than pronunciation. For example, **'\u092e\u0948\u0902 \u0911\u092b\u093f\u0938 \u091c\u093e \u0930\u0939\u093e \u0939\u0942\u0901'** translates to **'I am going to the office'** in English, changing both the script and the language while conveying the intended message.\n#### Examples of **Transliteration**:\n- **'Good morning'** becomes **'\u0917\u0941\u0921 \u092e\u0949\u0930\u094d\u0928\u093f\u0902\u0917'** in Hindi, where the pronunciation is preserved but the meaning is not translated.\n- **'\u0938\u0941\u092a\u094d\u0930\u092d\u093e\u0924'** becomes **'suprabhat'** in English.\n\nAvailable languages:\n- **`en-IN`**: English\n- **`hi-IN`**: Hindi\n- **`bn-IN`**: Bengali\n- **`gu-IN`**: Gujarati\n- **`kn-IN`**: Kannada\n- **`ml-IN`**: Malayalam\n- **`mr-IN`**: Marathi\n- **`od-IN`**: Odia\n- **`pa-IN`**: Punjabi\n- **`ta-IN`**: Tamil\n- **`te-IN`**: Telugu\n\nFor hands-on practice, you can explore the notebook tutorial on [Transliterate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/transliterate/Transliterate_API_Tutorial.ipynb).\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.text.transliterate(\n input=\"input\",\n source_language_code=\"auto\",\n target_language_code=\"bn-IN\",\n)\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**input:** `str` \u2014 The text you want to transliterate.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**source_language_code:** `TransliterateSourceLanguage` \n\nThe language code of the input text. This specifies the source language for transliteration.\n\n\n\n Note: The source language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration.\n\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**target_language_code:** `TranslatiterateTargetLanguage` \n\nThe language code of the transliteration text. This specifies the target language for transliteration.\n\n\n\n Note:The target language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration.\n\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**numerals_format:** `typing.Optional[NumeralsFormat]` \n\n`numerals_format` is an optional parameter with two options:\n\n- **`international`** (default): Uses regular numerals (0-9).\n- **`native`**: Uses language-specific native numerals.\n\n#### Example:\n- If `international` format is selected, we use regular numerals (0-9). For example: `\u092e\u0947\u0930\u093e phone number \u0939\u0948: 9840950950`.\n- If `native` format is selected, we use language-specific native numerals, like: `\u092e\u0947\u0930\u093e phone number \u0939\u0948: \u096f\u096e\u096a\u0966\u096f\u096b\u0966\u096f\u096b\u0966`.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**spoken_form_numerals_language:** `typing.Optional[SpokenFormNumeralsFormat]` \n\n`spoken_form_numerals_language` is an optional parameter with two options and only works when spoken_form is true:\n\n- **`english`** : Numbers in the text will be spoken in English.\n- **`native(default)`**: Numbers in the text will be spoken in the native language.\n\n#### Examples:\n- **Input:** \"\u092e\u0947\u0930\u0947 \u092a\u093e\u0938 \u20b9200 \u0939\u0948\"\n - If `english` format is selected: \"\u092e\u0947\u0930\u0947 \u092a\u093e\u0938 \u091f\u0942 \u0939\u0928\u094d\u0921\u0930\u094d\u0921 \u0930\u0942\u092a\u0940\u0938 \u0939\u0948\"\n - If `native` format is selected: \"\u092e\u0947\u0930\u0947 \u092a\u093e\u0938 \u0926\u094b \u0938\u094c \u0930\u0941\u092a\u092f\u0947 \u0939\u0948\"\n\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**spoken_form:** `typing.Optional[bool]` \n\n - Default: `False`\n - Converts text into a natural spoken form when `True`.\n - **Note:** No effect if output language is `en-IN`.\n\n#### Example:\n- **Input:** `\u092e\u0941\u091d\u0947 \u0915\u0932 9:30am \u0915\u094b appointment \u0939\u0948`\n - **Output:** `\u092e\u0941\u091d\u0947 \u0915\u0932 \u0938\u0941\u092c\u0939 \u0938\u093e\u0922\u093c\u0947 \u0928\u094c \u092c\u091c\u0947 \u0915\u094b \u0905\u092a\u0949\u0907\u0902\u091f\u092e\u0947\u0902\u091f \u0939\u0948`\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n### SpeechToText\n<details><summary><code>client.speech_to_text.<a href=\"src/sarvamai/speech_to_text/client.py\">transcribe</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n### Real-Time Speech to Text API\n\nThis API transcribes speech to text in multiple Indian languages and English. Supports real-time transcription for interactive applications.\n\n#### Available Options:\n- **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results\n- **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt/stt-batch-api)\n - Supports diarization (speaker identification)\n\n#### Note:\n- Pricing differs for Real-Time and Batch APIs\n- Diarization is only available in Batch API with separate pricing\n- Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.speech_to_text.transcribe()\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**file:** `from __future__ import annotations\n\ncore.File` \u2014 See core.File for more documentation\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**model:** `typing.Optional[SpeechToTextModel]` \n\nSpecifies the model to use for speech-to-text conversion.\nNote:- Default model is `saarika:v2`\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**language_code:** `typing.Optional[SpeechToTextLanguage]` \n\nSpecifies the language of the input audio. This parameter is required to ensure accurate transcription.\n For the `saarika:v1` model, this parameter is mandatory.\n For the `saarika:v2` model, it is optional.\n`unknown`: Use this when the language is not known; the API will detect it automatically. \nNote:- that the `saarika:v1` model does not support `unknown` language code.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n<details><summary><code>client.speech_to_text.<a href=\"src/sarvamai/speech_to_text/client.py\">translate</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n### Real-Time Speech to Text Translation API\n\nThis API automatically detects the input language, transcribes the speech, and translates the text to English.\n\n#### Available Options:\n- **Real-Time API** (Current Endpoint): For quick responses under 30 seconds with immediate results\n- **Batch API**: For longer audio files, requires following a notebook script - [View Notebook](https://github.com/sarvamai/sarvam-ai-cookbook/tree/main/notebooks/stt-translate/stt-translate-batch-api)\n - Supports diarization (speaker identification)\n\n#### Note:\n- Pricing differs for Real-Time and Batch APIs\n- Diarization is only available in Batch API with separate pricing\n- Please refer to [dashboard.sarvam.ai](https://dashboard.sarvam.ai) for detailed pricing information\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.speech_to_text.translate()\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**file:** `from __future__ import annotations\n\ncore.File` \u2014 See core.File for more documentation\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**prompt:** `typing.Optional[str]` \u2014 Conversation context can be passed as a prompt to boost model accuracy. However, the current system is at an experimentation stage and doesn\u2019t match the prompt performance of large language models.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**model:** `typing.Optional[SpeechToTextTranslateModel]` \u2014 Model to be used for converting speech to text in target language\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n### TextToSpeech\n<details><summary><code>client.text_to_speech.<a href=\"src/sarvamai/text_to_speech/client.py\">convert</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\nThis is the model to convert text into spoken audio. \nThe output is a wave file encoded as a base64 string.\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.text_to_speech.convert(\n text=\"text\",\n target_language_code=\"bn-IN\",\n)\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**text:** `str` \n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**target_language_code:** `TextToSpeechLanguage` \u2014 The language of the text is BCP-47 format\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**speaker:** `typing.Optional[TextToSpeechSpeaker]` \n\nThe speaker voice to be used for the output audio.\n\n**Default:** Meera\n\n**Model Compatibility (Speakers compatible with respective models):**\n- **bulbul:v1:**\n - Female: Diya, Maya, Meera, Pavithra, Maitreyi, Misha\n - Male: Amol, Arjun, Amartya, Arvind, Neel, Vian\n\n- **bulbul:v2:**\n - Female: Anushka, Manisha, Vidya, Arya\n - Male: Abhilash, Karun, Hitesh\n\n**Note:** Speaker selection must match the chosen model version.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**pitch:** `typing.Optional[float]` \u2014 Controls the pitch of the audio. Lower values result in a deeper voice, while higher values make it sharper. The suitable range is between -0.75 and 0.75. Default is 0.0.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**pace:** `typing.Optional[float]` \u2014 Controls the speed of the audio. Lower values result in slower speech, while higher values make it faster. The suitable range is between 0.5 and 2.0. Default is 1.0.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**loudness:** `typing.Optional[float]` \u2014 Controls the loudness of the audio. Lower values result in quieter audio, while higher values make it louder. The suitable range is between 0.3 and 3.0. Default is 1.0.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**speech_sample_rate:** `typing.Optional[SpeechSampleRate]` \u2014 Specifies the sample rate of the output audio. Supported values are 8000, 16000, 22050, 24000 Hz. If not provided, the default is 22050 Hz.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**enable_preprocessing:** `typing.Optional[bool]` \u2014 Controls whether normalization of English words and numeric entities (e.g., numbers, dates) is performed. Set to true for better handling of mixed-language text. Default is false.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**model:** `typing.Optional[TextToSpeechModel]` \u2014 Specifies the model to use for text-to-speech conversion. Default is bulbul:v1.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n\n### Chat\n<details><summary><code>client.chat.<a href=\"src/sarvamai/chat/client.py\">completions</a>(...)</code></summary>\n<dl>\n<dd>\n\n#### \ud83d\udcdd Description\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\nCalls Sarvam LLM API to get the chat completion. Supported model(s): `sarvam-m`.\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \ud83d\udd0c Usage\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n```python\nfrom sarvamai import SarvamAI\n\nclient = SarvamAI(\n api_subscription_key=\"YOUR_API_SUBSCRIPTION_KEY\",\n)\nclient.chat.completions(\n messages=[{\"content\": \"content\", \"role\": \"assistant\"}],\n)\n\n```\n</dd>\n</dl>\n</dd>\n</dl>\n\n#### \u2699\ufe0f Parameters\n\n<dl>\n<dd>\n\n<dl>\n<dd>\n\n**messages:** `typing.Sequence[ChatCompletionRequestMessageParams]` \u2014 A list of messages comprising the conversation so far.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**temperature:** `typing.Optional[float]` \n\nWhat 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.\nWe generally recommend altering this or `top_p` but not both.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**top_p:** `typing.Optional[float]` \n\nAn alternative to sampling with temperature, called nucleus sampling,\nwhere the model considers the results of the tokens with top_p probability\nmass. So 0.1 means only the tokens comprising the top 10% probability mass\nare considered.\n\nWe generally recommend altering this or `temperature` but not both.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**reasoning_effort:** `typing.Optional[ReasoningEffort]` \n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**max_tokens:** `typing.Optional[int]` \u2014 The maximum number of tokens that can be generated in the chat completion.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**stream:** `typing.Optional[bool]` \n\nIf set to true, the model response data will be streamed to the client\nas it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**stop:** `typing.Optional[StopConfigurationParams]` \n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**n:** `typing.Optional[int]` \u2014 How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**seed:** `typing.Optional[int]` \n\nThis feature is in Beta.\nIf 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.\nDeterminism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**frequency_penalty:** `typing.Optional[float]` \n\nNumber between -2.0 and 2.0. Positive values penalize new tokens based on\ntheir existing frequency in the text so far, decreasing the model's\nlikelihood to repeat the same line verbatim.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**presence_penalty:** `typing.Optional[float]` \n\nNumber between -2.0 and 2.0. Positive values penalize new tokens based on\nwhether they appear in the text so far, increasing the model's likelihood\nto talk about new topics.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**wiki_grounding:** `typing.Optional[bool]` \u2014 If this parameter is enabled, then the model uses a RAG based approach to retrieve relevant chunks from Wikipedia and uses them to answer the question. This is particularly useful for queries seeking factual information.\n \n</dd>\n</dl>\n\n<dl>\n<dd>\n\n**request_options:** `typing.Optional[RequestOptions]` \u2014 Request-specific configuration.\n \n</dd>\n</dl>\n</dd>\n</dl>\n\n\n</dd>\n</dl>\n</details>\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.1.21",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2e4eb9933f72681b7aed91b86913337dd3981fad97027881fbc66c3c5eb03568",
"md5": "7443c86a35d74d6581517c3f0b03064e",
"sha256": "daa4e5d16635fe434f5f270cee416849249285369141d77132a17f0bf670f120"
},
"downloads": -1,
"filename": "sarvamai-0.1.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7443c86a35d74d6581517c3f0b03064e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 175204,
"upload_time": "2025-10-07T07:37:46",
"upload_time_iso_8601": "2025-10-07T07:37:46.024249Z",
"url": "https://files.pythonhosted.org/packages/2e/4e/b9933f72681b7aed91b86913337dd3981fad97027881fbc66c3c5eb03568/sarvamai-0.1.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e908e5efcb30818ed220b818319255c22fd91e379489ebaa93efd6f444fb4987",
"md5": "a40709e6be8bb10956865d5c6f9dee87",
"sha256": "865065635b2b99d40f5519308832954015627938e06a6333b5f62ae9c36278bb"
},
"downloads": -1,
"filename": "sarvamai-0.1.21.tar.gz",
"has_sig": false,
"md5_digest": "a40709e6be8bb10956865d5c6f9dee87",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 87386,
"upload_time": "2025-10-07T07:37:47",
"upload_time_iso_8601": "2025-10-07T07:37:47.085019Z",
"url": "https://files.pythonhosted.org/packages/e9/08/e5efcb30818ed220b818319255c22fd91e379489ebaa93efd6f444fb4987/sarvamai-0.1.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-07 07:37:47",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sarvamai"
}