Skip to main content

AIRiskGuard Gateway

PyPI License: MIT Python 3.10+

AI traffic management for developer teams. A local proxy that sits between your developers and AI provider APIs — routing, logging, and protecting every AI call.

Free (MIT) · pip install airiskguard · works with Claude Code, Cursor, Copilot, any AI tool

What it does

  • Smart routing — route PII to an internal model, financial data to Azure, simple queries to cheaper models. Rules in plain YAML. Session stickiness keeps conversations on the same model.
  • Cost dashboard — see spend by model, by day, by team. Know your AI bill before it arrives.
  • Sensitive data protection — blocks API keys, SSNs, credit cards, and financial data before they reach external APIs. Redacts or blocks based on your policy.
  • Model allowlist — define which models your team can use. Everything else is blocked.
  • Content classification — detects task type (code, summarization, translation, Q&A), complexity, and language to enable smarter routing rules.

Quickstart

pip install airiskguard
airiskguard-gateway start         # starts API proxy on localhost:8080

Configure your AI tool

Claude Code:

export ANTHROPIC_BASE_URL=http://127.0.0.1:8080/anthropic
export ANTHROPIC_API_KEY=gw-your-gateway-key   # gateway key, not Anthropic key

OpenAI Codex CLI:

export OPENAI_BASE_URL=http://127.0.0.1:8080/openai
export OPENAI_API_KEY=gw-your-gateway-key

DeepSeek / Moonshot / GLM / any provider:

export OPENAI_BASE_URL=http://127.0.0.1:8080/deepseek   # or /moonshot, /glm, /minimax
export OPENAI_API_KEY=gw-your-gateway-key

The gateway key (gw-...) is issued by the gateway admin via airiskguard-gateway keygen. Developers never need the real provider API keys — the gateway holds them centrally. If no gateway key is configured, access is open (fine for single-machine use).

Cursor — use transparent proxy mode:

airiskguard-gateway start --mode proxy
# then: Settings → Features → HTTP Proxy → http://127.0.0.1:8080

Verify it's working

# In another terminal, after setting the env var above:
airiskguard-gateway logs --tail 5
# You should see your AI requests appear here

Gateway Authentication

Without a gateway key, anyone who can reach localhost:8080 can use your AI API keys. Set one before deploying to a shared host.

Free tier — single shared key

# 1. Generate a key
airiskguard-gateway keygen

# 2. Add to config.yaml
gateway_key: gw-your-generated-key

# 3. Each developer sets it as their ANTHROPIC_API_KEY
export ANTHROPIC_API_KEY=gw-your-generated-key
export ANTHROPIC_BASE_URL=http://gateway-host:8080/anthropic

The gateway validates the key on every request. If it doesn't match, the request gets a 401.

Team tier — per-developer keys

# Generate a key per developer
airiskguard-gateway keygen --name john@company.com --team engineering
airiskguard-gateway keygen --name jane@company.com --team data

Create a keys file (/etc/airiskguard/keys.txt):

# Gateway keys
key=gw-abc123  name=john@company.com  team=engineering
key=gw-xyz789  name=jane@company.com  team=data

Set in config:

gateway_keys_file: /etc/airiskguard/keys.txt

Each developer uses their own key. The audit log shows who made each request. Revoke by removing the line.


API Keys

Check which keys are configured:

airiskguard-gateway keys
Provider       Env Var                  Status      Key (masked)
anthropic      ANTHROPIC_API_KEY        ✓ env       sk-ant-...
openai         OPENAI_API_KEY           ✗ missing
deepseek       DEEPSEEK_API_KEY         ✓ config    sk-...
ollama         (none)                   n/a         local model

Option 1 — env vars (recommended):

export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
export DEEPSEEK_API_KEY=sk-...
export MOONSHOT_API_KEY=sk-...
export GLM_API_KEY=...
export MISTRAL_API_KEY=sk-...

Option 2 — inline in config.yaml (env var takes priority if both set):

api_keys:
  anthropic: sk-ant-...
  openai: sk-...
  deepseek: sk-...
  moonshot: sk-...

Two modes

Mode How it works Best for
api (default) FastAPI HTTP server at localhost:8080. Point SDKs at it via BASE_URL. No CA cert needed. Claude Code, Codex CLI, any SDK-based tool
proxy mitmproxy transparent HTTPS proxy. Set HTTPS_PROXY. Requires CA cert install. Cursor, browser-based tools, generic HTTP clients
airiskguard-gateway start              # API mode (default)
airiskguard-gateway start --mode proxy # Transparent proxy mode

Configuration

airiskguard-gateway config init   # write default config to ~/.config/airiskguard-gateway/config.yaml

Key settings:

on_secrets_detected: block    # block | redact | log
on_pii_detected: redact       # block | redact | log

allowed_models:
  - claude-sonnet-4-6
  - gpt-4o
  - gpt-4o-mini
  - deepseek-chat

Smart Routing

Rules are evaluated in order. First match wins. Session stickiness keeps a conversation on the same model once routed.

