omniai-kit 1.0.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omniai_kit-1.1.0/PKG-INFO +438 -0
- omniai_kit-1.1.0/README.md +389 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/__init__.py +57 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/_version.py +1 -1
- omniai_kit-1.1.0/omniai/client.py +536 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/resources/__init__.py +6 -0
- omniai_kit-1.1.0/omniai/resources/agents.py +716 -0
- omniai_kit-1.1.0/omniai/resources/chat.py +607 -0
- omniai_kit-1.1.0/omniai/resources/keys.py +222 -0
- omniai_kit-1.1.0/omniai/resources/livekit.py +116 -0
- omniai_kit-1.1.0/omniai/resources/models.py +185 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/resources/tasks.py +78 -26
- omniai_kit-1.1.0/omniai/types/__init__.py +60 -0
- omniai_kit-1.1.0/omniai/types/agents.py +91 -0
- omniai_kit-1.1.0/omniai/types/chat.py +139 -0
- omniai_kit-1.1.0/omniai/types/keys.py +41 -0
- omniai_kit-1.1.0/omniai/types/livekit.py +47 -0
- omniai_kit-1.1.0/omniai/types/models.py +51 -0
- omniai_kit-1.1.0/omniai_kit.egg-info/PKG-INFO +438 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai_kit.egg-info/SOURCES.txt +6 -1
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/pyproject.toml +2 -2
- omniai_kit-1.1.0/tests/test_v1_features.py +391 -0
- omniai_kit-1.0.0/PKG-INFO +0 -270
- omniai_kit-1.0.0/README.md +0 -221
- omniai_kit-1.0.0/omniai/client.py +0 -316
- omniai_kit-1.0.0/omniai/resources/chat.py +0 -403
- omniai_kit-1.0.0/omniai/resources/livekit.py +0 -71
- omniai_kit-1.0.0/omniai/resources/models.py +0 -63
- omniai_kit-1.0.0/omniai/types/__init__.py +0 -27
- omniai_kit-1.0.0/omniai/types/chat.py +0 -48
- omniai_kit-1.0.0/omniai/types/livekit.py +0 -17
- omniai_kit-1.0.0/omniai/types/models.py +0 -30
- omniai_kit-1.0.0/omniai_kit.egg-info/PKG-INFO +0 -270
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/LICENSE +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/_base.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/_constants.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/exceptions.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/py.typed +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/resources/router.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai/types/tasks.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai_kit.egg-info/dependency_links.txt +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai_kit.egg-info/requires.txt +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/omniai_kit.egg-info/top_level.txt +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/setup.cfg +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_async_client.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_client.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_exceptions.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_providers.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_retry.py +0 -0
- {omniai_kit-1.0.0 → omniai_kit-1.1.0}/tests/test_router.py +0 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: omniai-kit
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Official Python client SDK for OmniAI Gateway and Dynamic Multi-Provider LLM Router
|
|
5
|
+
Author-email: OmniAI Team <dev@omniai.ai>, Jayed Bin Jahangir <jayedbinjahangir@gmail.com>
|
|
6
|
+
Maintainer-email: Jayed Bin Jahangir <jayedbinjahangir@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://omniai.go-agents.app
|
|
9
|
+
Project-URL: Documentation, https://omniai.go-agents.app/docs
|
|
10
|
+
Project-URL: Repository, https://github.com/jayeeed/omniai-sdk
|
|
11
|
+
Project-URL: Issues, https://github.com/jayeeed/omniai-sdk/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/jayeeed/omniai-sdk
|
|
13
|
+
Keywords: omniai,llm,ai,gateway,router,openai,gemini,anthropic,vllm,livekit,sdk
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: httpx>=0.27.0
|
|
30
|
+
Requires-Dist: pydantic>=2.0.0
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: openai>=1.0.0; extra == "all"
|
|
33
|
+
Requires-Dist: google-genai>=0.1.0; extra == "all"
|
|
34
|
+
Requires-Dist: anthropic>=0.20.0; extra == "all"
|
|
35
|
+
Provides-Extra: openai
|
|
36
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
37
|
+
Provides-Extra: gemini
|
|
38
|
+
Requires-Dist: google-genai>=0.1.0; extra == "gemini"
|
|
39
|
+
Provides-Extra: anthropic
|
|
40
|
+
Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
|
|
41
|
+
Provides-Extra: vllm
|
|
42
|
+
Requires-Dist: openai>=1.0.0; extra == "vllm"
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
46
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# OmniAI Kit (`omniai-kit`) 🚀
|
|
51
|
+
|
|
52
|
+
[](https://pypi.org/project/omniai-kit/)
|
|
53
|
+
[](https://github.com/jayeeed/omniai-sdk)
|
|
54
|
+
[](https://pypi.org/project/omniai-kit/)
|
|
55
|
+
[](https://opensource.org/licenses/MIT)
|
|
56
|
+
[](https://peps.python.org/pep-0561/)
|
|
57
|
+
[](https://omniai.go-agents.app)
|
|
58
|
+
|
|
59
|
+
Official Python Client SDK for the **OmniAI Platform & Universal AI Gateway** — providing zero-config multi-provider LLM routing, real-time SSE token streaming, native Pydantic structured outputs, extended reasoning token budgets (`thinking`), background task queues, Custom AI Agents with RAG knowledge bases, scoped API key management, and real-time WebRTC multimodal live voice/video sessions.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ⚡ Key Capabilities
|
|
64
|
+
|
|
65
|
+
- **Zero-Configuration Setup:** Auto-discovers credentials (`OMNIAI_API_KEY`, `OMNI_API_KEY`, `X_API_KEY`) and defaults to `https://omniai.go-agents.app`.
|
|
66
|
+
- **Modern Resource Architecture:** Clean OpenAI-style resource hierarchy (`client.chat.completions.create`, `client.models.list`, `client.tasks.submit`, `client.livekit.create_session`, `client.agents`, `client.keys`) plus ergonomic top-level shortcuts (`client.chat`, `client.stream`, `client.execute_agent`).
|
|
67
|
+
- **Full Response & Billing Visibility:** Pass `full_response=True` to inspect completion ID, exact micro-dollar request cost (`0.000001`), cumulative API key spend, remaining budget, account tier, and granular prompt token details (`system_tokens`, `input_tokens`).
|
|
68
|
+
- **Extended Reasoning / Thinking Tokens:** Pass `thinking=1024` for reasoning models (e.g. Gemini 3.7 Flash, Claude 3.7 Sonnet, o3-mini) with automatic thinking block handling.
|
|
69
|
+
- **Synchronous & Asynchronous:** Identical API surfaces for both synchronous (`OmniaiClient`) and async (`AsyncOmniaiClient`) applications.
|
|
70
|
+
- **Strongly Typed Pydantic Schemas:** Pass Pydantic models directly to `response_model` for guaranteed schema validation and markdown JSON stripping.
|
|
71
|
+
- **Custom AI Agents & RAG:** Create autonomous agents, upload documents to Qdrant vector knowledge bases, attach dynamic tools, and execute agents with context.
|
|
72
|
+
- **Scoped API Key Management:** Programmatically provision API keys with spending limits (`total_limit`), expiration dates (`expires_at`), and model access control (`allowed_models`).
|
|
73
|
+
- **Enterprise Fault Tolerance:** Built-in exponential backoff with full jitter, honoring upstream `Retry-After` headers on 429 and 5xx errors.
|
|
74
|
+
- **LiveKit Multimodal Sessions:** Generate signed WebRTC access tokens for ultra-low latency Gemini Live audio and video agents.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 📦 Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install omniai-kit
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Optional Provider Dependencies (for direct standalone routing)
|
|
85
|
+
```bash
|
|
86
|
+
pip install "omniai-kit[all]" # Installs all upstream provider SDKs
|
|
87
|
+
pip install "omniai-kit[openai]" # Installs OpenAI SDK
|
|
88
|
+
pip install "omniai-kit[gemini]" # Installs Google GenAI SDK
|
|
89
|
+
pip install "omniai-kit[anthropic]" # Installs Anthropic SDK
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🏛️ Supported Model Providers
|
|
95
|
+
|
|
96
|
+
OmniAI natively routes, caches, and normalizes parameters across the following providers:
|
|
97
|
+
|
|
98
|
+
| Provider | Schema | Example Models |
|
|
99
|
+
| :--- | :--- | :--- |
|
|
100
|
+
| **Google Gemini** | `gemini:<model>` | `gemini:gemini-2.5-flash`, `gemini:gemini-3.7-flash`, `gemini-3.8-live` |
|
|
101
|
+
| **OpenAI** | `openai:<model>` | `openai:gpt-4o`, `openai:o3-mini`, `openai:gpt-4o-mini` |
|
|
102
|
+
| **Anthropic** | `anthropic:<model>` | `anthropic:claude-3-7-sonnet`, `anthropic:claude-3-5-haiku` |
|
|
103
|
+
| **OpenRouter** | `openrouter:<model>` | `openrouter:inclusionai/ling-3.2-flash:free`, `openrouter:meta-llama/llama-3.3-70b-instruct` |
|
|
104
|
+
| **vLLM (Self-Hosted)** | `vllm:<model>` | `vllm:meta-llama/Llama-3.1-8B-Instruct` |
|
|
105
|
+
| **Ollama (Local)** | `ollama:<model>` | `ollama:qwen2.5-coder:7b` |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 🚀 Usage Guide
|
|
110
|
+
|
|
111
|
+
### 1. Basic Chat Completion
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from omniai import OmniaiClient
|
|
115
|
+
|
|
116
|
+
# Automatically discovers OMNIAI_API_KEY from environment or .env
|
|
117
|
+
client = OmniaiClient()
|
|
118
|
+
|
|
119
|
+
response = client.chat(
|
|
120
|
+
model="gemini:gemini-2.5-flash",
|
|
121
|
+
prompt="Explain distributed event streaming in two concise sentences.",
|
|
122
|
+
)
|
|
123
|
+
print(response)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Both direct shortcut and resource styles are supported:
|
|
127
|
+
```python
|
|
128
|
+
# Shortcut style
|
|
129
|
+
response = client.chat(model="gemini:gemini-2.5-flash", prompt="Hello!")
|
|
130
|
+
|
|
131
|
+
# Resource hierarchy style (OpenAI-compatible)
|
|
132
|
+
response = client.chat.completions.create(model="gemini:gemini-2.5-flash", prompt="Hello!")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### 2. Full Response Envelope & Billing Inspection
|
|
138
|
+
|
|
139
|
+
Pass `full_response=True` to inspect exact token counts, cache hits, and request cost:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from omniai import OmniaiClient, ChatCompletionResponse
|
|
143
|
+
|
|
144
|
+
client = OmniaiClient()
|
|
145
|
+
|
|
146
|
+
resp: ChatCompletionResponse = client.chat(
|
|
147
|
+
model="openrouter:inclusionai/ling-3.2-flash:free",
|
|
148
|
+
prompt="Explain quantum entanglement briefly.",
|
|
149
|
+
full_response=True,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
print(f"Result: {resp.result}")
|
|
153
|
+
print(f"ID: {resp.id}")
|
|
154
|
+
print(f"Cached: {resp.cached}")
|
|
155
|
+
print(f"Tokens: {resp.usage.total_tokens} (prompt={resp.usage.prompt_tokens}, completion={resp.usage.completion_tokens})")
|
|
156
|
+
print(f" System Tokens: {resp.usage.details.system_tokens}")
|
|
157
|
+
print(f" User Input Tokens: {resp.usage.details.input_tokens}")
|
|
158
|
+
print(f"Request Cost: ${resp.billing.request_cost:.6f} USD")
|
|
159
|
+
print(f"Key Cumulative Spend: ${resp.billing.api_key.spent:.6f} USD")
|
|
160
|
+
print(f"Account Balance Remaining: ${resp.billing.account.balance_remaining:.6f} USD")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
### 3. Extended Reasoning / Thinking Budget
|
|
166
|
+
|
|
167
|
+
Allocate reasoning tokens for models that support chain-of-thought thinking (e.g. Gemini 3.7 Flash, Claude 3.7 Sonnet):
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
response = client.chat(
|
|
171
|
+
model="gemini:gemini-3.7-flash",
|
|
172
|
+
prompt="How many r's are in strawberry?",
|
|
173
|
+
thinking=1024, # Allocates 1,024 reasoning tokens
|
|
174
|
+
)
|
|
175
|
+
print(response)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 4. Real-Time Token Streaming
|
|
181
|
+
|
|
182
|
+
Stream completions token-by-token with Server-Sent Events (SSE):
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from omniai import OmniaiClient
|
|
186
|
+
|
|
187
|
+
client = OmniaiClient()
|
|
188
|
+
|
|
189
|
+
print("Assistant: ", end="", flush=True)
|
|
190
|
+
for token in client.stream(
|
|
191
|
+
model="gemini:gemini-2.5-flash",
|
|
192
|
+
prompt="List 3 key architectural benefits of event-driven microservices.",
|
|
193
|
+
):
|
|
194
|
+
print(token, end="", flush=True)
|
|
195
|
+
print()
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
### 5. Strongly Typed Structured Outputs (Pydantic V2)
|
|
201
|
+
|
|
202
|
+
Pass any Pydantic class to `response_model`. The SDK extracts JSON schema, enforces structured output from the model, and automatically parses and validates the response into your Python model:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from typing import List
|
|
206
|
+
from pydantic import BaseModel, Field
|
|
207
|
+
from omniai import OmniaiClient
|
|
208
|
+
|
|
209
|
+
class ServiceArchitecture(BaseModel):
|
|
210
|
+
service_name: str = Field(description="Name of the service")
|
|
211
|
+
patterns: List[str] = Field(description="Design patterns applied")
|
|
212
|
+
availability_sla: float = Field(description="Target SLA percentage")
|
|
213
|
+
|
|
214
|
+
client = OmniaiClient()
|
|
215
|
+
|
|
216
|
+
analysis: ServiceArchitecture = client.chat(
|
|
217
|
+
model="gemini:gemini-2.5-flash",
|
|
218
|
+
prompt="Design a high-throughput payment processing service.",
|
|
219
|
+
response_model=ServiceArchitecture,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
print(f"Service: {analysis.service_name}")
|
|
223
|
+
print(f"Patterns: {analysis.patterns}")
|
|
224
|
+
print(f"Target SLA: {analysis.availability_sla}%")
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
### 6. Custom AI Agents & Vector Knowledge Bases
|
|
230
|
+
|
|
231
|
+
Create autonomous custom agents, ingest reference documents into Qdrant vector memory, and execute queries:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
from omniai import OmniaiClient
|
|
235
|
+
|
|
236
|
+
client = OmniaiClient()
|
|
237
|
+
|
|
238
|
+
# 1. Create a custom agent
|
|
239
|
+
agent = client.agents.create(
|
|
240
|
+
name="Refund Policy Assistant",
|
|
241
|
+
prompt="You are a refund specialist. Answer user questions strictly based on the company's 30-day guarantee.",
|
|
242
|
+
model="gemini:gemini-3.8-flash",
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
# 2. Add document to agent's vectorized knowledge base
|
|
246
|
+
client.agents.knowledge.add(
|
|
247
|
+
agent_id=agent.id,
|
|
248
|
+
title="Refund Policy v2",
|
|
249
|
+
content="Customers can request a 100% refund within 30 days of purchase for unopened items.",
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# 3. Execute the agent
|
|
253
|
+
answer = client.execute_agent(
|
|
254
|
+
agent_id=agent.id,
|
|
255
|
+
message="What is the refund window for an unopened box?",
|
|
256
|
+
)
|
|
257
|
+
print("Agent:", answer)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
### 7. Scoped API Key Management
|
|
263
|
+
|
|
264
|
+
Programmatically provision, monitor, and revoke API keys with spend quotas and allowed models:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from omniai import OmniaiClient
|
|
268
|
+
|
|
269
|
+
client = OmniaiClient()
|
|
270
|
+
|
|
271
|
+
# 1. Create API key with $25 lifetime spend limit and model restrictions
|
|
272
|
+
new_key = client.keys.create(
|
|
273
|
+
name="staging-bot",
|
|
274
|
+
total_limit=25.0, # $25.00 lifetime spending limit
|
|
275
|
+
allowed_models=["openai:gpt-4o", "gemini:gemini-3.7-flash"],
|
|
276
|
+
expires_at="2027-12-31T23:59:59Z",
|
|
277
|
+
)
|
|
278
|
+
print(f"Key created: {new_key.name} -> {new_key.key}")
|
|
279
|
+
|
|
280
|
+
# 2. List all active keys
|
|
281
|
+
keys = client.keys.list()
|
|
282
|
+
for k in keys:
|
|
283
|
+
print(f"Key: {k.name} | Spent: ${k.current_spend:.4f} / ${k.total_limit or 'Unlimited'}")
|
|
284
|
+
|
|
285
|
+
# 3. Revoke key
|
|
286
|
+
client.keys.delete(new_key.id)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### 8. LiveKit Multimodal Real-Time Voice & Video
|
|
292
|
+
|
|
293
|
+
Create WebRTC sessions for sub-second bidirectional voice and vision agents:
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
from omniai import OmniaiClient
|
|
297
|
+
|
|
298
|
+
client = OmniaiClient()
|
|
299
|
+
|
|
300
|
+
session = client.create_live_session(
|
|
301
|
+
model="gemini-3.8-live",
|
|
302
|
+
voice="Aoede",
|
|
303
|
+
video_input=True,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
print(f"LiveKit Server: {session.server_url}")
|
|
307
|
+
print(f"Room: {session.room_name}")
|
|
308
|
+
print(f"Token: {session.participant_token}")
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
### 9. Asynchronous Client (`AsyncOmniaiClient`)
|
|
314
|
+
|
|
315
|
+
Full async/await parity for high-concurrency microservices, FastAPI, and async workers:
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
import asyncio
|
|
319
|
+
from omniai import AsyncOmniaiClient
|
|
320
|
+
|
|
321
|
+
async def main():
|
|
322
|
+
async with AsyncOmniaiClient() as client:
|
|
323
|
+
# Async chat with reasoning tokens
|
|
324
|
+
res = await client.chat(
|
|
325
|
+
model="gemini:gemini-3.7-flash",
|
|
326
|
+
prompt="Summarize CQRS in 20 words.",
|
|
327
|
+
thinking=1024,
|
|
328
|
+
)
|
|
329
|
+
print("Response:", res)
|
|
330
|
+
|
|
331
|
+
# Async streaming
|
|
332
|
+
print("Streaming: ", end="", flush=True)
|
|
333
|
+
async for chunk in client.stream(
|
|
334
|
+
model="gemini:gemini-2.5-flash",
|
|
335
|
+
prompt="Count from 1 to 5.",
|
|
336
|
+
):
|
|
337
|
+
print(chunk, end="", flush=True)
|
|
338
|
+
print()
|
|
339
|
+
|
|
340
|
+
asyncio.run(main())
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 🔑 Authentication & Configuration
|
|
346
|
+
|
|
347
|
+
`OmniaiClient` and `AsyncOmniaiClient` resolve configuration in the following order:
|
|
348
|
+
|
|
349
|
+
| Setting | 1. Explicit Argument | 2. Environment Variables (`.env`) | 3. Default Fallback |
|
|
350
|
+
| :--- | :--- | :--- | :--- |
|
|
351
|
+
| **`api_key`** | `OmniaiClient(api_key="...")` | `OMNIAI_API_KEY` → `OMNI_API_KEY` → `X_API_KEY` | `""` |
|
|
352
|
+
| **`base_url`** | `OmniaiClient(base_url="...")` | `OMNIAI_BASE_URL` → `OMNI_BASE_URL` → `GATEWAY_URL` | `"https://omniai.go-agents.app"` |
|
|
353
|
+
| **`timeout`** | `OmniaiClient(timeout=30.0)` | — | `60.0` seconds |
|
|
354
|
+
| **`max_retries`**| `OmniaiClient(max_retries=5)`| — | `3` attempts |
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## 🛡️ Exception Hierarchy
|
|
359
|
+
|
|
360
|
+
All SDK exceptions inherit from `OmniaiError`:
|
|
361
|
+
|
|
362
|
+
```text
|
|
363
|
+
OmniaiError
|
|
364
|
+
├── OmniaiAuthError # HTTP 401 / 403 (Invalid or revoked API key)
|
|
365
|
+
├── OmniaiPaymentRequiredError # HTTP 402 (Prepaid credit balance exhausted)
|
|
366
|
+
├── OmniaiNotFoundError # HTTP 404 (Resource or model not found)
|
|
367
|
+
├── OmniaiRateLimitError # HTTP 429 (Rate limit exceeded; includes .retry_after)
|
|
368
|
+
├── OmniaiTimeoutError # Request or polling timeout
|
|
369
|
+
├── OmniaiConnectionError # DNS, connection drop, network failure
|
|
370
|
+
├── OmniaiExecutionError # HTTP 5xx or upstream provider execution failure
|
|
371
|
+
├── OmniaiValidationError # Output failed Pydantic schema validation
|
|
372
|
+
└── OmniaiUnsupportedProviderError # Request for an unsupported provider prefix
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## 📂 Repository Directory Layout
|
|
378
|
+
|
|
379
|
+
```text
|
|
380
|
+
omniai-sdk/
|
|
381
|
+
├── omniai/
|
|
382
|
+
│ ├── resources/ # Modular resource namespaces
|
|
383
|
+
│ │ ├── chat.py # Chat completions & SSE streaming
|
|
384
|
+
│ │ ├── agents.py # Custom AI agents & RAG knowledge
|
|
385
|
+
│ │ ├── keys.py # Scoped API key management
|
|
386
|
+
│ │ ├── livekit.py # Multimodal WebRTC voice/video
|
|
387
|
+
│ │ ├── models.py # Foundation models catalog
|
|
388
|
+
│ │ ├── router.py # Multi-provider LLM router
|
|
389
|
+
│ │ └── tasks.py # Celery background tasks
|
|
390
|
+
│ ├── types/ # Typed Pydantic schemas
|
|
391
|
+
│ │ ├── chat.py # Response, usage, billing envelopes
|
|
392
|
+
│ │ ├── agents.py # Agent, tool, knowledge models
|
|
393
|
+
│ │ ├── keys.py # API key records
|
|
394
|
+
│ │ ├── livekit.py # Live session credentials
|
|
395
|
+
│ │ ├── models.py # Foundation model metadata
|
|
396
|
+
│ │ └── tasks.py # Task handles and job wrappers
|
|
397
|
+
│ ├── __init__.py # Top-level SDK exports
|
|
398
|
+
│ ├── _base.py # Base HTTP transport & retry policy
|
|
399
|
+
│ ├── _constants.py # Default constants & endpoints
|
|
400
|
+
│ ├── _version.py # Package version (1.1.0)
|
|
401
|
+
│ ├── client.py # OmniaiClient & AsyncOmniaiClient
|
|
402
|
+
│ ├── exceptions.py # Typed exception hierarchy
|
|
403
|
+
│ └── py.typed # PEP 561 typing compliance
|
|
404
|
+
├── examples/
|
|
405
|
+
│ ├── quickstart.py
|
|
406
|
+
│ ├── streaming.py
|
|
407
|
+
│ ├── structured_output.py
|
|
408
|
+
│ ├── async_chat.py
|
|
409
|
+
│ ├── thinking_reasoning.py
|
|
410
|
+
│ ├── custom_agents.py
|
|
411
|
+
│ └── api_keys.py
|
|
412
|
+
├── tests/ # Unit and integration test suite
|
|
413
|
+
├── test.py # Root verification script
|
|
414
|
+
├── pyproject.toml # PEP 517/621 packaging metadata
|
|
415
|
+
└── README.md # Documentation & Guides
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## 🧪 Testing
|
|
421
|
+
|
|
422
|
+
Run the test suite with `pytest`:
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
pytest tests
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Or run the root verification script:
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
python test.py
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
## 📄 License
|
|
437
|
+
|
|
438
|
+
MIT © [OmniAI Team](https://omniai.go-agents.app) — Jayed Bin Jahangir
|