apps/docs/model-enhancement/context-extender.mdx
import GettingAPIKey from '/snippets/getting-api-key.mdx';
supermemory Infinite Chat is a powerful solution that gives your chat applications unlimited contextual memory. It works as a transparent proxy in front of your existing LLM provider, intelligently managing long conversations without requiring any changes to your application logic.
<Tabs> <Tab title="Key Features"> <CardGroup cols={2}> <Card title="Unlimited Context" icon="infinity" color="#4F46E5"> No more token limits - conversations can extend indefinitely </Card> <Card title="Zero Latency" icon="bolt" color="#10B981"> Transparent proxying with negligible overhead </Card> <Card title="Cost Efficient" icon="coins" color="#F59E0B"> Save up to 70% on token costs for long conversations </Card> <Card title="Provider Agnostic" icon="plug" color="#6366F1"> Works with any OpenAI-compatible endpoint </Card> </CardGroup> </Tab> </Tabs>To use the Infinite Chat endpoint, you need to:
import OpenAI from "openai";
/**
* Initialize the OpenAI client with supermemory proxy
* @param {string} OPENAI_API_KEY - Your OpenAI API key
* @param {string} SUPERMEMORY_API_KEY - Your supermemory API key
* @returns {OpenAI} - Configured OpenAI client
*/
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://api.supermemory.ai/v3/https://api.openai.com/v1",
headers: {
"x-supermemory-api-key": process.env.SUPERMEMORY_API_KEY,
"x-sm-user-id": "Your_users_id"
},
});
import openai
import os
# Configure the OpenAI client with supermemory proxy
openai.api_base = "https://api.supermemory.ai/v3/https://api.openai.com/v1"
openai.api_key = os.environ.get("OPENAI_API_KEY") # Your regular OpenAI key
openai.default_headers = {
"x-supermemory--api-key": os.environ.get("SUPERMEMORY_API_KEY"), # Your supermemory key
}
# Create a chat completion with unlimited context
response = openai.ChatCompletion.create(
model="gpt-5-nano",
messages=[{"role": "user", "content": "Your message here"}]
)
Each response includes diagnostic headers that provide information about the processing:
| Header | Description |
|---|---|
x-supermemory-conversation-id | Unique identifier for the conversation thread |
x-supermemory-context-modified | Indicates whether supermemory modified the context ("true" or "false") |
x-supermemory-tokens-processed | Number of tokens processed in this request |
x-supermemory-chunks-created | Number of new chunks created from this conversation |
x-supermemory-chunks-deleted | Number of chunks removed (if any) |
x-supermemory-docs-deleted | Number of documents removed (if any) |
If an error occurs, an additional header x-supermemory-error will be included with details about what went wrong. Your request will still be processed by the underlying LLM provider even if supermemory encounters an error.
supermemory works with any OpenAI-compatible API, including:
<CardGroup cols={3}> <Card title="OpenAI" icon="openai"> GPT-3.5, GPT-4, GPT-4o </Card> <Card title="Anthropic" icon="user-astronaut"> Claude 3 models </Card> <Card title="Other Providers" icon="plug"> Any provider with an OpenAI-compatible endpoint </Card> </CardGroup>