Skip to content

SarvamAI

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official SarvamAI OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using SarvamAI;

using var client = new SarvamAIClient(apiKey);

Translation

Translate text between Indian languages and English using the Sarvam AI Translation API.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
using var client = new SarvamAIClient(apiKey);

// Translate text from English to Hindi
var response = await client.TranslateTextAsync(
    request: new TranslateRequest
    {
        Input = "Hello, how are you?",
        SourceLanguageCode = TranslateRequestSourceLanguageCode.EnIn,
        TargetLanguageCode = TranslateRequestTargetLanguageCode.HiIn,
        Mode = TranslateRequestMode.Formal,
    });

Console.WriteLine($"Translated text: {response.TranslatedText}");

Chat Completion

Generate chat completions using Sarvam AI's Indian language LLMs (Sarvam-105B, Sarvam-30B).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using var client = new SarvamAIClient(apiKey);

// Create a chat completion with Sarvam-30B
var response = await client.CreateChatCompletionAsync(
    request: new ChatCompletionRequest
    {
        Model = ChatCompletionRequestModel.Sarvam30b,
        Messages =
        [
            new ChatCompletionMessage
            {
                Role = ChatCompletionMessageRole.System,
                Content = "You are a helpful assistant that speaks Hindi.",
            },
            new ChatCompletionMessage
            {
                Role = ChatCompletionMessageRole.User,
                Content = "Tell me about India in 2 sentences.",
            },
        ],
        Temperature = 0.7,
        MaxTokens = 256,
    });

Console.WriteLine($"Response: {response.Choices[0].Message?.Content}");
Console.WriteLine($"Tokens used: {response.Usage?.TotalTokens}");

Transliteration

Convert text between scripts (e.g., Devanagari to Roman) without changing the language.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using var client = new SarvamAIClient(apiKey);

// Transliterate Hindi text from Devanagari to Roman script
var response = await client.TransliterateTextAsync(
    request: new TransliterateRequest
    {
        Input = "namaste, aap kaise hain?",
        SourceLanguageCode = TransliterateRequestSourceLanguageCode.EnIn,
        TargetLanguageCode = TransliterateRequestTargetLanguageCode.HiIn,
    });

Console.WriteLine($"Transliterated text: {response.TransliteratedText}");

Language Detection

Detect the language and script of input text using the Sarvam AI Language Detection API.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using var client = new SarvamAIClient(apiKey);

// Detect the language and script of Hindi text
var response = await client.DetectLanguageAsync(
    request: new DetectLanguageRequest
    {
        Input = "नमस्ते, आप कैसे हैं?",
    });

Console.WriteLine($"Language: {response.LanguageCode}");
Console.WriteLine($"Script: {response.ScriptCode}");

MEAI Speech-to-Text

Use SarvamAIClient as a Microsoft.Extensions.AI ISpeechToTextClient for unified speech transcription.

1
2
3
4
5
6
7
8
using var client = new SarvamAIClient(apiKey);

// Get service metadata from the ISpeechToTextClient
Meai.ISpeechToTextClient sttClient = client;

var metadata = Meai.SpeechToTextClientExtensions.GetService<Meai.SpeechToTextClientMetadata>(sttClient);

var self = Meai.SpeechToTextClientExtensions.GetService<SarvamAIClient>(sttClient);

Ecosystem maintenance

This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.

Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.

Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.

Support

Priority place for bugs: https://github.com/tryAGI/SarvamAI/issues
Priority place for ideas and general questions: https://github.com/tryAGI/SarvamAI/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.