Skip to content

Python: Report the injected Mistral SDK client's endpoint in service_url - #9968

Open
Mehedi Hasan (Mahdi-Hasan) wants to merge 2 commits into
microsoft:mainfrom
Mahdi-Hasan:fix/9965-mistral-injected-endpoint
Open

Mehedi Hasan (Mahdi-Hasan) wants to merge 2 commits into
microsoft:mainfrom
Mahdi-Hasan:fix/9965-mistral-injected-endpoint

Conversation

@Mahdi-Hasan

Copy link
Copy Markdown

Motivation & Context

When a mistralai.client.Mistral is injected, RawMistralChatClient, MistralChatClient and MistralEmbeddingClient still keep MISTRAL_SERVER_URL (or an explicit server_url=) in self.server_url. Requests go to the injected client's endpoint, but service_url() and telemetry report the other URL.

Description & Review Guide

  • What are the major changes?
    • For an injected SDK client, server_url now always comes from client.sdk_configuration.get_server_details()[0].
    • Docstrings note that server_url is ignored when client is provided.
  • What is the impact of these changes?
    • Only reported metadata changes. Requests already used the injected client's endpoint.
    • Owned-client and http_client paths keep their existing precedence. Model resolution is unchanged.
  • What do you want reviewers to focus on?
    • The issue also suggests not loading API key / server URL settings at all on the injected path. load_settings reads every field of the TypedDict, and both fields are plain strings that can't fail parsing. So I kept one load_settings call and stopped using those values, rather than adding a second settings type.

Related Issue

Fixes #9965

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, tests, and this description. The issue's repro was re-run against a real Mistral SDK client before and after the change.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

🤖 Generated with Claude Code

Mistral chat and embedding clients kept MISTRAL_SERVER_URL (or an explicit
server_url) in self.server_url when an SDK client was injected. Requests
still went to the injected client's endpoint, so service_url() and the
telemetry metadata reported the wrong server.

An injected mistralai.client.Mistral now always defines server_url.

Fixes microsoft#9965

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active moderate issues remain because injected SDK clients still load API key and server URL settings from ambient configuration, and the related documentation does not clearly distinguish SDK-client behavior from the deprecated HTTP-client path.

4 open issues

Review effort: Lite

Comment on lines +408 to +409
# The injected SDK client sends the requests, so its endpoint wins over configured settings.
self.server_url = client.sdk_configuration.get_server_details()[0]
Comment on lines +160 to +161
# The injected SDK client sends the requests, so its endpoint wins over configured settings.
self.server_url = client.sdk_configuration.get_server_details()[0]
api_key: Mistral API key. Defaults to ``MISTRAL_API_KEY`` environment variable.
server_url: Optional server URL override. Defaults to ``MISTRAL_SERVER_URL``
environment variable, or the Mistral default.
environment variable, or the Mistral default. Ignored when ``client`` is provided.
api_key: Mistral API key. Defaults to ``MISTRAL_API_KEY`` environment variable.
server_url: Optional server URL override. Defaults to ``MISTRAL_SERVER_URL``
environment variable, or the Mistral default.
environment variable, or the Mistral default. Ignored when ``client`` is provided.
server_url is only ignored when a Mistral SDK client is injected. The
deprecated httpx.AsyncClient path via `client` still uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
github-app-auth — 7c234d80 Deployed Nov 3, 2026 by Mahdi-Hasan via add_label #26917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Mistral environment endpoint overrides injected-client service metadata

2 participants