Skip to main content

A minimal, generic client for AI models (OpenAI, Anthropic, Google, xAI) with middleware support.

Project description

aiclient

PyPI version License: MIT

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

(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

aiclient_llm-0.1.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiclient_llm-0.1.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file aiclient_llm-0.1.0.tar.gz.

File metadata

  • Download URL: aiclient_llm-0.1.0.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

Hashes for aiclient_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87b7c8d26db231754257f0c34f0e31cc31ccd0d92e76caaa98ad7c3979e4a6f1
MD5 70463739af86f07060556b9dda04af65
BLAKE2b-256 e34e1965f76cbed42f0fb89d2cacefe30efbefd8a3329d1729510a809f13e9ff

See more details on using hashes here.

File details

Details for the file aiclient_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiclient_llm-0.1.0-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

Hashes for aiclient_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4c69f0f887dca160e4b425c00aa6208fdffb3e63710ec6aeb0b2b9f1ca593c8
MD5 bdc8e27e86fa2497fc9f7bdbd5974dbe
BLAKE2b-256 c18d2e58b0138eb4936ff2d2e484d35639e984470262df06cf129b0d5ab1b327

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page