Documentation
¶
Overview ¶
Package sarvamai provides a Go client for the Sarvam AI API.
Usage ¶
Create a client with your API key:
client, err := sarvamai.NewClient(sarvamai.Config{
APIKey: "your-api-key",
})
API Key ¶
You can obtain an API key from the Sarvam dashboard: https://dashboard.sarvam.ai/key-management
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Text *text.TextClient
SpeechToText *stt.STTClient
SpeechToTextTranslate *translate.TranslateClient
SpeechToTextJob *sttjob.SttJobClient
SpeechToTextTranslateJob *translatejob.TranslateJobClient
TextToSpeech *tts.TTSClient
Chat *chat.ChatClient
DocumentIntelligence *docintel.DocIntelClient
// contains filtered or unexported fields
}
Client provides access to Sarvam AI services.
Services ¶
The client exposes the following services:
- Text: For translation, transliteration, and language detection
- SpeechToText: For speech-to-text transcription (REST and streaming)
- TextToSpeech: For text-to-speech conversion
- Chat: For conversational AI interactions
Example ¶
client, err := sarvamai.NewClient(sarvamai.Config{
APIKey: "your-api-key",
})
if err != nil {
log.Fatal(err)
}
// Use text translation
resp, err := client.Text.Translate(ctx, translate.Request{...})
// Use speech-to-text
resp, err := client.SpeechToText.Transcribe(ctx, stt.TranscribeRequest{...})
// Use text-to-speech
resp, err := client.TextToSpeech.Convert(ctx, tts.ConvertRequest{...})
// Use chat
resp, err := client.Chat.Completions(ctx, chat.ChatRequest{...})
func NewClient ¶
NewClient creates a new Sarvam AI client with the given configuration.
Parameters ¶
cfg: Configuration containing API key and optional settings. APIKey is required.
Returns ¶
A new Client instance or an error if the API key is missing.
Example ¶
client, err := sarvamai.NewClient(sarvamai.Config{
APIKey: "your-api-key",
BaseURL: "https://api.sarvam.ai", // optional, default: https://api.sarvam.ai
HTTPClient: &http.Client{Timeout: 30 * time.Second}, // optional
})
type Config ¶
Config holds the configuration for the Sarvam AI client.
Fields ¶
- APIKey: Your Sarvam AI API key. Required. Get one at https://dashboard.sarvam.ai/key-management
- BaseURL: The base URL for the API. Defaults to "https://api.sarvam.ai" if empty.
- HTTPClient: The HTTP client to use for requests. Defaults to a 30-second timeout if nil.
- MaxRetries: Maximum number of retries for transient errors (429, 5xx). Defaults to 3 if <= 0.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chat provides types for the Chat Completions API.
|
Package chat provides types for the Chat Completions API. |
|
Package docintel provides types for Document Intelligence API requests and responses.
|
Package docintel provides types for Document Intelligence API requests and responses. |
|
examples
|
|
|
chat-completion
command
|
|
|
document-intelligence
command
|
|
|
language-detection
command
|
|
|
speech-to-text
command
|
|
|
speech-to-text-ws
command
|
|
|
stt-translate
command
|
|
|
stt-translate-ws
command
|
|
|
text-to-speech
command
|
|
|
text-to-speech-ws
command
|
|
|
translation
command
|
|
|
transliteration
command
|
|
|
internal
|
|
|
Package languages provides language codes supported by the Sarvam AI API.
|
Package languages provides language codes supported by the Sarvam AI API. |
|
shared
|
|
|
speech
Contains types used across multiple packages in the speech domain.
|
Contains types used across multiple packages in the speech domain. |
|
Package translate provides types for the Speech-to-Text Translate API.
|
Package translate provides types for the Speech-to-Text Translate API. |
|
Package translatejob provides types for the Speech-to-Text Translate Batch Job API.
|
Package translatejob provides types for the Speech-to-Text Translate Batch Job API. |
|
Package tts provides types for Text-to-Speech API requests and responses.
|
Package tts provides types for Text-to-Speech API requests and responses. |
Click to show internal directories.
Click to hide internal directories.