Skip to main content
AI Router Logo

🪄 AI Router: Automatically get the best LLM for any request.

Documentation | Pricing | FAQ

PyPI version Python Versions License: MIT

Installation

Basic Installation

Install the package using pip:

pip install "airouter_sdk"

Privacy Features

To enable privacy mode for local embedding generation:

pip install "airouter_sdk[privacy]"

Development Setup

For SDK development, use Poetry:

poetry install --no-root

Usage

Basic Usage

Initialize the AiRouter class with your API key:

from airouter.router import AiRouter

# Initialize with API key
airouter = AiRouter(api_key="your_api_key_here")  # Note: Use AIROUTER_API_KEY env var instead in production

# Create a chat completion
response = airouter.chat.completions.create(
    messages=[
        {"role": "user", "content": "Hello, world!"}
    ]
)
print(response)

Environment Variables

For security best practices, set your API key as an environment variable:

export AIROUTER_API_KEY="your_api_key_here"

Model Selection

You can very easily retrieve the best model:

# Get the best model for your use case
model_name = airouter.get_best_model(
    messages=[
        {"role": "user", "content": "Hello, world!"}
    ]
)
print(model_name)  # Returns the recommended model identifier

This is particularly useful when working with private models or when you need to handle the model calling logic yourself.

You can also limit the models, for example to create a simple switch between gpt-5-mini and gpt-5:

model_name = airouter.get_best_model(
    messages=[
        {"role": "user", "content": "Hello, world!"}
    ],
    models=[Model.GPT_5_MINI, Model.GPT_5]
)
if model_name == Model.GPT_5_MINI:
    # call your private gpt-5-mini endpoint
else:
    # call your private gpt-5 endpoint

Privacy Features

For enhanced privacy, use the full_privacy mode to avoid sending message content:

# Use privacy mode for sensitive content
model_name = airouter.get_best_model(
    messages=[
        {"role": "user", "content": "Hello, world!"}
    ],
    full_privacy=True
)
print(model_name)

This mode:

  • Generates embeddings locally
  • Only sends embeddings to AI Router
  • Protects sensitive message content
  • Requires the privacy dependencies: pip install "airouter_sdk[privacy]"

If you want to use existing text-embedding-3-small embeddings, you can do so by handing in these embeddings and setting the embedding type:

# generate openai embeddings
messages = [
    {"role": "user", "content": "Hello, world!"}
]
input = " ".join(message['content'] for message in messages)
input = messages_query.replace("\n", " ")
embedding = openai_client.embeddings.create(
    model="text-embedding-3-small",
    input=input,
    dimensions=1536
)

# Use privacy mode for sensitive content with existing openai embeddings
model_name = airouter.get_best_model(
    full_privacy=True,
    embedding=embedding,
    embedding_type=EmbeddingType.TEXT_EMBEDDING_3_SMALL,
)
print(model_name)

Testing

Running Tests

Run the test suite using Poetry:

poetry run pytest

Integration Tests

For running integration tests (marked with @pytest.mark.integration):

poetry run pytest --run-integration

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for airouter-sdk 0.2.7

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

Source distribution (sdist)

Source distribution for airouter-sdk 0.2.7
File Size Uploaded Provenance Actions
airouter_sdk-0.2.7.tar.gz 6.1 kB Without provenance Details for airouter_sdk-0.2.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for airouter-sdk 0.2.7
File Interpreter ABI Platform Actions
airouter_sdk-0.2.7-py3-none-any.whl Python 3 none any Details for airouter_sdk-0.2.7-py3-none-any.whl

Total release size: 13.5 kB

Release files / airouter_sdk-0.2.7.tar.gz

Download URL airouter_sdk-0.2.7.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7a32efd62ea3216d984654ba508ff47263fc0c0b99fcc099a426469b1dce262b
BLAKE2b-256 checksum
How to use checksums
167a055accfd0cd27d478d923aa97d829d8833bfb8f56b7245b8199aeb8cc471
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.8 Darwin/25.5.0

Release files / airouter_sdk-0.2.7-py3-none-any.whl

Download URL airouter_sdk-0.2.7-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9261dfeb10f09f192761c49e6ecdfd2eb6f9aa760a0f0b4fb5d1b151a2cbe03a
BLAKE2b-256 checksum
How to use checksums
3a3f290f9c78fa197f9e9d7a5a3edb2861b52ca22dbaa60e94c7a07630a75cb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.8 Darwin/25.5.0

Security for airouter-sdk 0.2.7

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