Deploying a Model#

Before deploying a model, ensure that the QUANTAGONIA_API_KEY environment variable is set to a valid API key.

There are two ways to deploy a DecisionAI model, each suited for different use cases:

Using the Python Interface (For Dynamic Deployment)#

The Python interface is ideal for:

  • Dynamically creating and testing models

  • Quick experimentation with DecisionAI

  • Prototyping and development workflows

Here’s how to use it:

from decision_ai import DecisionAI
from decision_ai.client.schemas.model import OptModelClassNames

client = DecisionAI()

# Create and deploy model with automatic class name detection
response = client.deploy_model(
    module="path/to/your_model.py",  # File path to the python module containing the model
    model_name="your_model",         # Name for the model
    description=""                   # Optional description
)

# Or specify class names manually
class_names = OptModelClassNames(
    py_class_name_of_model="YourModel",
    py_class_name_of_input_data="YourInputData"
)
response = client.deploy_model(
    module="path/to/your_model.py",
    model_name="your_model",
    description="",
    class_names=class_names
)

# The response contains the model ID
model_id = response.id

Configuration File#

When using the CLI tools, the TOML configuration file (default: pyproject.toml) stores your model settings. Multiple models are supported.

You can either use decision_ai init to add models to the configuration file, or manually edit the file directly.

Structure#

Models are defined under [tool.decision_ai.model.<model_name>] sections:

[tool.decision_ai.model.my_model1]
description = "First optimization model"
path = "model1.py"
opt_model_class_name = "Model1"          # Optional - will be auto-detected if omitted
input_data_class_name = "MyInputData1"   # Optional - will be auto-detected if omitted
examples_dir = "examples1"               # Optional

[tool.decision_ai.model.my_model2]
description = "Second optimization model"
path = "model2.py"
# No class names - will be auto-detected during deployment
# No examples_dir - no in-context learning

Configuration Fields#

Each model configuration supports the following fields:

Required fields:

  • path (string): Path to the Python file containing the model code. The file must exist and be a valid Python file.

Optional fields:

  • opt_model_class_name (string): Name of the model class in the Python file. If omitted, the class name will be automatically detected during deployment. Must be provided together with input_data_class_name or both omitted.

  • input_data_class_name (string): Name of the input data class in the Python file. If omitted, the class name will be automatically detected during deployment. Must be provided together with opt_model_class_name or both omitted.

  • description (string): Description of your optimization model. Default: empty string.

  • examples_dir (string): Path to a directory containing XML example files for in-context learning. If specified, the directory must exist. If omitted, no in-context learning examples will be used.

Validation Rules#

When you run decision_ai validate or decision_ai deploy, the configuration is validated:

  1. The path must point to an existing file (not a directory)

  2. Both opt_model_class_name and input_data_class_name must be provided together, or both must be omitted for automatic detection

  3. If class names are provided, they must exist in the specified Python file

  4. If examples_dir is specified, it must point to an existing directory (not a file)

Manual Configuration#

You can manually edit the pyproject.toml file instead of using decision_ai init. This is useful when:

  • Migrating existing models

  • Batch adding multiple models

  • Using version control to manage configurations

  • Automating deployment pipelines

After manually editing the configuration, run decision_ai validate to ensure your configuration is correct before deploying.

Lock File#

The decisionai.lock file tracks deployed model IDs per base URL:

{
    "https://decisionai.quantagonia.com/api/v1": {
        "my_model1": "model-id-1",
        "my_model2": "model-id-2"
    },
    "https://staging.example.com/api/v1": {
        "my_model1": "staging-model-id-1"
    }
}

Warning

Do not manually edit the lock file. Use the CLI commands to manage model deployments.

Environment Variables#

Required:

  • QUANTAGONIA_API_KEY: Your API key for authentication (required for both CLI and Python interface)