Metadata-Version: 2.4
Name: tinymagiq-ai-gateway
Version: 0.1.0
Summary: Simple AI Gateway - 100+ LLM providers, one function call
Home-page: https://github.com/yourusername/tinymagiq_ai_gateway
Author: TinyMagiq
Author-email: your@email.com
License: MIT
Classifier: Development Status :: 4 - Beta
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
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: litellm>=1.50.0
Provides-Extra: cache
Requires-Dist: redis>=4.0; extra == "cache"
Provides-Extra: guardrails
Requires-Dist: presidio-analyzer>=2.0; extra == "guardrails"
Provides-Extra: all
Requires-Dist: redis>=4.0; extra == "all"
Requires-Dist: presidio-analyzer>=2.0; extra == "all"
Requires-Dist: langfuse>=2.0; extra == "all"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# TinyMagiq AI Gateway

Simple AI Gateway wrapping LiteLLM - 100+ providers, one function call.

## Install

```bash
pip install tinymagiq-ai-gateway
```

## Quick Start

```python
from tinymagiq_ai_gateway import completion

response = completion(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response["content"])
```

## Switch Providers Instantly

```python
# OpenAI
response = completion("gpt-4", [{"role": "user", "content": "Hi"}])

# Anthropic
response = completion("anthropic/claude-3-opus", [{"role": "user", "content": "Hi"}])

# Azure
response = completion("azure/gpt-4", [{"role": "user", "content": "Hi"}])

# Bedrock
response = completion("bedrock/anthropic.claude-v2", [{"role": "user", "content": "Hi"}])
```

## Features

### Caching (Save Money)

```python
from tinymagiq_ai_gateway import enable_cache, completion

enable_cache(ttl=3600)  # Cache for 1 hour
response = completion("gpt-4", [{"role": "user", "content": "Hello"}])
# Second identical call returns instantly from cache
```

### Fallback (Increase Reliability)

```python
from tinymagiq_ai_gateway import with_fallback

response = with_fallback(
    models=["gpt-4", "claude-3-opus", "gpt-3.5-turbo"],
    messages=[{"role": "user", "content": "Hello"}]
)
# Tries gpt-4 first, falls back to claude-3 if it fails
```

### Load Balancing (Distribute Traffic)

```python
from tinymagiq_ai_gateway import with_load_balance

router = with_load_balance(
    deployments=[
        {"model_name": "gpt4-east", "litellm_params": {"model": "gpt-4"}},
        {"model_name": "gpt4-west", "litellm_params": {"model": "gpt-4"}},
    ],
    strategy="least-busy"
)
response = router.completion(
    model="gpt4-east",
    messages=[{"role": "user", "content": "Hello"}]
)
```

### Guardrails (Block Harmful Content)

```python
from tinymagiq_ai_gateway import add_block_pattern, check_content

add_block_pattern("ssn", r"\d{3}-\d{2}-\d{4}")
add_block_pattern("credit_card", r"\d{4}-\d{4}-\d{4}-\d{4}")

if check_content("My SSN is 123-45-6789"):
    print("Safe to process")
else:
    print("Blocked - contains sensitive data")
```

### Smart Routing (Optimize Cost/Latency)

```python
from tinymagiq_ai_gateway import smart_route

router = smart_route(
    models=[
        {"model_name": "expensive", "litellm_params": {"model": "gpt-4"}},
        {"model_name": "cheap", "litellm_params": {"model": "gpt-4o-mini"}},
    ],
    goal="cost"  # Always pick cheapest
)
```

### Logging (Track Usage)

```python
from tinymagiq_ai_gateway import enable_logging

enable_logging(providers=["console"])
# All API calls are now logged
```

## Available Functions

| Function | Description |
|----------|-------------|
| `completion()` | Generate text from any LLM |
| `acompletion()` | Async version of completion() |
| `embedding()` | Convert text to vector |
| `embedding_batch()` | Convert multiple texts to vectors |
| `with_fallback()` | Try multiple models if one fails |
| `awith_fallback()` | Async version of with_fallback() |
| `enable_cache()` | Cache responses to save money |
| `disable_cache()` | Turn off caching |
| `clear_cache()` | Delete cached responses |
| `cache_status()` | Check if caching is enabled |
| `with_load_balance()` | Distribute requests across deployments |
| `add_block_pattern()` | Block content matching regex |
| `remove_block_pattern()` | Remove a block rule |
| `check_content()` | Check if content is safe |
| `find_matches()` | Find blocked patterns in text |
| `clear_patterns()` | Remove all block rules |
| `list_patterns()` | List configured block rules |
| `smart_route()` | Route to cheapest/fastest model |
| `enable_logging()` | Log API calls |
| `disable_logging()` | Turn off logging |
| `redact_messages()` | Hide message content from logs |
| `unredact_messages()` | Show message content in logs |

## License

MIT License - see [License](License) for details.

Powered by [LiteLLM](https://github.com/BerriAI/litellm) (MIT License).