routing:
  sticky_sessions: true       # same conversation → same model
  session_ttl_hours: 24

  rules:
    # PII → local model, never leaves the machine
    - match: contains_pii
      action: route_to
      destination: local_ollama

    # Simple questions → 94% cheaper
    - match: task_type
      task_type: simple_qa
      action: route_to
      destination: deepseek_cheap

    # Chinese prompts → Chinese-optimized model
    - match: language
      language: zh
      action: route_to
      destination: moonshot

    # Downgrade all GPT-4 requests
    - match: model_pattern
      model_pattern: "gpt-4*"
      action: route_to
      destination: gpt_mini

    # Financial data → block external, or route to private endpoint
    - match: contains_financial_data
      action: block

  destinations:
    local_ollama:
      provider: ollama
      model: llama3.2

    deepseek_cheap:
      provider: deepseek
      model: deepseek-chat    # $0.14/M input vs $2.50/M for GPT-4o

    moonshot:
      provider: moonshot
      model: moonshot-v1-8k

    gpt_mini:
      provider: openai
      model: gpt-4o-mini

Available match types

match description
contains_pii email, phone, SSN, credit card, DOB detected in prompt
contains_secrets API keys, DB URIs, private keys detected
contains_financial_data revenue, IBAN, account numbers, trade data etc.
task_type simple_qa, code_generation, summarization, translation, complex_reasoning, data_analysis
complexity low, medium, high — based on prompt length + task type
language zh, en, ja, ko etc. — detected from character sets
model_pattern glob match on requested model name e.g. gpt-4*
provider match by provider name e.g. openai, anthropic
always catch-all fallback rule

Supported Providers

Built-in — just set the env var and route to the provider name:

Provider Env var BASE_URL path Notes
Anthropic ANTHROPIC_API_KEY /anthropic Claude Code default
OpenAI OPENAI_API_KEY /openai Codex CLI default
DeepSeek DEEPSEEK_API_KEY /deepseek 94% cheaper than GPT-4o
Moonshot MOONSHOT_API_KEY /moonshot Chinese-optimized
GLM (Zhipu) GLM_API_KEY /glm
MiniMax MINIMAX_API_KEY /minimax
Mistral MISTRAL_API_KEY /mistral
Azure OpenAI AZURE_OPENAI_API_KEY /azure_openai set base_url in config
Google GOOGLE_API_KEY /google
Ollama (none) /ollama local models

Add any OpenAI-compatible provider (vLLM, LiteLLM, custom):

providers:
  my_private_llm:
    base_url: https://llm.internal.company.com/v1
    format: openai
    api_key_env: MY_LLM_API_KEY

CLI Reference

airiskguard-gateway setup              # first-time setup: cert + per-tool instructions
airiskguard-gateway start              # start in API mode (default)
airiskguard-gateway start --mode proxy # start in transparent proxy mode
airiskguard-gateway start --daemon     # start as background daemon
airiskguard-gateway stop               # stop daemon
airiskguard-gateway status             # show status + last hour stats
airiskguard-gateway keys               # show API key status for all providers
airiskguard-gateway logs --tail 50     # view audit log
airiskguard-gateway logs --follow      # live stream
airiskguard-gateway logs --blocked-only
airiskguard-gateway license YOUR-KEY   # validate a license key
airiskguard-gateway config init        # write default config.yaml
airiskguard-gateway config show        # print current config
airiskguard-gateway install-cert       # generate CA + install to trust store (proxy mode)

Team Tier ($299/mo)

The free proxy runs locally. The Team tier adds:

  • Web dashboard with cost breakdown by model
  • Centralized policy server — push policies to all developer machines
  • Slack alerts on blocked requests
  • Per-team model allowlists
  • 30-day audit log retention

Start at airiskguard.ai.

Activating your license

# Validate your key
airiskguard-gateway license YOUR-LICENSE-KEY

# Start the policy server
AIRISKGUARD_LICENSE=YOUR-LICENSE-KEY docker compose up -d

License

Proxy core: MIT — free to use, modify, and distribute. Policy server + dashboard (src/airiskguard_gateway/policy_server/): Proprietary — requires a Team license.

Metadata

Release files for airiskguard 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airiskguard 0.8.0
File Size Uploaded Provenance Actions
airiskguard-0.8.0.tar.gz 55.5 kB Without provenance Details for airiskguard-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for airiskguard 0.8.0
File Interpreter ABI Platform Actions
airiskguard-0.8.0-py3-none-any.whl Python 3 none any Details for airiskguard-0.8.0-py3-none-any.whl

Total release size: 124.4 kB

Release files / airiskguard-0.8.0.tar.gz

Download URL airiskguard-0.8.0.tar.gz
Size 55.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1d56f8f07cdcee557e91bd898459f34558ac0a956cfd5229ec550dce10a931fa
BLAKE2b-256 checksum
How to use checksums
7c71b0d217234b0ae63eaea255a8bd4b75b6a35fa628f92592d12a730e70fbfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / airiskguard-0.8.0-py3-none-any.whl

Download URL airiskguard-0.8.0-py3-none-any.whl
Size 68.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0340a0c49708dd9660854aa175eb57ba6e339126be45b3d1346a9481d071401
BLAKE2b-256 checksum
How to use checksums
8d2dac5539ac1817ea44f06dc511071a786e851c115301c8880c0e562cf01632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for airiskguard 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page