Unified SDK for multi-provider LLM comparison (Cerebras, AWS Bedrock) with OpenAI-compatible interface.
Project description
UnifiedAI SDK
OpenAI-compatible Python SDK unifying multiple providers (Cerebras, AWS Bedrock) with Solo and Comparison modes, strict models, and built‑in telemetry.
Highlights
- OpenAI-compatible API:
UnifiedAI().chat.completions.create(...)(sync) andAsyncUnifiedAI(async) - Multi-Provider Support: Cerebras and AWS Bedrock (extensible architecture)
- Dual Modes: Solo execution or side-by-side Comparison
- Rich Metrics: Duration, TTFB, tokens/sec, provider-specific timing
- Observability: Structured logs, Prometheus metrics, OpenTelemetry tracing hooks
- Flexible Credentials: Pass at client construction or use environment variables
Install
From PyPI (core):
pip install unifiedai-sdk
Optional extras:
# AWS Bedrock support (requires boto3)
pip install "unifiedai-sdk[bedrock]"
# HTTP/2 support for httpx
pip install "unifiedai-sdk[http2]"
From GitHub (optional):
pip install git+https://github.com/<your-org-or-user>/<your-repo>.git#subdirectory=cerebras
Usage
Sync (scripts/CLI)
Cerebras Example:
from unifiedai import UnifiedAI
client = UnifiedAI(
provider="cerebras",
model="llama3.1-8b",
credentials={"api_key": "csk-..."}, # or set CEREBRAS_KEY in env
)
resp = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}]
)
print(resp.choices[0].message["content"])
print(f"Tokens: {resp.usage.total_tokens}")
Bedrock Example:
from unifiedai import UnifiedAI
client = UnifiedAI(
provider="bedrock",
model="qwen.qwen3-32b-v1:0",
credentials={
"aws_access_key_id": "...",
"aws_secret_access_key": "...",
"region_name": "us-east-1"
}
)
resp = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}]
)
print(resp.choices[0].message["content"])
Async (web backends)
from unifiedai import AsyncUnifiedAI
async with AsyncUnifiedAI(provider="cerebras", model="llama3") as client:
resp = await client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}]
)
Streaming (async)
async with AsyncUnifiedAI(provider="cerebras", model="llama3") as client:
async for chunk in client.chat.completions.stream(
messages=[{"role": "user", "content": "Stream this"}]
):
print(chunk.delta.get("content", ""), end="")
Comparison (two providers)
from unifiedai import AsyncUnifiedAI
async with AsyncUnifiedAI(
credentials_by_provider={
"cerebras": {"api_key": "csk-..."},
"bedrock": {
"aws_access_key_id": "...",
"aws_secret_access_key": "...",
"region_name": "us-east-1"
}
}
) as client:
result = await client.compare(
providers=["cerebras", "bedrock"],
models={"cerebras": "llama3.1-8b", "bedrock": "qwen.qwen3-32b-v1:0"},
messages=[{"role": "user", "content": "Compare outputs"}],
)
print(f"Provider A: {result.provider_a.response.choices[0].message['content']}")
print(f"Provider B: {result.provider_b.response.choices[0].message['content']}")
print(f"Speed difference: {result.comparative_metrics.speed_difference_ms}ms")
Credentials
Cerebras
Set environment variable or pass credentials:
# Environment variable
export CEREBRAS_KEY="csk-..."
# Or pass directly
client = UnifiedAI(
provider="cerebras",
credentials={"api_key": "csk-..."}
)
AWS Bedrock
Set AWS credentials via environment or pass directly:
# Environment variables
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_REGION="us-east-1"
# Or pass directly
client = AsyncUnifiedAI(
provider="bedrock",
credentials={
"aws_access_key_id": "...",
"aws_secret_access_key": "...",
"region_name": "us-east-1"
}
)
Multi-Provider (Comparison Mode)
client = AsyncUnifiedAI(
credentials_by_provider={
"cerebras": {"api_key": "csk-..."},
"bedrock": {
"aws_access_key_id": "...",
"aws_secret_access_key": "...",
"region_name": "us-east-1"
}
}
)
Precedence: Direct credentials > Environment variables > IAM roles (for Bedrock)
FastAPI demo (Swagger UI)
uvicorn apps.chat.backend:app --reload --port 8000
# Swagger UI: http://localhost:8000/docs
Supported Models
Cerebras
llama3.1-8b- Llama 3.1 8Bllama3.1-70b- Llama 3.1 70Bqwen-3-32b- Qwen 3 32B
AWS Bedrock
qwen.qwen3-32b-v1:0- Qwen 3 32Banthropic.claude-3-haiku-20240307-v1:0- Claude 3 Haiku (fastest)anthropic.claude-3-sonnet-20240229-v1:0- Claude 3 Sonnetanthropic.claude-3-5-sonnet-20240620-v1:0- Claude 3.5 Sonnetmeta.llama3-70b-instruct-v1:0- Llama 3 70B
Note: Some Bedrock models require requesting access through the AWS Bedrock console.
Response Metrics
All responses include comprehensive metrics:
duration_ms: Total SDK round-trip timettfb_ms: Time to first byteround_trip_time_s: Total time in secondsinference_time_s: Provider-reported inference timeoutput_tokens_per_sec: Output generation speedtotal_tokens_per_sec: Overall token throughput
Project Structure
src/unifiedai/: SDK implementation_client.py,_async_client.py: Public API clientsadapters/: Provider implementations (Cerebras, Bedrock)models/: Pydantic data modelscore/: Comparison orchestrationmetrics/: Prometheus metrics
examples/: Usage examples (solo, streaming, comparison, Bedrock)apps/chat/: Demo FastAPI backend with comparison UItests/: Unit and integration tests
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unifiedai_sdk-1.0.6.tar.gz.
File metadata
- Download URL: unifiedai_sdk-1.0.6.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7402569939b10e27a5cc4aa4b6be869ac538c5ed190ef2ce0317c20673485404
|
|
| MD5 |
f55c1ba27f4e3d8a9111c7f38e1ab0da
|
|
| BLAKE2b-256 |
f3cb01e5e73956fada227d996a01a88c6174c3faa961dc32ebe9c8a4c4aa860e
|
File details
Details for the file unifiedai_sdk-1.0.6-py3-none-any.whl.
File metadata
- Download URL: unifiedai_sdk-1.0.6-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c5b97363af16fe3336150d2c110f16e7462fe524938de823c5fa3d91a7817db
|
|
| MD5 |
0566c3d05b39b644fa6bcf4b5f35f70b
|
|
| BLAKE2b-256 |
f2f2d631f0bd93ac10259dff26c7cda65186faad81007eacebd9e2649d8be913
|