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
3 changes: 2 additions & 1 deletion .claude/skills/cognee-integrations/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: cognee-integrations
description: Use when the user wants to connect cognee to external services — switching LLM or embedding providers (OpenAI, Azure, Gemini, Anthropic, Ollama, OpenRouter), changing databases (Postgres, PGVector, Neo4j, Neptune, Turso), S3 storage, or the MCP server for IDE integration.
description: Use when the user wants to connect cognee to external services — switching LLM or embedding providers (OpenAI, Azure, Gemini, Anthropic, Ollama, OpenRouter, aimlapi.com), changing databases (Postgres, PGVector, Neo4j, Neptune, Turso), S3 storage, or the MCP server for IDE integration.
---

# Set up cognee integrations
Expand All @@ -16,6 +16,7 @@ Default is OpenAI (`LLM_API_KEY` is all you need). To switch, set
`LLM_PROVIDER`, `LLM_MODEL`, `LLM_API_KEY`, and (where relevant)
`LLM_ENDPOINT` / `LLM_API_VERSION`:

- **aimlapi.com**: `LLM_PROVIDER=custom`, `LLM_MODEL=aiml/<catalogue-id>`, `LLM_ENDPOINT=https://api.aimlapi.com/v1`. Embeddings drop the `aiml/` prefix (litellm has no aiml embedding route) and rely on `EMBEDDING_ENDPOINT` instead.
- **Azure OpenAI**: `LLM_PROVIDER=azure`, `LLM_MODEL=azure/gpt-4o-mini`, endpoint + api version required.
- **Gemini** (no extra needed): `LLM_PROVIDER=gemini`, `LLM_MODEL=gemini/gemini-2.0-flash-exp`.
- **Anthropic** (`cognee[anthropic]`): `LLM_PROVIDER=anthropic`, model e.g. `claude-3-5-sonnet-20241022`.
Expand Down
22 changes: 22 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,28 @@ WEB_SCRAPER_MAX_DELAY=10.0
# Uncomment + fill values to switch providers.
###############################################################################

########## aimlapi.com ########################################################
# OpenAI-compatible gateway; litellm routes it under the "aiml/" prefix, so no
# extra install is needed. LLM_PROVIDER must be "custom" -- an "aiml/" prefix on
# its own raises ProviderNotDeducibleError, exactly like "openrouter/".
# Catalogue: https://api.aimlapi.com/v1/models?include=all
# Note: litellm's own env var for this provider is AIML_API_KEY, but cognee
# never reads it -- cognee passes api_key to litellm explicitly, so the key
# must be in LLM_API_KEY (setting only AIML_API_KEY raises LLMAPIKeyNotSetError).
#LLM_API_KEY="<<go-get-one-yourself"
#LLM_PROVIDER="custom"
#LLM_MODEL="aiml/openai/gpt-4o-mini"
#LLM_ENDPOINT="https://api.aimlapi.com/v1"
# Embeddings are configured independently. litellm has no "aiml" embedding
# route, so the embedding model carries NO "aiml/" prefix -- EMBEDDING_ENDPOINT
# is what points the OpenAI-compatible route at aimlapi.com.
#EMBEDDING_PROVIDER="custom"
#EMBEDDING_API_KEY="<<go-get-one-yourself"
#EMBEDDING_MODEL="openai/text-embedding-3-large"
#EMBEDDING_ENDPOINT="https://api.aimlapi.com/v1"
#EMBEDDING_DIMENSIONS=3072
#EMBEDDING_MAX_COMPLETION_TOKENS=8191

########## Azure OpenAI (API key auth) ########################################
#LLM_PROVIDER="azure"
#LLM_MODEL="azure/gpt-5-mini"
Expand Down
16 changes: 15 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,21 @@ Four flags trade memory features for speed. Know what each turns off before flip

### LLM Provider Configuration

Supported providers: OpenAI (default), Azure OpenAI, Google Gemini, Anthropic, AWS Bedrock, Ollama, LM Studio, Custom (OpenAI-compatible APIs)
Supported providers: aimlapi.com, OpenAI (default), Azure OpenAI, Google Gemini, Anthropic, AWS Bedrock, Ollama, LM Studio, Custom (OpenAI-compatible APIs)

#### aimlapi.com
```bash
LLM_PROVIDER="custom"
LLM_MODEL="aiml/openai/gpt-4o-mini"
LLM_ENDPOINT="https://api.aimlapi.com/v1"
LLM_API_KEY="your_aimlapi_key" # not AIML_API_KEY: cognee passes the key to litellm itself
# Embeddings are separate; no "aiml/" prefix (litellm has no aiml embedding route)
EMBEDDING_PROVIDER="custom"
EMBEDDING_MODEL="openai/text-embedding-3-large"
EMBEDDING_ENDPOINT="https://api.aimlapi.com/v1"
EMBEDDING_API_KEY="your_aimlapi_key"
EMBEDDING_DIMENSIONS=3072
```

