Python client library for the XimaAI API
Project description
Control Panel for AI Apps
Features
The XimaAi SDK is built on top of the OpenAI SDK, allowing you to seamlessly integrate XimaAi's advanced features while retaining full compatibility with OpenAI methods. With XimaAi, you can enhance your interactions with OpenAI or any other OpenAI-like provider by leveraging robust monitoring, reliability, prompt management, and more features - without modifying much of your existing code.
AI Gateway
| Unified API Signature If you've used OpenAI, you already know how to use XimaAi with any other provider. |
Interoperability Write once, run with any provider. Switch between any model from_any provider seamlessly. |
| Automated Fallbacks & Retries Ensure your application remains functional even if a primary service fails. |
Load Balancing Efficiently distribute incoming requests among multiple models. |
| Semantic Caching Reduce costs and latency by intelligently caching results. |
Virtual Keys Secure your LLM API keys by storing them in XimaAi vault and using disposable virtual keys. |
| Request Timeouts Manage unpredictable LLM latencies effectively by setting custom request timeouts on requests. |
Observability
| Logging Keep track of all requests for monitoring and debugging. |
Requests Tracing Understand the journey of each request for optimization. |
| Custom Metadata Segment and categorize requests for better insights. |
Feedbacks Collect and analyse weighted feedback on requests from users. |
| Analytics Track your app & LLM's performance with 40+ production-critical metrics in a single place. |
Usage
Prerequisites
- Sign up on XimaAi and grab your XimaAi API Key
- Add your OpenAI key to XimaAi's Virtual Keys page and keep it handy
# Installing the SDK
$ pip install XimaAi-ai
$ export XimaAi_API_KEY=XimaAi_API_KEY
Making a Request to OpenAI
- XimaAi fully adheres to the OpenAI SDK signature. You can instantly switch to XimaAi and start using our production features right out of the box.
- Just replace
from openai import OpenAIwithfrom XimaAi_ai import XimaAi:
from XimaAi_ai import XimaAi
XimaAi = XimaAi(
api_key="XimaAi_API_KEY",
virtual_key="VIRTUAL_KEY"
)
chat_completion = XimaAi.chat.completions.create(
messages = [{ "role": 'user', "content": 'Say this is a test' }],
model = 'gpt-4'
)
print(chat_completion)
Async Usage
- Use
AsyncXimaAiinstead ofXimaAiwithawait:
import asyncio
from XimaAi_ai import AsyncXimaAi
XimaAi = AsyncXimaAi(
api_key="XimaAi_API_KEY",
virtual_key="VIRTUAL_KEY"
)
async def main():
chat_completion = await XimaAi.chat.completions.create(
messages=[{'role': 'user', 'content': 'Say this is a test'}],
model='gpt-4'
)
print(chat_completion)
asyncio.run(main())
Strands Agents Integration (optional)
Installation:
pip install 'XimaAi-ai[strands]'
Usage with Strands:
from strands.agent import Agent
from XimaAi_ai.integrations.strands import XimaAiStrands
model = XimaAiStrands(
api_key="XimaAi_API_KEY",
model_id="@openai/gpt-4o-mini",
# base_url="https://api.XimaAi.ai/v1", ## Optional
)
agent = Agent(model=model)
import asyncio
async def main():
result = await agent.invoke_async("Tell me a short programming joke.")
print(getattr(result, "text", result))
asyncio.run(main())
Google ADK Integration (optional)
Installation:
pip install 'XimaAi-ai[adk]'
Usage with ADK:
import asyncio
from google.adk.models.llm_request import LlmRequest
from google.genai import types
from XimaAi_ai.integrations.adk import XimaAiAdk
llm = XimaAiAdk(
api_key="XimaAi_API_KEY",
model="@openai/gpt-4o-mini",
# base_url="https://api.XimaAi.ai/v1", ## Optional
)
req = LlmRequest(
model="@openai/gpt-4o-mini",
contents=[
types.Content(
role="user",
parts=[types.Part.from_text(text="Tell me a short programming joke.")],
)
],
)
async def main():
# Print only partial chunks to avoid duplicate final output
async for resp in llm.generate_content_async(req, stream=True):
if getattr(resp, "partial", False) and resp.content and resp.content.parts:
for p in resp.content.parts:
if getattr(p, "text", None):
print(p.text, end="")
print()
asyncio.run(main())
Non-streaming example (single final response):
import asyncio
from google.adk.models.llm_request import LlmRequest
from google.genai import types
from XimaAi_ai.integrations.adk import XimaAiAdk
llm = XimaAiAdk(
api_key="XimaAi_API_KEY",
model="@openai/gpt-4o-mini",
)
req = LlmRequest(
model="@openai/gpt-4o-mini",
contents=[
types.Content(
role="user",
parts=[types.Part.from_text(text="Give me a one-line programming joke (final only).")],
)
],
)
async def main():
final_text = []
async for resp in llm.generate_content_async(req, stream=False):
if resp.content and resp.content.parts:
for p in resp.content.parts:
if getattr(p, "text", None):
final_text.append(p.text)
print("".join(final_text))
asyncio.run(main())
Configuration notes:
-
system_role: By default, the adapter sends the system instruction as a
developerrole message to align with ADK. If your provider expects a strictsystemrole, passsystem_role="system"when constructingXimaAiAdk.llm = XimaAiAdk( model="@openai/gpt-4o-mini", api_key="XimaAi_API_KEY", system_role="system", # switch from default "developer" )
-
Tools: When tools are present in the ADK request, the adapter sets
tool_choice="auto"to enable function calling by default (mirrors the Strands adapter behavior).
Compatibility with OpenAI SDK
XimaAi currently supports all the OpenAI methods, including the legacy ones.
| Methods | OpenAI V1.26.0 |
XimaAi V1.3.1 |
|---|---|---|
| Audio | ✅ | ✅ |
| Chat | ✅ | ✅ |
| Embeddings | ✅ | ✅ |
| Images | ✅ | ✅ |
| Fine-tuning | ✅ | ✅ |
| Batch | ✅ | ✅ |
| Files | ✅ | ✅ |
| Models | ✅ | ✅ |
| Moderations | ✅ | ✅ |
| Assistants | ✅ | ✅ |
| Threads | ✅ | ✅ |
| Thread - Messages | ✅ | ✅ |
| Thread - Runs | ✅ | ✅ |
| Thread - Run - Steps | ✅ | ✅ |
| Vector Store | ✅ | ✅ |
| Vector Store - Files | ✅ | ✅ |
| Vector Store - Files Batches | ✅ | ✅ |
| Generations | ❌ (Deprecated) | ✅ |
| Completions | ❌ (Deprecated) | ✅ |
XimaAi-Specific Methods
| Methods | XimaAi V1.3.1 |
|---|---|
| Feedback | ✅ |
| Prompts | ✅ |
Check out XimaAi docs for the full list of supported providers
Contributing
Get started by checking out Github issues. Email us at support@XimaAi.ai or just ping on Discord to chat.
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 xima_ai-2.1.0.tar.gz.
File metadata
- Download URL: xima_ai-2.1.0.tar.gz
- Upload date:
- Size: 568.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02a203fbd99cbfe414f1e8ebf5c8e0b8b1ea68dbd3b8d437493479e3dfd090cd
|
|
| MD5 |
ff8d07343e662cbbba6210554c261f3e
|
|
| BLAKE2b-256 |
2f430b91142baa53a858dfc091ce4927ca386cb78e283e70f02ba8df2b1a9fe2
|
File details
Details for the file xima_ai-2.1.0-py3-none-any.whl.
File metadata
- Download URL: xima_ai-2.1.0-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
106407897704fa49271c54d4ece53604e365f7788f9f4addba91d9e9d322f301
|
|
| MD5 |
789157d9dfc7716098d50571d02ccf2a
|
|
| BLAKE2b-256 |
cd56258a25091fc879256376b6666072c6b21b4dd9f99d5fdb6eff6a70d08c58
|