Official Python client for AgentCache.ai - Reduce LLM costs by 90%
Project description
AgentCache Python Client
Official Python client for AgentCache.ai - The Global Edge Cache for LLMs.
Installation
pip install agentcache
Usage
Standard Completion
import agentcache
# Drop-in replacement for OpenAI call logic
response = agentcache.completion(
model="gpt-4",
messages=[{"role": "user", "content": "Hello world"}],
provider="openai" # optional, defaults to openai
)
if response and response.get('hit'):
print("Cache HIT:", response['response'])
else:
print("Cache MISS - Call your LLM here")
Streaming
AgentCache supports streaming responses, making it compatible with chat UIs that expect Server-Sent Events (SSE).
stream = agentcache.completion(
model="gpt-4",
messages=[{"role": "user", "content": "Write a poem"}],
stream=True
)
if stream:
print("Cache HIT (Streaming):")
for chunk in stream:
content = chunk['choices'][0]['delta'].get('content', '')
print(content, end="", flush=True)
Reasoning Cache (NEW in v0.3.0)
Cache reasoning traces for o1, Kimi, and DeepSeek models:
response = agentcache.completion(
model="o1-preview",
messages=[{"role": "user", "content": "Analyze this contract..."}],
strategy="reasoning_cache"
)
if response and response.get('cached'):
print("Reasoning trace retrieved from cache")
Multimodal Cache (NEW in v0.3.0)
Cache 3D meshes, images, and audio for generative models:
response = agentcache.completion(
model="sam-3d-body",
messages=[{
"role": "user",
"content": "Generate 3D model",
"file_path": "input.jpg"
}],
strategy="multimodal"
)
if response and response.get('cached'):
asset_data = response['asset']
print(f"Retrieved cached 3D asset: {len(asset_data['vertices'])} vertices")
Environment Variables
Set AGENTCACHE_API_KEY in your environment, or pass api_key to the constructor.
from agentcache import AgentCache
client = AgentCache(api_key="ac_live_...")
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 agentcache-0.3.0.tar.gz.
File metadata
- Download URL: agentcache-0.3.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62484c2100a9dcfb6bfbb62cc946bc289bb19d69ab1dbe6426009c0d1b7b20ab
|
|
| MD5 |
58f0e66da0eceedc8e657c351ce16878
|
|
| BLAKE2b-256 |
422c3cf44e77aba1c958c674bff0232d26f6808302b4e28d7753a7ea8a2a5e2c
|
File details
Details for the file agentcache-0.3.0-py3-none-any.whl.
File metadata
- Download URL: agentcache-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3549c67d79888b86d394e717abe1984f9f658e169bdf9b97e3f0d9c5334493e7
|
|
| MD5 |
20a744c92482dcdecf392c2001cf93d7
|
|
| BLAKE2b-256 |
a1ab7a6be8fea77490b6b42b2c77110f470403815c127eac048f51de35c7f3c5
|