#### OpenAI (Recommended - Minimal Setup)
```bash
Expand Down
27 changes: 27 additions & 0 deletions catalog/entries/integrations/aimlapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
id: aimlapi
title: aimlapi.com as the cognee LLM provider
kind: integration
stack: llm-provider
tags:
- aimlapi
- llm-provider
- openai-compatible
- litellm
- embeddings
summary: Run cognee's LLM and embedding calls on aimlapi.com, an OpenAI-compatible gateway, using litellm's built-in "aiml/" route and no extra install.
what_youll_build: A cognee pipeline that builds a knowledge graph and answers a recall query with both extraction and embeddings served by aimlapi.com.
quickstart: |
git clone https://github.com/topoteretes/cognee.git
cd cognee
uv pip install cognee
export LLM_API_KEY=your_aimlapi_key
python examples/guides/aimlapi_example.py
expected_output: |
A "Knowledge graph built successfully" line followed by a recall answer
synthesized from the sample text. The LLM call is routed through litellm's
aiml/ prefix and the embedding call through the aimlapi.com endpoint, so no
OpenAI key is involved.
difficulty: easy
repo: topoteretes/cognee
path: examples/guides/aimlapi_example.py
example_path: examples/guides/aimlapi_example.py
97 changes: 97 additions & 0 deletions examples/guides/aimlapi_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Example: Running Cognee on aimlapi.com.

aimlapi.com is an OpenAI-compatible gateway serving hundreds of chat models
behind one key. Cognee reaches it through litellm, so no adapter is needed:
set ``LLM_PROVIDER="custom"`` and prefix the catalogue id with ``aiml/``.

- LLM Provider: aimlapi.com (``aiml/openai/gpt-4o-mini``)
- Embeddings: aimlapi.com (``openai/text-embedding-3-large``)
- Local embedded database stack (Kuzu, LanceDB, SQLite)

Requires an aimlapi.com key exported as ``LLM_API_KEY``. Get one at
https://aimlapi.com/app/keys — the model catalogue is public at
https://api.aimlapi.com/v1/models?include=all
"""

import os
import asyncio
import tempfile
from pathlib import Path

# Setup temp directory to keep this example self-contained
_DATA_DIR = tempfile.mkdtemp(prefix="cognee_aimlapi_example_")
os.environ["ENABLE_BACKEND_ACCESS_CONTROL"] = "false"
os.environ["CACHING"] = "false"

# Configure aimlapi.com environment settings.
# LLM_PROVIDER must be "custom": cognee's provider enum is deliberately small and
# an "aiml/" prefix alone raises ProviderNotDeducibleError, exactly like "openrouter/".
os.environ["LLM_PROVIDER"] = "custom"
os.environ["LLM_MODEL"] = "aiml/openai/gpt-4o-mini"
os.environ["LLM_ENDPOINT"] = "https://api.aimlapi.com/v1"
os.environ.setdefault("LLM_API_KEY", "") # export your key before running

# Embeddings are configured independently of the LLM. litellm has no "aiml"
# embedding route, so the embedding model carries NO "aiml/" prefix -- it is the
# endpoint that points the OpenAI-compatible route at aimlapi.com.
os.environ["EMBEDDING_PROVIDER"] = "custom"
os.environ["EMBEDDING_MODEL"] = "openai/text-embedding-3-large"
os.environ["EMBEDDING_ENDPOINT"] = "https://api.aimlapi.com/v1"
os.environ["EMBEDDING_API_KEY"] = os.environ["LLM_API_KEY"]
os.environ["EMBEDDING_DIMENSIONS"] = "3072"
os.environ["EMBEDDING_MAX_COMPLETION_TOKENS"] = "8191"

import cognee # noqa: E402
from cognee.modules.search.types import SearchType # noqa: E402
from cognee.infrastructure.llm.config import get_llm_config # noqa: E402

# Force local embedded stack configuration
cognee.config.set_graph_database_provider("kuzu")
cognee.config.set_vector_db_provider("lancedb")
cognee.config.data_root_directory(str(Path(_DATA_DIR) / "data"))
cognee.config.system_root_directory(str(Path(_DATA_DIR) / "system"))


SAMPLE_TEXT = """\
Cognee is an open-source library that helps developers turn documents into AI memory.
It builds semantic graphs, indexes entities, and stores vectors to enable structured retrieval.
Cognee supports hosted gateways such as aimlapi.com as well as local execution via Ollama.
"""


def banner(title: str) -> None:
print("\n" + "=" * 78)
print(title)
print("=" * 78)


async def main() -> None:
if not os.environ.get("LLM_API_KEY"):
raise SystemExit("Export LLM_API_KEY with your aimlapi.com key before running.")

# Start from a clean slate in isolated directory
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)

banner("REMEMBER USING AIMLAPI.COM")
llm_config = get_llm_config()
print(f"Using LLM: {llm_config.llm_model}")
print(f"Using Embeddings: {os.environ.get('EMBEDDING_MODEL')}")

await cognee.remember(SAMPLE_TEXT, dataset_name="aimlapi_demo", self_improvement=False)
print("Knowledge graph built successfully.")

banner("RECALL")
query = "What does Cognee help developers do?"
results = await cognee.recall(
query_text=query,
query_type=SearchType.GRAPH_COMPLETION,
datasets=["aimlapi_demo"],
)
print(f"Query: {query}")
print("Recall Results:")
print(results[0].text if results else "<no results>")


if __name__ == "__main__":
asyncio.run(main())