Skip to main content

AI Cortex: An LLM API toolkit for any language model through Ollama servers. Access Gemma, Mistral, Deepseek, Qwen, Llama, and more - completely free, zero-signup, zero API keys. Unified chat API, real-time streaming, multi-server orchestration, and OpenAI-compatible endpoints.

Project description

🧠 AI Cortex

The unified Python toolkit for accessing any LLM through Ollama.
Zero API keys. Zero signup. Completely free.

PyPI Version Downloads Python Versions License


AI Cortex gives you a single, clean Python interface to hundreds of language models — Llama, Mistral, Gemma, DeepSeek, Qwen, and more — all served through Ollama. No accounts. No credit cards. No rate limits.

from aicortex import chat

response = chat("Explain neural networks like I'm five.")
print(response)

✨ Why AI Cortex?

Feature What it means for you
🆓 100% Free No API keys, no billing, no subscriptions — ever
🤖 Any Model Llama, Mistral, Gemma, DeepSeek, Qwen, and more
🌐 Any Server Local Ollama, remote servers, or community endpoints
Streaming Real-time token streaming for responsive UIs
🔌 OpenAI-Compatible Drop-in replacement for OpenAI client apps
🛡️ Type-Safe Full type hints, stubs, and IDE autocomplete
🔧 Production Ready Automatic failover, multi-server routing, error handling
📦 Lightweight One dependency (ollama) for the core package

🚀 Installation

# Core package
pip install aicortex-core

# With OpenAI-compatible server support
pip install aicortex-core[server]

💬 Chat

from aicortex import chat

# Simple response
response = chat("What is the speed of light?")
print(response)

# Custom model and parameters
response = chat(
    "Write a Python function to reverse a string.",
    model="llama3.2:3b",
    temperature=0.2,
    max_tokens=200,
)
print(response)

⚡ Streaming

from aicortex import chat

stream = chat("Write a haiku about AI.", stream=True)

for event in stream:
    if event.type == "token":
        print(event.content, end="", flush=True)

🤖 Model Discovery

from aicortex import families, models, get_model_info

# Available families
print(families())   # ['llama', 'mistral', 'gemma', 'deepseek', 'qwen']

# Models in a family
print(models("mistral"))

# Full metadata for a model
info = get_model_info("llama3.2:3b")
print(info['parameter_size'], info['quantization_level'])

🌐 Server Discovery

from aicortex import list_model_servers, get_server_info, get_llm_params

# All Ollama servers hosting a model
servers = list_model_servers("llama3.2:3b")
for s in servers:
    print(f"{s['url']}{s['location']['city']}, {s['location']['country']}")

# Ready-to-use params for LangChain's OllamaLLM
params = get_llm_params("mistral:7b")
# → {'model': 'mistral:7b', 'base_url': 'http://...'}

🖥️ OpenAI-Compatible Server

Run a local proxy that speaks OpenAI's API — drop-in compatible with any OpenAI client:

from aicortex.tools import run_server

run_server(host="127.0.0.1", port=8000, default_model="llama3.2:3b")
# Use with curl
curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "llama3.2:3b", "messages": [{"role": "user", "content": "Hello!"}]}'

# Use with the openai Python SDK — just change the base_url
from openai import OpenAI
client = OpenAI(api_key="none", base_url="http://localhost:8000/v1")
response = client.chat.completions.create(
    model="llama3.2:3b",
    messages=[{"role": "user", "content": "Hello!"}]
)

🔧 Model Management Tools

Keep the bundled model database fresh with the four-step pipeline:

from pathlib import Path
from aicortex.tools import (
    find_valid_endpoints,     # Step 1: ping all known IPs
    fetch_models,             # Step 2: pull model lists
    resolve_models,           # Step 3: merge with IP metadata
    apply_valid_models,       # Step 4: write into family JSONs
)

json_dir   = Path("aicortex/models")
valid_urls = find_valid_endpoints(json_dir)                              # Step 1
fetch_models(Path("valid.txt"), Path("fetched.json"))                   # Step 2
resolve_models(Path("fetched.json"), json_dir, Path("resolved.json"))   # Step 3
apply_valid_models(Path("resolved.json"), json_dir, backup=True)        # Step 4

📚 Full Documentation

aicortex.readthedocs.io


🤝 Contributing

Contributions are welcome! See CONTRIBUTING.md and the Development Guide.

📄 License

GNU Lesser General Public License v3.0 — free for open-source and commercial use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aicortex_core-1.0.3.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aicortex_core-1.0.3-py3-none-any.whl (63.7 kB view details)

Uploaded Python 3

File details

Details for the file aicortex_core-1.0.3.tar.gz.

File metadata

  • Download URL: aicortex_core-1.0.3.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for aicortex_core-1.0.3.tar.gz
Algorithm Hash digest
SHA256 712cf68381bdaba3aa38f0ce98cbedb7dfbe7f8705da72bef0b2e46b391a72df
MD5 06de74438947c414ac5e6ab3a7a4461e
BLAKE2b-256 c8157a9a2f509bccf19ada45311427ade6791c26c2125d0d6427684be5012ae8

See more details on using hashes here.

File details

Details for the file aicortex_core-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: aicortex_core-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 63.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for aicortex_core-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 68f17f524ddbe49bc8cbfe6e8556fe611df90436d47f740f92ddd9bbb728e0e2
MD5 87d18701741c77595fb15629838b3078
BLAKE2b-256 191c311ba82dd3e9239db218e1d1791f0966118b53a42291bf1f497404001fe3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page