Appearance
Elsai Model
Package: elsai-model v1.4.1
A unified interface to connect with multiple LLM providers. Every connector exposes the same .invoke() and .stream() API so you can swap providers without changing application code.
Installation
bash
pip install --extra-index-url https://core-packages.elsai.ai/root/elsai-model/ elsai-model==1.4.1Requirements: Python >= 3.9, .env with API keys
Connectors
1. OpenAIConnector
python
from elsai_model.openai import OpenAIConnector
llm = OpenAIConnector(
openai_api_key="your_openai_api_key", # or OPENAI_API_KEY env var
model_name="gpt-4o-mini",
temperature=0.1,
implementation="native" # or "langchain" (v1.3.0+)
)
messages = [{"role": "user", "content": "Tell me a short joke."}]
response = llm.invoke(messages=messages)
# Streaming (v1.0.1+)
for chunk in llm.stream(messages=messages):
print(chunk, end='', flush=True)Environment variables: OPENAI_API_KEY, OPENAI_MODEL_NAME, OPENAI_TEMPERATURE
:::note v1.3.0 added implementation parameter — choose 'native' (default) or 'langchain'. :::
2. AzureOpenAIConnector
python
from elsai_model.azure_openai import AzureOpenAIConnector
llm = AzureOpenAIConnector(
azure_endpoint="https://your-resource.openai.azure.com/",
openai_api_key="your-key",
openai_api_version="2023-05-15",
deployment_name="gpt-4o-mini",
temperature=0.1,
implementation="native" # or "langchain" (v1.3.0+)
)
response = llm.invoke(messages=[{"role": "user", "content": "Hello!"}])Environment variables: AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, OPENAI_API_VERSION, AZURE_OPENAI_DEPLOYMENT_NAME
3. BedrockConnector
Native boto3-based implementation — lower latency, fewer dependencies than the previous LangChain version.
python
from elsai_model.bedrock import BedrockConnector
llm = BedrockConnector(
aws_access_key="your_key",
aws_secret_key="your_secret",
aws_region="us-east-1",
model_id="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
max_tokens=500,
temperature=0.1,
)
result = llm.invoke([{"role": "user", "content": "What is the capital of France?"}])
# Streaming (v1.1.0+)
for chunk in llm.invoke_model_with_response_stream(messages):
print(chunk, end='', flush=True)
# Image OCR (v1.2.0+)
ocr_output = llm.invoke_with_image(image_path="scan.png", prompt="Transcribe all text.")Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, BEDROCK_MODEL_ID
:::note v1.1.1 — Updated to use the Messages API, fixing ValidationException with Claude Sonnet 4 models. v1.2.2 — .invoke() now returns the full response object instead of plain text. :::
4. AnthropicBedrockConnector
Specialized connector for Anthropic Claude models through AWS Bedrock.
python
from elsai_model.anthropic_bedrock import AnthropicBedrockConnector
connector = AnthropicBedrockConnector(
model_id="your_anthropic_bedrock_model_id",
max_tokens=500,
temperature=0.7,
aws_access_key="your_key",
aws_secret_key="your_secret",
aws_region="us-east-1",
)
response = connector.invoke(messages)
for chunk in connector.invoke_with_stream(messages):
print(chunk, end='', flush=True):::note Available from elsai-model v1.1.0. :::
5. GeminiService
python
from elsai_model.gemini import GeminiService
service = GeminiService(api_key="your_gemini_api_key", model="gemini-2.5-flash")
# Single-shot
result = service.generate_text("What is AI?")
# Streaming
for chunk in service.stream_text("Tell me a short story"):
print(chunk, end="", flush=True)
# Multi-turn chat
chat = service.create_chat()
chat.send_message("I have 2 dogs.")
chat.send_message("How many paws in my house?")
# Streaming chat
for chunk in chat.send_message_stream("Explain in detail"):
print(chunk, end="", flush=True)
# View chat history
history = chat.get_history()
# Multimodal
response = service.generate_with_image(image_path="photo.png", prompt="Describe this image.")Environment variables: GEMINI_API_KEY
Logprobs support v1.2.1+
Logprobs expose token-level log probabilities and the top alternative tokens the model considered at each position. Use them for confidence scoring, uncertainty detection, calibration analysis, and debugging model behaviour.
Two parameters control logprobs:
| Parameter | Type | Description |
|---|---|---|
response_logprobs | bool | Enable logprobs in the response |
logprobs | int | Number of top alternative tokens to return per position |
Logprobs are supported on generate_text(), stream_text(), and generate_with_image().
Basic example:
python
from elsai_model.gemini import GeminiService
service = GeminiService(api_key="your_gemini_api_key", model="gemini-2.5-flash")
result = service.generate_text(
"What is Artificial Intelligence?",
response_logprobs=True,
logprobs=5, # return top 5 alternative tokens at each position
)
print(result)Streaming with logprobs:
python
for chunk in service.stream_text(
"Explain quantum computing",
response_logprobs=True,
logprobs=3,
):
print(chunk, end="", flush=True)Multimodal with logprobs:
python
result = service.generate_with_image(
image_path="chart.png",
prompt="What trend does this chart show?",
response_logprobs=True,
logprobs=5,
)Confidence scoring example:
python
import math
result = service.generate_text(
"Is the capital of France Paris?",
response_logprobs=True,
logprobs=1,
)
# Convert log probability to linear probability for the first token
# result.candidates[0].logprobs_result contains the token data
candidates = result.candidates[0].logprobs_result.chosen_candidates
first_token_logprob = candidates[0].log_probability
confidence = math.exp(first_token_logprob)
print(f"Model confidence on first token: {confidence:.2%}")6. LiteLLMConnector
Single consistent interface across all providers.
python
from elsai_model.litellm import LiteLLMConnector
connector = LiteLLMConnector(
model_name="openai/gpt-4o-mini", # format: provider/model
temperature=0.1
)
response = connector.invoke(messages=[{"content": "Hello!", "role": "user"}])Model name formats: openai/gpt-4o-mini · azure/deployment-name · bedrock/model-id
7. Async connectors
Both OpenAI and Azure OpenAI have async variants for high-throughput workloads.
python
from elsai_model.openai import AsyncOpenAIConnector
from elsai_model.azure_openai import AsyncAzureOpenAIConnector
async def run():
connector = AsyncOpenAIConnector(model_name="gpt-4o-mini", temperature=0.1)
response = await connector.invoke([{"role": "user", "content": "Hello!"}])
async for chunk in connector.stream(messages=[{"role": "user", "content": "Hello!"}]):
print(chunk, end='', flush=True)Version history
| Version | Changes |
|---|---|
| 1.4.1 | Current stable release |
| 1.3.0 | implementation param for native vs LangChain in OpenAI/Azure connectors |
| 1.2.2 | All connectors return full response object instead of plain text |
| 1.2.1 | Gemini logprobs support |
| 1.2.0 | Bedrock invoke_with_image for OCR |
| 1.1.2 | Gemini response format change |
| 1.1.1 | Bedrock updated to Messages API (Claude Sonnet 4 support) |
| 1.1.0 | AnthropicBedrockConnector added; Bedrock streaming |
| 1.0.1 | Streaming for OpenAI and Azure OpenAI |
| 1.0.0 | Gemini and LiteLLM added; native Bedrock boto3 implementation |