Skip to main content

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_...")

Release files for agentcache 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentcache 0.3.0
File Size Uploaded
agentcache-0.3.0.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentcache 0.3.0
File Interpreter ABI Platform
agentcache-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / agentcache-0.3.0.tar.gz

Download URL agentcache-0.3.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
62484c2100a9dcfb6bfbb62cc946bc289bb19d69ab1dbe6426009c0d1b7b20ab
BLAKE2b-256 checksum
How to use checksums
422c3cf44e77aba1c958c674bff0232d26f6808302b4e28d7753a7ea8a2a5e2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / agentcache-0.3.0-py3-none-any.whl

Download URL agentcache-0.3.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3549c67d79888b86d394e717abe1984f9f658e169bdf9b97e3f0d9c5334493e7
BLAKE2b-256 checksum
How to use checksums
a1ab7a6be8fea77490b6b42b2c77110f470403815c127eac048f51de35c7f3c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page