doc/development/ai_features/model_switching.md
The Model Switching Framework in the GitLab AI Gateway allows customers to choose between different AI models for various features.
This feature is available for GitLab.com and self-managed instances using the cloud-connected AI Gateway.
This guide explains how to add new models to make them selectable by users on both SaaS and self-managed instances.
Adding a new model to the Model Switching Framework involves two main steps:
models.yml with its configuration parametersunit_primitives.ymlBoth files are located in the gitlab-ai-gateway repository.
Before adding a new model, ensure that:
gitlab-ai-gateway repository.FETCH_MODEL_SELECTION_DATA_FROM_LOCAL=true in your GDK environment. This will ensure that the model selection data is fetched from the local models.yml and unit_primitives.yml files.Add your model definition to ai_gateway/model_selection/models.yml. Each model requires the following properties:
| Property | Required | Description |
|---|---|---|
name | Yes | Human-readable name displayed in the UI (for example, "OpenAI GPT-5-Mini") |
gitlab_identifier | Yes | Unique identifier used internally (for example, gpt_5_mini) |
family | No | Ordered list of prompt definition families to use (see Prompt Selection) |
params | Yes | Dictionary of parameters passed to the model client |
# ai_gateway/model_selection/models.yml
models:
- name: "OpenAI GPT-5-Mini"
gitlab_identifier: "gpt_5_mini"
family:
- gpt_5
params:
model: gpt-5-mini-2025-08-07
max_tokens: 4_096
The params dictionary typically includes:
model: The actual model identifier used by the provider's APImax_tokens: Maximum number of tokens in the responsetemperature: Controls randomness (0.0 = deterministic, higher = more random)model_class_provider: The provider (for example, anthropic, litellm, vertex_ai)top_p, top_k, verbosity)The optional family field determines which prompt definitions are used with this model:
base prompts are usedAfter defining the model, add it to the appropriate feature's selectable_models list in ai_gateway/model_selection/unit_primitives.yml.
# ai_gateway/model_selection/unit_primitives.yml
configurable_unit_primitives:
- feature_setting: "duo_agent_platform"
unit_primitives:
- "duo_agent_platform"
default_model: "claude_sonnet_4_20250514"
selectable_models:
- "claude_sonnet_3_7_20250219"
- "claude_sonnet_4_20250514"
- "claude_sonnet_4_5_20250929"
- "gpt_5"
- "gpt_5_mini" # Add your new model here
- "gpt_5_codex"
Each feature setting entry includes:
feature_setting: The feature identifierunit_primitives: List of unit primitives using this configurationdefault_model: The gitlab_identifier of the default modelselectable_models: List of gitlab_identifier values that users can choose from[!note] The
default_modelmust always be included in theselectable_modelslist, or validation will fail.
The AI Gateway automatically validates the configuration:
unit_primitives.yml must be defined in models.ymldefault_model must be included in selectable_modelsIf validation fails, you'll see clear error messages indicating what needs to be fixed.
After adding a new model:
Verify the configuration files are syntactically correct (valid YAML)
Test the model selection in the GitLab UI
Ensure the model responds correctly to requests and that the right prompts are being used. You can do this by tailing the logs of the ai_gateway service and GitLab Duo workflow service, using:
gdk tail duo-workflow-service gitlab-ai-gateway
Validate that appropriate prompts are being used
gpt-5-mini and gpt-5-codex models.