Models¶
Sonika AI Toolkit supports five LLM providers. All implement the ILanguageModel interface with predict(), invoke(), and stream_response() methods.
OpenAI¶
from sonika_ai_toolkit import OpenAILanguageModel
llm = OpenAILanguageModel(
api_key="sk-...",
model_name="gpt-4o-mini", # default
temperature=0.7,
)
Supported models: gpt-4o, gpt-4o-mini, gpt-4-turbo, o1, o1-mini, etc.
Google Gemini¶
from sonika_ai_toolkit import GeminiLanguageModel
llm = GeminiLanguageModel(
api_key="...",
model_name="gemini-2.5-flash",
temperature=0.7,
)
Thinking models
Gemini thinking models (gemini-2.5-*, *-thinking, *thinking-exp*) require temperature=1.0 — this is automatically overridden with a warning.
Thinking model behavior: When include_thoughts=True, response.content is a list containing thinking and text blocks. The toolkit handles this automatically.
DeepSeek¶
from sonika_ai_toolkit import DeepSeekLanguageModel
llm = DeepSeekLanguageModel(
api_key="...",
model_name="deepseek-chat", # or "deepseek-reasoner"
)
DeepSeek Reasoner
deepseek-reasoner (and models with r1 in the name) uses a custom _DeepSeekReasonerChatModel that captures reasoning_content. It does not support tool calling — a ValueError is raised if tools are provided.
Anthropic (Claude)¶
from sonika_ai_toolkit import AnthropicLanguageModel
llm = AnthropicLanguageModel(
api_key="sk-ant-...",
model_name="claude-haiku-4-5", # default
temperature=0.7,
max_tokens=4096, # Anthropic requires max_tokens
)
Supported models: claude-haiku-4-5, claude-sonnet-4-6, claude-opus-4-8, etc.
Extended thinking
Pass thinking_budget=N to enable extended thinking. This forces temperature=1.0 (with a warning) and raises max_tokens above the budget. As with Gemini, thinking responses return content as a list of blocks; the toolkit strips the thinking blocks automatically.
Amazon Bedrock¶
from sonika_ai_toolkit import BedrockLanguageModel
llm = BedrockLanguageModel(
api_key="...",
model_name="amazon.nova-micro-v1:0",
region="us-east-1",
)
The AWS_BEARER_TOKEN_BEDROCK env var is set automatically during initialization.
ILanguageModel Interface¶
All models implement:
from sonika_ai_toolkit import ILanguageModel
class ILanguageModel(ABC):
model: BaseChatModel # underlying LangChain model
def predict(self, prompt: str) -> str: ...
def invoke(self, prompt: str) -> ResponseModel: ...
def stream_response(self, prompt: str) -> Iterator: ...
Type-hint against ILanguageModel for provider-agnostic code: