Quick Start Guide

1. Get Your API Key

Create an account at agentcache.ai/signup, finish onboarding, then open your workspace dashboard to generate an API key and copy your default namespace.

2. Install SDK

npm install agentcache-client

3. Initialize Client

import { AgentCache } from 'agentcache-client';

const cache = new AgentCache({
  apiKey: 'ac_live_your_key',
  baseUrl: 'https://agentcache.ai',
  namespace: 'default'
});

Optional: Test The API Directly

curl -X POST https://agentcache.ai/api/cache/set \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "X-Cache-Namespace: default" \
  -d '{
    "provider": "openai",
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"What is 2+2?"}],
    "response": "4"
  }'

4. Cache AI Responses

const cached = await cache.get({
  provider: 'openai',
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'What is 2+2?' }]
});

if (cached.hit) {
  console.log('Cache hit!', cached.value);
} else {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [{ role: 'user', content: 'What is 2+2?' }]
  });

  await cache.set(
    {
      provider: 'openai',
      model: 'gpt-4o-mini',
      messages: [{ role: 'user', content: 'What is 2+2?' }]
    },
    response.choices[0].message.content
  );
}

5. Cache Tool Calls

const toolInput = JSON.stringify({ city: 'San Francisco' });

const weatherCache = await cache.get({
  provider: 'tool',
  model: 'get_weather',
  messages: [{ role: 'user', content: toolInput }]
});

if (!weatherCache.hit) {
  const weather = await fetchWeather('San Francisco');
  await cache.set(
    {
      provider: 'tool',
      model: 'get_weather',
      messages: [{ role: 'user', content: toolInput }]
    },
    weather,
    { ttl: 1800 }
  );
}

6. Monitor Your Savings

const stats = await cache.stats();

console.log(`Cache hit rate: ${stats.metrics.hit_rate}%`);
console.log(`Money saved: ${stats.metrics.cost_saved}`);
console.log(`Requests cached: ${stats.metrics.total_requests}`);

🎉 You're All Set!

You're now caching AI responses and saving money. Check out the full documentation for advanced features.

View Pricing