Skip to main content

TryAii

Embedding-based AI model router. Understands your prompt semantically and routes to the best model based on benchmarks, cost, speed, and quality.

from tryaii import DREClient, Router

router = Router()
result = router.route("Write a Python function to merge sorted arrays")

print(result.best_model)     # "gpt-5.2"
print(result.best_reasoning) # "Quality: 0.94 on [HumanEval (93%), SWE-bench (87%)]"

client = DREClient(api_key="sk-or-...")
response = client.chat("Write a quicksort implementation")
print(response.content)

Install

pip install tryaii

The base install includes local embeddings via sentence-transformers - no API keys needed.

Optional extras for provider integrations:

pip install tryaii[openrouter]  # Route & call models via OpenRouter (adds httpx)
pip install tryaii[openai]      # Use OpenAI embeddings instead of local (adds openai)
pip install tryaii[redis]       # Redis client for planned distributed cache (not yet implemented)
pip install tryaii[all]         # All optional integrations

Quick Start

from tryaii import Router, Priorities

router = Router()

# Route with default balanced priorities
result = router.route("Explain quantum entanglement simply")
print(result.best_model)

# Quality-first (ignore cost)
result = router.route(
    "Debug this memory leak in my Node.js app",
    priorities=Priorities(quality=5, cost=1, speed=2),
)

# Budget mode
result = router.route(
    "Summarize this email",
    priorities=Priorities.budget(),
)

CLI

Installing the package adds a tryaii command (same surface as the Node SDK). It opens with an animated blue→red banner, then runs your command. The banner prints to stderr and auto-suppresses when output is piped, so --json stays clean.

tryaii route "Write a Python function to merge sorted arrays" --quality=5 --cost=1
tryaii eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1
tryaii models --provider anthropic        # add --json for machine-readable output
tryaii benchmarks --json
tryaii setup                               # download the embedding model + warm centroids
tryaii cachelint request.json              # pre-flight prompt-cache analysis (warn-only)
Command Key options
route "<prompt>" --quality/--cost/--speed <1-5> (default 3), --top-k <n>
eval <input.json> -o/--output <dir>, --max-price <usd>, --output-tokens <n>, --budget-mode strict|fit-output
cachelint <input.json | -> --json, raw-text mode via --provider <name> + --model <name>; exact OpenAI/xAI counts need pip install tryaii[cachelint]

The cachelint engine also runs inside the clients: pass cache_lint="warn" to DREClient/AsyncDREClient/OpenRouterIntegration (or set TRYAII_CACHE_LINT=warn) to lint every outgoing chat request and verify cache predictions against the response usage — warn-only and fail-open.

| models | --provider <name>, --json | | benchmarks | --json | | setup / regenerate | --model <name> |

Global flags: --no-banner (or TRYAII_NO_BANNER=1), NO_COLOR=1, -v/--verbose, -V/--version. All flags work in any position and match the npm CLI.

Eval over a dataset

# Balanced run into a named folder
tryaii eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1

# Budget-aware: --max-price is the total budget for the whole dataset
tryaii eval prompts.json --output results/budget --max-price=0.10 --output-tokens=2000
tryaii eval prompts.json --output results/budget-fit --max-price=0.10 --output-tokens=2000 --budget-mode=fit-output

The input can be an array of strings or objects with prompt, optional id, and optional category. In budgeted eval, quality/cost/speed priority flags are ignored: price is the hard constraint, and the optimizer maximizes model quality within that price. --budget-mode=fit-output lowers the fixed output token estimate when the requested length cannot fit the total budget. The command writes results.jsonl, summary.json, and index.html.

OpenRouter Integration

from tryaii import Router
from tryaii.integrations import OpenRouterIntegration

router = Router()
openrouter = OpenRouterIntegration(router, api_key="sk-or-...")

response = openrouter.chat("Write a quicksort implementation")
print(response.model_used)  # Auto-selected best model
print(response.content)     # Actual response

OpenAI Embeddings

from tryaii import Router
from tryaii.embeddings import OpenAIEmbeddingProvider

router = Router(
    embedding_provider=OpenAIEmbeddingProvider(),
)

result = router.route("Summarize this architecture decision")
print(result.best_model)

Install the OpenAI client first:

pip install tryaii[openai]

License

Apache 2.0

Download files

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

Source Distribution

tryaii-0.5.0.tar.gz (237.8 kB view details)

Uploaded Source

Built Distribution

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

tryaii-0.5.0-py3-none-any.whl (228.9 kB view details)

Uploaded Python 3

File details

Details for the file tryaii-0.5.0.tar.gz.

File metadata

  • Download URL: tryaii-0.5.0.tar.gz
  • Upload date:
  • Size: 237.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for tryaii-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9500307ac3902892d6d83ec092b13bb22b542c82f88831b78b6016c53ac7fae3
MD5 005a85d80845bd5a789c7262f14ccc60
BLAKE2b-256 d7f2e4e63b54b6d33bc5dc5e6dd546456e88c10aba58ddd77a2caf6165dc1535

See more details on using hashes here.

File details

Details for the file tryaii-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: tryaii-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 228.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for tryaii-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d67e055b692796f1c542a79e2612e4da91da9decd58f1cd468a0ea4a07466e65
MD5 e9b4b09aadc6b82fef1d6c2ae8d10160
BLAKE2b-256 cf270db994967e400afeeaf83f7e49997cd889bd1fd357d1d74a7fa78f3932b0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

Supported by

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