A minimal, generic client for AI models (OpenAI, Anthropic, Google, xAI) with middleware support.
Project description
aiclient
A minimal, unified, and resilient Python client for modern LLMs.
Supports OpenAI, Anthropic (Claude 3), Google (Gemini), and xAI (Grok) with a single, consistent interface.
Features
- 🦄 Unified Interface: Swap between providers without changing code.
- ⚡ Async & Sync: Native asyncio support for high-performance apps.
- 👁️ Multimodal: Send images and text seamlessly.
- 🛡️ Resilient: Automatic retries with exponential backoff for 429/5xx errors.
- 🤖 Agent Primitives: Built-in ReAct loop for tool-using agents.
- 🛠️ Tool Calling: Standardized function calling across providers.
- 📊 Middleware: Inspect requests, track costs, or log data.
Installation
pip install aiclient-llm
(Note: Not yet on PyPI, install from source/git)
Quick Start
Basic Chat
from aiclient import Client
client = Client(
api_key_openai="sk-...",
api_key_anthropic="sk-ant-..."
)
# Call OpenAI
response = client.chat("gpt-4o").generate("Hello!")
print(response.text)
# Call Claude
response = client.chat("claude-3-opus-20240229").generate("Hello!")
print(response.text)
Multimodal (Vision)
from aiclient.types import UserMessage, Text, Image
msg = UserMessage(content=[
Text(text="What's in this image?"),
Image(path="./image.png") # Handles base64 automatically
])
response = client.chat("gpt-4o").generate([msg])
print(response.text)
Agents (Tool Use)
from aiclient.agent import Agent
def get_weather(location: str):
return "Sunny in " + location
agent = Agent(
model=client.chat("gpt-4o"),
tools=[get_weather]
)
print(agent.run("Weather in SF?"))
Streaming
for chunk in client.chat("gpt-4o").stream("Write a poem"):
print(chunk.text, end="", flush=True)
Configuration
Retries
# Retries up to 3 times with backoff
client = Client(max_retries=3, retry_delay=1.0)
License
MIT
Project details
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 aiclient_llm-0.1.1.tar.gz.
File metadata
- Download URL: aiclient_llm-0.1.1.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7a6d178028564b213b1149ac13cacc26de498f8cec6e0cbec2cd36d874fc959
|
|
| MD5 |
3166a6d7b4fe69eda11c96b2bfd77cdd
|
|
| BLAKE2b-256 |
36f0143eaba4cf79677d4f7cc278ce4bade139314bfec85469bc379cf50795be
|
File details
Details for the file aiclient_llm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aiclient_llm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdb0d6b390e02dd3b1189f99558589bbb9213628a4fd56d8fb8ffe63a99c406b
|
|
| MD5 |
5c0be7ac6c2fcbbf021be78b44a1840b
|
|
| BLAKE2b-256 |
55a6d20f22d38a4cab40439a8489eb0c6464c8b484f958207fbdfa4462355f16
|