Catalog PyPI
Back to packageRELEASE DETAILS

0.1.0

PyPI

aigateway-sdk

Unified AI Gateway - Multi-provider LLM routing, observability, and evaluation platform

aianthropicevaluationgatewaygeminillmobservabilityopenaitracing
Published3 Apr 2026
Direct dependencies31
Transitive dependenciesNot calculated

README

Version 0.1.0 documentation

Ai_Gateway

A unified AI Gateway SDK for LLM routing, observability, and evaluation.

PyPI version License: MIT

Features

  • Multi-Provider Gateway: Unified API for OpenAI, Anthropic, Google Gemini with automatic fallbacks
  • Full Observability: Distributed tracing, logging, cost tracking, and analytics
  • Evaluation Metrics: Built-in metrics for relevance, coherence, toxicity detection
  • Smart Caching: Response caching with semantic similarity matching
  • Self-Hosted or Cloud: Store telemetry locally (SQLite) or in the cloud

Installation

pip install Ai_Gateway

# With all providers
pip install Ai_Gateway[all-providers]

# With semantic caching
pip install Ai_Gateway[semantic-cache]

# Everything
pip install Ai_Gateway[full]

Quick Start

Basic Usage

import aigateway

# Initialize with your API keys
aigateway.init(
    openai_api_key="sk-...",
    anthropic_api_key="sk-ant-...",
    google_api_key="...",
)

# Use the unified gateway
response = aigateway.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

Monitor Existing Clients

from openai import OpenAI
import aigateway

# Initialize AIGateway
aigateway.init()

# Wrap your existing client
client = OpenAI()
aigateway.monitor(client)

# All calls are now automatically traced
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Automatic Fallbacks

import aigateway

aigateway.init(
    openai_api_key="sk-...",
    anthropic_api_key="sk-ant-...",
    fallback_providers=["anthropic"],  # Fallback to Anthropic if OpenAI fails
)

# Will automatically retry with Anthropic if OpenAI fails
response = aigateway.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Tracing

import aigateway
from aigateway import trace, span

@trace(name="my_workflow")
async def process_request(query: str):
    # Create spans for sub-operations
    with span("retrieve_context"):
        context = await retrieve_documents(query)

    with span("generate_response"):
        response = await generate_answer(query, context)

    return response

Evaluation

import aigateway

# Evaluate LLM outputs
result = await aigateway.evaluate(
    input_text="What is Python?",
    output_text="Python is a programming language...",
    metrics=["relevance", "coherence", "toxicity"]
)

print(f"Overall Score: {result.overall_score}")
print(f"Passed: {result.passed}")

for metric in result.metrics:
    print(f"  {metric.name}: {metric.score:.2f}")

Track Feedback

import aigateway

# Track user feedback on responses
aigateway.track_feedback(
    trace_id="...",
    value="thumbs_up",
    comment="Very helpful response!"
)

Configuration

Environment Variables

AIGATEWAY_API_KEY=your-cloud-api-key
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...

AIGATEWAY_DEFAULT_PROVIDER=openai
AIGATEWAY_STORAGE_BACKEND=sqlite
AIGATEWAY_TRACING_ENABLED=true
AIGATEWAY_CACHE_ENABLED=true

Programmatic Configuration

import aigateway

aigateway.init(
    # Provider keys
    openai_api_key="sk-...",
    anthropic_api_key="sk-ant-...",

    # Gateway settings
    default_provider="openai",
    fallback_providers=["anthropic", "google"],

    # Tracing
    tracing_enabled=True,
    sample_rate=1.0,

    # Storage (sqlite, postgresql, cloud, memory)
    storage_backend="sqlite",
    storage_path="./aigateway.db",

    # Caching
    cache_enabled=True,
    cache_backend="memory",

    # Debug
    debug=False,
)

API Reference

Gateway Client

from aigateway import AIGateway

gateway = AIGateway()

# Async completion
response = await gateway.complete(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0.7,
    max_tokens=1000,
)

# Streaming
async for chunk in gateway.complete_stream(
    model="gpt-4",
    messages=[{"role": "user", "content": "Tell me a story"}],
):
    print(chunk.choices[0].delta.content, end="")

# Embeddings
embeddings = await gateway.embed(
    model="text-embedding-3-small",
    input="Hello, world!"
)

Tracing

from aigateway import Trace, Span, SpanKind

# Manual tracing
with Trace(name="my_request", user_id="user123") as trace:
    with trace.span("step1", kind=SpanKind.LLM) as span:
        span.set_input({"query": "Hello"})
        result = do_llm_call()
        span.set_output({"response": result})
        span.set_llm_info(model="gpt-4", provider="openai")

Evaluation Metrics

from aigateway.evaluation import (
    Evaluator,
    RelevanceMetric,
    CoherenceMetric,
    ToxicityMetric,
    CustomMetric,
)

# Custom evaluator
evaluator = Evaluator(metrics=[
    RelevanceMetric(threshold=0.8),
    CoherenceMetric(threshold=0.6),
    ToxicityMetric(threshold=0.2),
])

