Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions LLM.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ config = MemoryConfig(

### Supported Providers

#### LLM Providers (20 supported)
#### LLM Providers (21 supported)
- **aimlapi** - aimlapi.com gateway (350+ models)
- **openai** - OpenAI GPT models (default)
- **anthropic** - Claude models
- **gemini** - Google Gemini
Expand All @@ -293,7 +294,8 @@ config = MemoryConfig(
- **openai_structured** - OpenAI with structured output
- **azure_openai_structured** - Azure OpenAI with structured output

#### Embedding Providers (10 supported)
#### Embedding Providers (11 supported)
- **aimlapi** - aimlapi.com embeddings
- **openai** - OpenAI embeddings (default)
- **ollama** - Ollama embeddings
- **huggingface** - HuggingFace models
Expand Down Expand Up @@ -419,6 +421,7 @@ config = MemoryConfig(
```

#### LLM Providers
- **aimlapi.com** - OpenAI-compatible gateway to 350+ models
- **OpenAI** - GPT-4, GPT-3.5-turbo, and structured outputs
- **Anthropic** - Claude models with advanced reasoning
- **Google AI** - Gemini models for multimodal applications
Expand Down
1 change: 1 addition & 0 deletions docs/components/embedders/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Here's a comprehensive list of all parameters that can be used across different
| `memory_update_embedding_type` | The type of embedding to use for the update memory action | VertexAI |
| `memory_search_embedding_type` | The type of embedding to use for the search memory action | VertexAI |
| `lmstudio_base_url` | Base URL for LM Studio API | LM Studio |
| `aimlapi_base_url` | Base URL for the aimlapi.com API | aimlapi.com |
</Tab>
<Tab title="TypeScript">
| Parameter | Description | Provider |
Expand Down
91 changes: 91 additions & 0 deletions docs/components/embedders/models/aimlapi.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: aimlapi.com
description: "Configure aimlapi.com as an embedding provider in Mem0, with OpenAI, Voyage, Google and Alibaba embedding models behind one OpenAI-compatible endpoint."
---

[aimlapi.com](https://aimlapi.com) serves embedding models from several vendors over the OpenAI-compatible `/v1/embeddings` route. Set the `AIMLAPI_API_KEY` environment variable with a key from the [aimlapi.com dashboard](https://aimlapi.com/app/keys).

Model ids are namespaced, for example `openai/text-embedding-3-small` (1536 dims) or `openai/text-embedding-3-large` (3072 dims). The live catalog is at `https://api.aimlapi.com/v1/models`.

### Usage

<Note> The `embedding_model_dims` parameter for `vector_store` must match the model you pick — `1536` for `openai/text-embedding-3-small`, `3072` for `openai/text-embedding-3-large`. </Note>

<CodeGroup>
```python Python
import os
from mem0 import Memory

os.environ["AIMLAPI_API_KEY"] = "your-api-key"

config = {
"llm": {
"provider": "aimlapi",
"config": {
"model": "openai/gpt-5-mini"
}
},
"embedder": {
"provider": "aimlapi",
"config": {
"model": "openai/text-embedding-3-small"
}
}
}

m = Memory.from_config(config)
messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
m.add(messages, user_id="john")
```

```typescript TypeScript
import { Memory } from 'mem0ai/oss';

const config = {
embedder: {
provider: 'aimlapi',
config: {
apiKey: process.env.AIMLAPI_API_KEY || '',
model: 'openai/text-embedding-3-small',
embeddingDims: 1536,
},
},
};

const memory = new Memory(config);
await memory.add("I'm visiting Paris", { userId: "john" });
```

</CodeGroup>

<Note>
The endpoint accepts a string or a list of strings as `input` and rejects the pre-tokenised integer-array form with a 400. If you route aimlapi.com through the `langchain` embedder instead of this one, configure the LangChain embedding class to send text rather than token ids.
</Note>

### Config

Here are the parameters available for configuring the aimlapi.com embedder:

<Tabs>
<Tab title="Python">
| Parameter | Description | Default Value |
| --- | --- | --- |
| `model` | The name of the embedding model to use | `openai/text-embedding-3-small` |
| `embedding_dims` | Dimensions of the embedding model; sent as `dimensions` only when set | `1536` |
| `api_key` | The aimlapi.com API key | `AIMLAPI_API_KEY` |
| `aimlapi_base_url` | Base URL for the API | `https://api.aimlapi.com/v1` |
</Tab>
<Tab title="TypeScript">
| Parameter | Description | Default Value |
| --- | --- | --- |
| `model` | The name of the embedding model to use | `openai/text-embedding-3-small` |
| `embeddingDims` | Dimensions of the embedding model for vector store configuration | `1536` |
| `apiKey` | The aimlapi.com API key | `AIMLAPI_API_KEY` |
| `baseURL` | Base URL for the API | `https://api.aimlapi.com/v1` |
</Tab>
</Tabs>
3 changes: 2 additions & 1 deletion docs/components/embedders/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Mem0 offers support for various embedding models, allowing users to choose the o
See the list of supported embedders below.

<Note>
All embedders listed below are supported in the Python implementation. The TypeScript implementation supports: **OpenAI**, **Azure OpenAI**, **AWS Bedrock**, **FastEmbed**, **Google AI**, **Hugging Face**, **Langchain**, **LM Studio**, **Ollama**, **Together**, and **Vertex AI**.
All embedders listed below are supported in the Python implementation. The TypeScript implementation supports: **OpenAI**, **Azure OpenAI**, **AWS Bedrock**, **FastEmbed**, **Google AI**, **Hugging Face**, **Langchain**, **LM Studio**, **Ollama**, **Together**, **Vertex AI**, and **aimlapi.com**.
</Note>

<CardGroup cols={4}>
<Card title="aimlapi.com" icon="/images/provider-icons/aimlapi.svg" href="/components/embedders/models/aimlapi"></Card>
<Card title="OpenAI" icon="/images/provider-icons/openai.svg" href="/components/embedders/models/openai"></Card>
<Card title="Azure OpenAI" icon="/images/provider-icons/azure-color.svg" href="/components/embedders/models/azure_openai"></Card>
<Card title="Ollama" icon="/images/provider-icons/ollama.svg" href="/components/embedders/models/ollama"></Card>
Expand Down
1 change: 1 addition & 0 deletions docs/components/llms/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Here's a comprehensive list of all parameters that can be used across different
| `deepseek_base_url` | Base URL for DeepSeek API | DeepSeek |
| `xai_base_url` | Base URL for XAI API | XAI |
| `sarvam_base_url` | Base URL for Sarvam API | Sarvam |
| `aimlapi_base_url` | Base URL for the aimlapi.com API | aimlapi.com |
| `reasoning_effort` | Reasoning level (low, medium, high) | All |
| `frequency_penalty` | Penalize frequent tokens (-2.0 to 2.0) | Sarvam |
| `presence_penalty` | Penalize existing tokens (-2.0 to 2.0) | Sarvam |
Expand Down
103 changes: 103 additions & 0 deletions docs/components/llms/models/aimlapi.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: aimlapi.com
description: "Configure aimlapi.com as an LLM provider in Mem0, an OpenAI-compatible gateway to 350+ chat models from OpenAI, Anthropic, Google, DeepSeek and others."
---

[aimlapi.com](https://aimlapi.com) exposes 350+ chat models behind a single OpenAI-compatible endpoint, so one key and one base URL reach OpenAI, Anthropic, Google, DeepSeek, Alibaba and others. Mem0 can use it for the LLM, the [embedder](/components/embedders/models/aimlapi), or both.

Set the `AIMLAPI_API_KEY` environment variable with a key from the [aimlapi.com dashboard](https://aimlapi.com/app/keys).

Model ids are namespaced, for example `openai/gpt-5-mini`, `anthropic/claude-sonnet-4.6` or `google/gemini-2.5-flash`. The live catalog is at `https://api.aimlapi.com/v1/models`.

## Usage

<CodeGroup>
```python Python
import os
from mem0 import Memory

os.environ["AIMLAPI_API_KEY"] = "your-api-key"

config = {
"llm": {
"provider": "aimlapi",
"config": {
"model": "openai/gpt-5-mini",
"temperature": 0.1,
}
},
"embedder": {
"provider": "aimlapi",
"config": {
"model": "openai/text-embedding-3-small"
}
}
}

m = Memory.from_config(config)
messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
m.add(messages, user_id="alex")
```

```typescript TypeScript
import { Memory } from 'mem0ai/oss';

const config = {
llm: {
provider: 'aimlapi',
config: {
apiKey: process.env.AIMLAPI_API_KEY || '',
model: 'openai/gpt-5-mini',
temperature: 0.1,
},
},
embedder: {
provider: 'aimlapi',
config: {
apiKey: process.env.AIMLAPI_API_KEY || '',
model: 'openai/text-embedding-3-small',
embeddingDims: 1536,
},
},
};

const memory = new Memory(config);
const messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about thriller movies? They can be quite engaging."},
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
];
await memory.add(messages, { userId: 'alex' });
```

</CodeGroup>

## Pointing at a different endpoint

`aimlapi_base_url` (Python) or `baseURL` (TypeScript) overrides the endpoint, and `AIMLAPI_API_BASE` does the same from the environment. Mem0's attribution headers are only attached when the resolved host is `api.aimlapi.com`, so they are not forwarded to a gateway of your own.

```python
config = {
"llm": {
"provider": "aimlapi",
"config": {
"model": "anthropic/claude-sonnet-4.6",
"aimlapi_base_url": "https://my-gateway.internal/v1",
}
}
}
```

<Note>
`max_tokens` does not bound reasoning tokens on every model behind the gateway, and `completion_tokens` in the usage block excludes reasoning tokens on some of them. Treat it as a length hint, not a cost ceiling.
</Note>

## Config

All available parameters for the `aimlapi` config are present in [Master List of All Params in Config](../config).
3 changes: 2 additions & 1 deletion docs/components/llms/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ For a comprehensive list of available parameters for llm configuration, please r
See the list of supported LLMs below.

<Note>
All LLMs are supported in Python. The following LLMs are also supported in TypeScript: **OpenAI**, **Anthropic**, **AWS Bedrock**, **Groq**, **Azure OpenAI**, **DeepSeek**, **Google AI**, **Langchain**, **LM Studio**, **Mistral AI**, and **Ollama**.
All LLMs are supported in Python. The following LLMs are also supported in TypeScript: **OpenAI**, **Anthropic**, **AWS Bedrock**, **Groq**, **Azure OpenAI**, **DeepSeek**, **Google AI**, **Langchain**, **LM Studio**, **Mistral AI**, **Ollama**, and **aimlapi.com**.
</Note>

<CardGroup cols={4}>
<Card title="aimlapi.com" icon="/images/provider-icons/aimlapi.svg" href="/components/llms/models/aimlapi" />
<Card title="OpenAI" icon="/images/provider-icons/openai.svg" href="/components/llms/models/openai" />
<Card title="Ollama" icon="/images/provider-icons/ollama.svg" href="/components/llms/models/ollama" />
<Card title="Azure OpenAI" icon="/images/provider-icons/azure-color.svg" href="/components/llms/models/azure_openai" />
Expand Down
2 changes: 2 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"group": "Supported LLMs",
"icon": "list",
"pages": [
"components/llms/models/aimlapi",
"components/llms/models/openai",
"components/llms/models/anthropic",
"components/llms/models/azure_openai",
Expand Down Expand Up @@ -243,6 +244,7 @@
"group": "Supported Embedding Models",
"icon": "list",
"pages": [
"components/embedders/models/aimlapi",
"components/embedders/models/openai",
"components/embedders/models/azure_openai",
"components/embedders/models/ollama",
Expand Down
10 changes: 10 additions & 0 deletions docs/images/provider-icons/aimlapi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ Everything below is OSS-only provider configuration. Skip this entire section wh
### LLM Providers [OSS]
- [LLM Overview](https://docs.mem0.ai/components/llms/overview) [OSS]: Use when the user is choosing an LLM for memory extraction.
- [LLM Configuration](https://docs.mem0.ai/components/llms/config) [OSS]: Use for the `llm` config schema.
- [aimlapi.com](https://docs.mem0.ai/components/llms/models/aimlapi) [OSS]: Use when the LLM is reached through the aimlapi.com gateway.
- [OpenAI](https://docs.mem0.ai/components/llms/models/openai) [OSS]: Use when the extraction LLM is OpenAI.
- [Anthropic](https://docs.mem0.ai/components/llms/models/anthropic) [OSS]: Use when the extraction LLM is Claude.
- [Azure OpenAI](https://docs.mem0.ai/components/llms/models/azure_openai) [OSS]: Use when the user is on Azure-hosted OpenAI.
Expand All @@ -471,6 +472,7 @@ Everything below is OSS-only provider configuration. Skip this entire section wh
### Embedding Providers [OSS]
- [Embeddings Overview](https://docs.mem0.ai/components/embedders/overview) [OSS]: Use when choosing an embedding model.
- [Embeddings Configuration](https://docs.mem0.ai/components/embedders/config) [OSS]: Use for the `embedder` config schema.
- [aimlapi.com Embeddings](https://docs.mem0.ai/components/embedders/models/aimlapi) [OSS]: Use when embeddings are reached through the aimlapi.com gateway.
- [OpenAI Embeddings](https://docs.mem0.ai/components/embedders/models/openai) [OSS]: Use when embeddings come from OpenAI.
- [Azure OpenAI Embeddings](https://docs.mem0.ai/components/embedders/models/azure_openai) [OSS]: Use for Azure-hosted OpenAI embeddings.
- [AWS Bedrock Embeddings](https://docs.mem0.ai/components/embedders/models/aws_bedrock) [OSS]: Use for Bedrock-hosted embeddings.
Expand Down
34 changes: 34 additions & 0 deletions mem0-ts/src/oss/src/embeddings/aimlapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { OpenAIEmbedder } from "./openai";
import { EmbeddingConfig } from "../types";
import { buildAimlapiHeaders, resolveAimlapiBaseURL } from "../utils/aimlapi";

const DEFAULT_MODEL = "openai/text-embedding-3-small";

/**
* aimlapi.com embedder — the OpenAI-compatible `/v1/embeddings` route.
*
* Mirrors `mem0/embeddings/aimlapi.py` in the Python SDK. Model ids are the
* gateway's namespaced ids, e.g. `openai/text-embedding-3-small` (1536 dims) or
* `openai/text-embedding-3-large` (3072 dims).
*/
export class AimlapiEmbedder extends OpenAIEmbedder {
constructor(config: EmbeddingConfig) {
const apiKey = config.apiKey || process.env.AIMLAPI_API_KEY;
if (!apiKey) {
throw new Error(
"aimlapi.com API key is required. Set AIMLAPI_API_KEY or pass apiKey in the config.",
);
}
const baseURL = resolveAimlapiBaseURL(
config.baseURL || config.url,
process.env.AIMLAPI_API_BASE,
);
super({
...config,
apiKey,
baseURL,
model: config.model || DEFAULT_MODEL,
defaultHeaders: buildAimlapiHeaders(baseURL, config.defaultHeaders),
});
}
}
1 change: 1 addition & 0 deletions mem0-ts/src/oss/src/embeddings/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class OpenAIEmbedder implements Embedder {
this.openai = new OpenAI({
apiKey: config.apiKey,
baseURL: config.baseURL || config.url,
...(config.defaultHeaders && { defaultHeaders: config.defaultHeaders }),
});
this.model = config.model || "text-embedding-3-small";
this.embeddingDims = config.embeddingDims;
Expand Down
Loading