Problem/Motivation
Currently the Mistral provider (or rather the Partitech\PhpMistral lib) hardcodes the API endpoint (https://api.mistral.ai). There's no way to configure a custom endpoint, which is useful for:
- Using API proxies
- Self-hosted or enterprise Mistral deployments
- Automated testing with mock servers
Other providers like OpenAI support this via a host configuration option.
Proposed resolution
1. Add a host field to MistralConfigForm (in Advanced settings)
2. Save it to ai_provider_mistral.settings config
3. Update loadClient() to pass the custom URL to MistralClient constructor
4. Update config schema
The php-mistral library already supports this:
public function __construct(string $apiKey, string $url = self::ENDPOINT)
Remaining tasks
- Add host field to config form
- Update MistralProvider::loadClient()
- Update config schema
User interface changes
- Adds a new "Host" text field under "Advanced settings" on the Mistral configuration form (/admin/config/ai/providers/mistral)
API changes
- None - the provider's public methods remain unchanged
Data model changes
- Adds new host key to ai_provider_mistral.settings configuration
- Updates config schema to include the host property
Issue fork ai_provider_mistral-3570602
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
petar_basic commentedComment #4
petar_basic commented- Added host setting to config schema with empty default (uses Mistral's default)
- Added "API Host" text field to the settings form with helper text
- Modified loadClient() to pass custom host to the Mistral client when configured
To test:
1. Go to /admin/config/ai/providers/mistral
2. Enter a custom host URL (e.g., https://invalid.test)
3. Save and run a chat request:
4. Verify the error message shows the custom host: Could not resolve host: invalid.test for "https://invalid.test/v1/chat/completions"
OR setup a valid host - e.g. a mock server or a proxy
5. Clear the host field and save - verify requests go to the default api.mistral.ai endpoint
Comment #5
fagothanks, the feature is straight-forward and easy to add. changes are good and come with tests. also verified locally it works as it should. Merged!