llm

Sarvam LLM service implementation using OpenAI-compatible interface.

class pipecat.services.sarvam.llm.SarvamLLMSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, system_instruction: str | None | NotGiven = <factory>, temperature: float | None | NotGiven | NotGiven = <factory>, max_tokens: int | None | NotGiven | NotGiven = <factory>, top_p: float | None | NotGiven | NotGiven = <factory>, top_k: int | None | NotGiven = <factory>, frequency_penalty: float | None | NotGiven | NotGiven = <factory>, presence_penalty: float | None | NotGiven | NotGiven = <factory>, seed: int | None | NotGiven | NotGiven = <factory>, filter_incomplete_user_turns: bool | None | NotGiven = <factory>, user_turn_completion_config: UserTurnCompletionConfig | None | NotGiven = <factory>, use_provider_thinking_default: bool | NotGiven = <factory>, max_completion_tokens: int | None | NotGiven | NotGiven = <factory>, wiki_grounding: bool | None | NotGiven = <factory>, reasoning_effort: Literal['low', 'medium', 'high'] | None | ~pipecat.utils.types.NotGiven=<factory>)[source]

Bases: OpenAILLMSettings

Settings for SarvamLLMService.

Parameters:
  • wiki_grounding – Sarvam wiki grounding toggle.

  • reasoning_effort – Reasoning effort level (low, medium, high).

class pipecat.services.sarvam.llm.SarvamLLMService(*, api_key: str, base_url: str | None = None, settings: SarvamLLMSettings | None = None, default_headers: Mapping[str, str] | None = None, **kwargs)[source]

Bases: OpenAILLMService

A service for interacting with Sarvam’s API using the OpenAI-compatible interface.

This service extends OpenAILLMService to connect to Sarvam’s API endpoint while maintaining full compatibility with OpenAI’s interface and functionality.

supports_developer_role: bool = False

Whether this service’s API supports the “developer” message role.

OpenAI’s native API supports it, but some OpenAI-compatible services (e.g. Cerebras) do not. Subclasses that don’t support it should set this to False, which causes the adapter to convert “developer” messages to “user” messages before sending them to the API.

Settings

alias of SarvamLLMSettings

__init__(*, api_key: str, base_url: str | None = None, settings: SarvamLLMSettings | None = None, default_headers: Mapping[str, str] | None = None, **kwargs)[source]

Initialize Sarvam LLM service.

Parameters:
  • api_key – Sarvam API key used for both OpenAI auth and Sarvam subscription header.

  • base_url – Sarvam OpenAI-compatible base URL. When None, resolved from the model: /v1 for sarvam-105b-conversations, /v2 for all other models.

  • settings – Runtime-updatable settings.

  • default_headers – Additional HTTP headers to include in requests.

  • **kwargs – Additional keyword arguments passed to OpenAILLMService.

create_client(api_key=None, base_url=None, organization=None, project=None, default_headers=None, **kwargs)[source]

Create OpenAI-compatible client for Sarvam API endpoint.

Ensures Sarvam auth and SDK identification headers are always attached.

async run_inference(context: LLMContext, max_tokens: int | None = None, system_instruction: str | None = None, response_schema: dict[str, Any] | None = None) → str | None[source]

Run inference, pushing an error frame on misconfiguration.

Validates tool parameters, vision support, and capability support before delegating to the base class. Validation failures are pushed as non-fatal error frames rather than raised, so an LLMSwitcher can fall back to another service at runtime.

Parameters:
  • context – The LLM context containing conversation history.

  • max_tokens – Optional maximum number of tokens to generate.

  • system_instruction – Optional system instruction for this inference.

  • response_schema – Optional JSON schema the reply must follow.

Returns:

The LLM’s response, or None if the request is invalid or produced no response.

build_chat_completion_params(params_from_context: OpenAILLMInvocationParams) → dict[source]

Build parameters for Sarvam chat completion request.

Starts from OpenAI-compatible defaults, then removes unsupported request fields and applies Sarvam-specific options.