Skip to content

datarobot_genai.core.config

config

LLMConfig

Bases: BaseModel

Pure LLM connection parameters — no env-var machinery, no NAT base class.

Used as a base for Config (adds env reading) and DataRobotLLMComponentModelConfig (adds NAT schema), and as the primary/fallback type accepted by the router so core has no NAT dependency.

Source code in datarobot_genai/core/config.py
class LLMConfig(BaseModel):
    """Pure LLM connection parameters — no env-var machinery, no NAT base class.

    Used as a base for ``Config`` (adds env reading) and
    ``DataRobotLLMComponentModelConfig`` (adds NAT schema), and as the
    primary/fallback type accepted by the router so ``core`` has no NAT
    dependency.
    """

    datarobot_endpoint: str | None = None
    datarobot_api_token: str | None = None
    llm_deployment_id: str | None = None
    nim_deployment_id: str | None = None
    use_datarobot_llm_gateway: bool = True
    llm_default_model: str | None = None

    def get_llm_type(self) -> LLMType:
        if self.use_datarobot_llm_gateway:
            return LLMType.GATEWAY
        elif self.llm_deployment_id:
            return LLMType.DEPLOYMENT
        elif self.nim_deployment_id:
            return LLMType.NIM
        else:
            return LLMType.EXTERNAL

    def to_litellm_params(self) -> dict:
        """Return a litellm_params dict suitable for ``litellm.Router``'s model_list.

        Falls back to env-loaded ``Config`` values for endpoint and api_key
        when they are not set on this instance directly.
        """
        env = Config()
        api_key = (
            self.datarobot_api_token
            if self.datarobot_api_token is not None
            else env.datarobot_api_token
        )
        endpoint = (
            self.datarobot_endpoint
            if self.datarobot_endpoint is not None
            else env.datarobot_endpoint
        )
        model_name = (
            getattr(self, "model_name", None)
            or self.llm_default_model
            or env.llm_default_model
            or "datarobot-deployed-llm"
        )
        llm_type = self.get_llm_type()

        if llm_type == LLMType.GATEWAY:
            return {
                "model": _with_datarobot_prefix(model_name),
                "api_base": llm_gateway_url(endpoint),
                "api_key": api_key,
            }
        elif llm_type == LLMType.DEPLOYMENT:
            return {
                "model": _with_datarobot_prefix(model_name),
                "api_base": deployment_url(self.llm_deployment_id, endpoint),  # type: ignore[arg-type]
                "api_key": api_key,
            }
        elif llm_type == LLMType.NIM:
            return {
                "model": _with_datarobot_prefix(model_name),
                "api_base": deployment_url(self.nim_deployment_id, endpoint),  # type: ignore[arg-type]
                "api_key": api_key,
            }
        else:  # EXTERNAL
            return {
                "model": model_name.removeprefix("datarobot/"),
                "api_key": api_key,
            }

to_litellm_params

to_litellm_params() -> dict

Return a litellm_params dict suitable for litellm.Router's model_list.

Falls back to env-loaded Config values for endpoint and api_key when they are not set on this instance directly.

Source code in datarobot_genai/core/config.py
def to_litellm_params(self) -> dict:
    """Return a litellm_params dict suitable for ``litellm.Router``'s model_list.

    Falls back to env-loaded ``Config`` values for endpoint and api_key
    when they are not set on this instance directly.
    """
    env = Config()
    api_key = (
        self.datarobot_api_token
        if self.datarobot_api_token is not None
        else env.datarobot_api_token
    )
    endpoint = (
        self.datarobot_endpoint
        if self.datarobot_endpoint is not None
        else env.datarobot_endpoint
    )
    model_name = (
        getattr(self, "model_name", None)
        or self.llm_default_model
        or env.llm_default_model
        or "datarobot-deployed-llm"
    )
    llm_type = self.get_llm_type()

    if llm_type == LLMType.GATEWAY:
        return {
            "model": _with_datarobot_prefix(model_name),
            "api_base": llm_gateway_url(endpoint),
            "api_key": api_key,
        }
    elif llm_type == LLMType.DEPLOYMENT:
        return {
            "model": _with_datarobot_prefix(model_name),
            "api_base": deployment_url(self.llm_deployment_id, endpoint),  # type: ignore[arg-type]
            "api_key": api_key,
        }
    elif llm_type == LLMType.NIM:
        return {
            "model": _with_datarobot_prefix(model_name),
            "api_base": deployment_url(self.nim_deployment_id, endpoint),  # type: ignore[arg-type]
            "api_key": api_key,
        }
    else:  # EXTERNAL
        return {
            "model": model_name.removeprefix("datarobot/"),
            "api_key": api_key,
        }

Config

Bases: LLMConfig, DataRobotAppFrameworkBaseSettings

Finds variables in the priority order of: env variables (including Runtime Parameters), .env, file_secrets, then Pulumi output variables.

Source code in datarobot_genai/core/config.py
class Config(LLMConfig, DataRobotAppFrameworkBaseSettings):
    """
    Finds variables in the priority order of: env
    variables (including Runtime Parameters), .env, file_secrets, then
    Pulumi output variables.
    """

    datarobot_endpoint: str = "https://app.datarobot.com/api/v2"

    max_history_messages: int = Field(
        default=DEFAULT_MAX_HISTORY_MESSAGES, ge=0, alias="datarobot_genai_max_history_messages"
    )

get_max_history_messages_default

get_max_history_messages_default() -> int

Return the default maximum number of history messages.

This can be overridden globally via the DATAROBOT_GENAI_MAX_HISTORY_MESSAGES environment variable. Invalid values fall back to the built-in default. Negative values are treated as 0 (disable history).

Source code in datarobot_genai/core/config.py
def get_max_history_messages_default() -> int:
    """Return the default maximum number of history messages.

    This can be overridden globally via the
    ``DATAROBOT_GENAI_MAX_HISTORY_MESSAGES`` environment variable.
    Invalid values fall back to the built-in default. Negative values are
    treated as 0 (disable history).
    """
    return max(Config().max_history_messages, 0)

default_response_model

default_response_model() -> str

Return the configured model to report in OpenAI chat/completions responses.

dragent agents ignore the request's model and run the LLM configured in workflow.yaml / env, so the response should report that actual model — not echo the caller's string (which need not be sent at all) nor NAT's "unknown-model" placeholder. Resolves the same way the LLM client does (:meth:LLMConfig.to_litellm_params): LLM_DEFAULT_MODEL env, else the deployed-LLM default; always datarobot/-prefixed and never None so the response can never regress to "unknown-model". (A per-LLM model_name set inline in workflow.yaml is not reflected here — env/global config only.)

Source code in datarobot_genai/core/config.py
def default_response_model() -> str:
    """Return the configured model to report in OpenAI ``chat/completions`` responses.

    dragent agents ignore the request's ``model`` and run the LLM configured in
    ``workflow.yaml`` / env, so the response should report that actual model — not
    echo the caller's string (which need not be sent at all) nor NAT's
    ``"unknown-model"`` placeholder. Resolves the same way the LLM client does
    (:meth:`LLMConfig.to_litellm_params`): ``LLM_DEFAULT_MODEL`` env, else the
    deployed-LLM default; always ``datarobot/``-prefixed and never ``None`` so the
    response can never regress to ``"unknown-model"``. (A per-LLM ``model_name`` set
    inline in ``workflow.yaml`` is not reflected here — env/global config only.)
    """
    return _with_datarobot_prefix(default_model_name() or "datarobot-deployed-llm")