llm
OpenRouter LLM service implementation.
This module provides an OpenAI-compatible interface for interacting with OpenRouter’s API, extending the base OpenAI LLM service functionality.
- class pipecat.services.openrouter.llm.OpenRouterLLMSettings(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>, max_completion_tokens: int | _NotGiven | NotGiven = <factory>)[source]
Bases:
OpenAILLMSettingsSettings for OpenRouterLLMService.
- class pipecat.services.openrouter.llm.OpenRouterLLMService(*, api_key: str | None = None, model: str | None = None, base_url: str = 'https://openrouter.ai/api/v1', settings: OpenRouterLLMSettings | None = None, **kwargs)[source]
Bases:
OpenAILLMServiceA service for interacting with OpenRouter’s API using the OpenAI-compatible interface.
This service extends OpenAILLMService to connect to OpenRouter’s API endpoint while maintaining full compatibility with OpenAI’s interface and functionality.
- Settings
alias of
OpenRouterLLMSettings
- __init__(*, api_key: str | None = None, model: str | None = None, base_url: str = 'https://openrouter.ai/api/v1', settings: OpenRouterLLMSettings | None = None, **kwargs)[source]
Initialize the OpenRouter LLM service.
- Parameters:
api_key – The API key for accessing OpenRouter’s API. If None, will attempt to read from environment variables.
model –
The model identifier to use. Defaults to “openai/gpt-4o-2024-11-20”.
Deprecated since version 0.0.105: Use
settings=OpenRouterLLMService.Settings(model=...)instead.base_url – The base URL for OpenRouter API. Defaults to “https://openrouter.ai/api/v1”.
settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.**kwargs – Additional keyword arguments passed to OpenAILLMService.
- create_client(api_key=None, base_url=None, **kwargs)[source]
Create an OpenRouter API client.
- Parameters:
api_key – The API key to use for authentication. If None, uses instance default.
base_url – The base URL for the API. If None, uses instance default.
**kwargs – Additional arguments passed to the parent client creation method.
- Returns:
The configured OpenRouter API client instance.