result = await evaluator.evaluate(
    input_text="...",
    output_text="...",
    context="...",  # Optional
)

Storage Backends

from aigateway.storage import SQLiteStorage, CloudStorage, MemoryStorage

# SQLite (local)
storage = SQLiteStorage(db_path="./data.db")
await storage.initialize()

# Cloud (remote)
storage = CloudStorage(
    endpoint="https://api.aigateway.io",
    api_key="your-api-key"
)
await storage.initialize()

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src tests
ruff check src tests

# Type checking
mypy src

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE for details.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 35

Native requirements
31 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
aiosqlite
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
aiosqlite>=0.19.0runtime
contextvars
Environment
{
  "extras": "",
  "marker": "python_version < \"3.7\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
contextvars>=2.4; python_version < "3.7"runtime
httpx
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
httpx>=0.25.0runtime
pydantic-settings
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pydantic-settings>=2.0.0runtime
pydantic
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pydantic>=2.0.0runtime
python-dotenv
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
python-dotenv>=1.0.0runtime
structlog
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
structlog>=23.1.0runtime
tenacity
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
tenacity>=8.2.0runtime
tiktoken
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
tiktoken>=0.5.0runtime
anthropic
Environment
{
  "extras": "",
  "marker": "extra == \"all-providers\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
anthropic>=0.18.0; extra == "all-providers"runtime
google-generativeai
Environment
{
  "extras": "",
  "marker": "extra == \"all-providers\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
google-generativeai>=0.3.0; extra == "all-providers"runtime
openai
Environment
{
  "extras": "",
  "marker": "extra == \"all-providers\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
openai>=1.0.0; extra == "all-providers"runtime
anthropic
Environment
{
  "extras": "",
  "marker": "extra == \"anthropic\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
anthropic>=0.18.0; extra == "anthropic"runtime
black
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
black>=23.0.0; extra == "dev"runtime
httpx
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
httpx>=0.25.0; extra == "dev"runtime
mypy
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
mypy>=1.5.0; extra == "dev"runtime
pre-commit
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pre-commit>=3.4.0; extra == "dev"runtime
pytest-asyncio
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pytest-asyncio>=0.21.0; extra == "dev"runtime
pytest-cov
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pytest-cov>=4.1.0; extra == "dev"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.4.0; extra == "dev"runtime
ruff
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
ruff>=0.1.0; extra == "dev"runtime
mkdocs-material
Environment
{
  "extras": "",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
mkdocs-material>=9.4.0; extra == "docs"runtime
mkdocs
Environment
{
  "extras": "",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
mkdocs>=1.5.0; extra == "docs"runtime
mkdocstrings
Environment
{
  "extras": "python",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
mkdocstrings[python]>=0.23.0; extra == "docs"runtime
aigateway
Environment
{
  "extras": "all-providers,dev,docs,postgres,redis,semantic-cache,server",
  "marker": "extra == \"full\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
aigateway[all-providers,dev,docs,postgres,redis,semantic-cache,server]; extra == "full"runtime
google-generativeai
Environment
{
  "extras": "",
  "marker": "extra == \"google\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
google-generativeai>=0.3.0; extra == "google"runtime
openai
Environment
{
  "extras": "",
  "marker": "extra == \"openai\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
openai>=1.0.0; extra == "openai"runtime
asyncpg
Environment
{
  "extras": "",
  "marker": "extra == \"postgres\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
asyncpg>=0.29.0; extra == "postgres"runtime
sqlalchemy
Environment
{
  "extras": "asyncio",
  "marker": "extra == \"postgres\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
sqlalchemy[asyncio]>=2.0.0; extra == "postgres"runtime
redis
Environment
{
  "extras": "",
  "marker": "extra == \"redis\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
redis>=5.0.0; extra == "redis"runtime
numpy
Environment
{
  "extras": "",
  "marker": "extra == \"semantic-cache\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
numpy>=1.24.0; extra == "semantic-cache"runtime
sentence-transformers
Environment
{
  "extras": "",
  "marker": "extra == \"semantic-cache\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
sentence-transformers>=2.2.0; extra == "semantic-cache"runtime
fastapi
Environment
{
  "extras": "",
  "marker": "extra == \"server\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
fastapi>=0.109.0; extra == "server"runtime
python-multipart
Environment
{
  "extras": "",
  "marker": "extra == \"server\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
python-multipart>=0.0.6; extra == "server"runtime
uvicorn
Environment
{
  "extras": "standard",
  "marker": "extra == \"server\"",
  "requires_python": ">=3.9",
  "evaluation": "NOT_EVALUATED"
}
uvicorn[standard]>=0.27.0; extra == "server"runtime

Distribution files

2 collected
aigateway_sdk-0.1.0-py3-none-any.whl

bdist_wheel · 195.47 KB · Python py3

Source file
aigateway_sdk-0.1.0.tar.gz

sdist · 165.21 KB · Python source

Source file

Repository

PENDING
uditmishra-webby/aigate

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:45 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:a07e68466b29eb73d2cc4cabcca01d1c9f4534900ed4f8d5e898c64731cdaff5

Other collected versions

View all collected versions →