Model base class provides a consistent interface for invoking any supported LLM provider, whether synchronously, asynchronously, or via streaming.
Supported Providers
| Provider | Class | Default Model | Docs |
|---|---|---|---|
| OpenAI | OpenAIChat | gpt-4o | OpenAI |
| DeepSeek | DeepSeekChat | deepseek-chat | DeepSeek |
| Moonshot | MoonshotChat | kimi-k2-turbo-preview | Moonshot |
| xAI | xAI | grok-beta | xAI |
| Custom | OpenAILike | — | OpenAI-Like |
Basic Usage
Common Parameters
All model classes accept these parameters:The model identifier (e.g.,
"gpt-4o", "deepseek-chat").API key for authentication. Defaults to the provider’s environment variable.
Override the API base URL. Useful for proxies or self-hosted endpoints.
Sampling temperature (0.0 to 2.0). Lower values are more deterministic.
Maximum number of tokens to generate.
Request timeout in seconds.
Maximum number of retries on transient failures.
Invocation Methods
Every model supports four ways to call it:| Method | Sync/Async | Streaming | Returns |
|---|---|---|---|
invoke() | Sync | No | ModelResponse |
ainvoke() | Async | No | ModelResponse |
invoke_stream() | Sync | Yes | Iterator[ModelResponse] |
ainvoke_stream() | Async | Yes | AsyncIterator[ModelResponse] |
Retry Configuration
All models support automatic retries with configurable backoff:Number of retry attempts on failure.
Base delay in seconds between retries.
Whether to use exponential backoff for retries.
Response Caching
Cache model responses locally for development and testing:Model Resolution from Strings
You can resolve a model from a"provider:model-id" string: