Sign up now for $10 free budget - Get an extra $40 when you get in touch

Using the python SDK

Call the AI Router using our python SDK

Setting up the SDK

If you don't have it installed already, install the airouter_sdk package using pip or the dependency manager of your choice:

pip install airouter_sdk

In case you are planning to use the full privacy mode, also install the privacy features along with the base package:

pip install "airouter_sdk[privacy]"

Model Routing

Set the api key to the one you generated. Then proceed to call the AiRouter client as a replacement to your OpenAI client:

from airouter import AiRouter
 
client = AiRouter(
    api_key="<THE-API-KEY-YOU-GENERATED>"
)
 
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
		{"role": "system", "content": "You are a helpful assistant."},
		{"role": "user", "content": "What is the meaning of life?"}
    ]
)

This example now uses the AI Router to select the most appropriate model for each request and uses gpt-4o-mini as a default model. You can also supply no model or specify a different model, as well as a list of models for the AI Router to consider to choose from.

Model Selection

You can also retrieve the best model name without automatically calling it. This allows you to use your private models (e.g. from AWS Bedrock) while maintaining full control over the execution.

from airouter import AiRouter
 
client = AiRouter(
    api_key="<THE-API-KEY-YOU-GENERATED>"
)
 
model_name = client.get_best_model(
    messages=[
		{"role": "system", "content": "You are a helpful assistant."},
		{"role": "user", "content": "What is the meaning of life?"}
    ]
)

You can also activate the full privacy mode to prevent your query being sent to the AI Router in clear text. With this mode the query will be embedded first on your machine and only the embedding will be sent.

Full Privacy Mode ensures your queries never leave your machine in raw text form. When enabled, queries are first converted to embeddings locally on your machine. Only these embeddings are then sent to the AI Router to retrieve the best model name.

Note: Make sure, you installed the privacy features as noted above (pip install "airouter_sdk[privacy]")

from airouter import AiRouter
 
client = AiRouter(
    api_key="<THE-API-KEY-YOU-GENERATED>"
)
 
model_name = client.get_best_model(
    messages=[
		{"role": "system", "content": "You are a helpful assistant."},
		{"role": "user", "content": "What is the meaning of life?"}
    ],
    full_privacy=True
)