Metadata-Version: 2.4
Name: cortyxia
Version: 0.1.9
Summary: The Memory Layer for Enterprise AI — persistent memory and 40% token cost reduction for any LLM stack
License: MIT
Project-URL: Homepage, https://www.cortyxia.com
Project-URL: Documentation, https://docs.cortyxia.com
Project-URL: Repository, https://github.com/simar5244/CortyxiaAPI.git
Project-URL: Issues, https://github.com/simar5244/CortyxiaAPI/issues
Keywords: cortyxia,llm,memory,ai,enterprise,context,rag,agent,chatbot,proxy,memory-layer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.25.0

# Cortyxia Python SDK

> The Memory Layer for Enterprise AI — persistent memory and 40% token cost reduction for any LLM stack.

## Installation

```bash
pip install cortyxia
```

Requires Python >= 3.9.

## Quickstart

Set your email and initialize the client. On first run, Cortyxia auto-provisions a project, API key, and ISO token. No signup form required.

```python
import os
os.environ["CORTYXIA_EMAIL"] = "you@example.com"

from cortyxia import Cortyxia

client = Cortyxia()  # Auto-provisions on first run

# Chat with automatic memory injection
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "What was I working on yesterday?"}]
)
print(response["choices"][0]["message"]["content"])
```

## Credential Storage

Cortyxia stores credentials in **two locations** for resilience and portability:

| Location | Path | Priority |
|----------|------|----------|
| Project-local | `./.cortyxia/credentials.json` | 1st (highest) |
| Machine-global | `~/.cortyxia/credentials.json` | 2nd |
| Environment | `CORTYXIA_EMAIL` | Triggers provisioning / override |

Both files are created with `0600` permissions. A `./.cortyxia/.gitignore` with `*` is auto-generated to prevent accidental commits.

### Resolution Order

1. If `iso_token` is passed explicitly to `Cortyxia()`, it is used directly.
2. Otherwise, read `CORTYXIA_EMAIL` from the environment.
3. Fall back to `./.cortyxia/credentials.json`, then `~/.cortyxia/credentials.json`.
4. If credentials exist for the resolved email, use them.
5. If not, call `/v1/auth/provision` to create a Supabase auth user, default project, and key.

**Credential changes propagate to both files automatically.**

## Email Switching

Change `CORTYXIA_EMAIL` to switch accounts. Your data is never deleted — each email has its own isolated project world.

```python
import os
os.environ["CORTYXIA_EMAIL"] = "work@company.com"
client = Cortyxia()  # Provisions or resumes work@company.com

os.environ["CORTYXIA_EMAIL"] = "personal@gmail.com"
client2 = Cortyxia()  # Provisions or resumes personal@gmail.com
```

If Cortyxia detects another email on the same machine, it stores a **soft link** and prints a discovery message so you know where your other projects live.

## API Reference

### Chat

```python
# Non-streaming
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Hello"}],
    model="gpt-4o",          # optional
    temperature=0.7,         # optional
    max_tokens=256,          # optional
)

# Streaming
for line in client.chat.completions.stream(
    messages=[{"role": "user", "content": "Hello"}]
):
    print(line)
```

### Memory

```python
# Add a memory node
node = client.memory.add(
    content="User prefers Rust over Go",
    tags=["preference", "language"]
)

# Query memory directly
results = client.memory.query("What language does the user prefer?", limit=5)
```

### Projects

```python
# List all projects
projects = client.projects.list()

# Create a new project
project = client.projects.create("Agentic Coding", shared_memory_enabled=True)

# Get / Delete
project = client.projects.get(project["id"])
client.projects.delete(project["id"])
```

### Keys

```python
# Create a standard key
key = client.keys.create(
    project_id=client.project_id,
    label="Production Key",
    provider="OpenAI",
    model="gpt-4o",
)

# Create a developer-mode key (isolated context window for agentic coding)
key = client.keys.create(
    project_id=client.project_id,
    label="Claude Code Agent",
    provider="Anthropic",
    model="claude-sonnet-4-20250514",
    dev_mode=True,
    dev_namespace="isolated",
    recent_window_min=2,
    recent_window_max=8,
)

# Update
client.keys.update(
    project_id=client.project_id,
    key_id=key["id"],
    dev_mode=False,
    recent_window_max=16,
)

# List / Delete
keys = client.keys.list(client.project_id)
client.keys.delete(client.project_id, key["id"])
```

### Self-hosted

```python
# Configure a self-hosted Postgres + Turso backend
client.self_hosted.configure(
    postgres_url="postgresql://user:pass@host/db",
    libsql_url="libsql://your-db.turso.io",
    libsql_auth_token="ey...",
)

# Read / Test / Delete
config = client.self_hosted.get()
result = client.self_hosted.test(postgres_url="...")
client.self_hosted.delete()
```

## Web Dashboard Graduation

SDK-provisioned accounts are fully compatible with the web dashboard. When you sign up on the web with the same email:

1. The dashboard detects your SDK-provisioned account via `/api/auth/check-sdk-user`.
2. You set a password via `/api/auth/complete-sdk-signup`.
3. You sign in normally. Your projects, keys, and memory are already there.

## Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `CORTYXIA_EMAIL` | Yes (first run) | Email for provisioning and account resolution |
| `CORTYXIA_URL` | No | Base URL of the project service (default: `https://api.cortyxia.com`) |

## Error Handling

```python
from cortyxia import Cortyxia, CortyxiaError

try:
    client = Cortyxia()
except CortyxiaError as e:
    print(f"Setup failed: {e}")
```

## License

MIT
