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

Command icon 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

petar_basic created an issue. See original summary.

petar_basic’s picture

Status: Active » Needs work
petar_basic’s picture

Assigned: petar_basic » Unassigned
Status: Needs work » Needs review

- 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:

$provider = \Drupal::service("ai.provider")->createInstance("mistral"); 
$input = new ChatInput([new ChatMessage("user", "Hello")]);
$provider->chat($input, "mistral-small-latest");

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

fago’s picture

Status: Needs review » Fixed

thanks, 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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • fago committed 451e8407 on 1.1.x authored by petar_basic
    feat: #3570602 Add support for custom API endpoint configuration
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.