Skip to content

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

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

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

Conversation

@Mahdi-Hasan

Copy link
Copy Markdown
Contributor

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

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>
An injected SDK client owns its credentials and endpoint, so the chat and
embedding clients no longer resolve MISTRAL_API_KEY or MISTRAL_SERVER_URL
for it.

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

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.

🟢 Approval recommended

No active review issues remain; the endpoint precedence and model-only settings behavior are covered by the added chat and embedding tests, with only non-blocking documentation and typing nits noted.

1 open issue
3 resolved since last review

Review effort: Lite

@eavanvalkenburg

Copy link
Copy Markdown
Member

Mehedi Hasan (@Mahdi-Hasan) The extra MistralChatModelSettings and MistralEmbeddingModelSettings types are not needed for this fix. required_fields controls validation after loading; it does not control which fields load_settings reads. Please keep the regular settings types, set the required fields for the injected-client path, and ignore the unused API-key and server-URL values. If we want field-selective settings loading, that should be added once to load_settings instead of duplicating settings schemas and adding type-ignore assignments here.

Drop MistralChatModelSettings and MistralEmbeddingModelSettings. The
injected path loads MistralSettings / MistralEmbeddingSettings with
relaxed required fields and ignores the api_key and server_url values,
as requested in review.

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

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg) Thanks, done in 2152a92.

  • Removed MistralChatModelSettings and MistralEmbeddingModelSettings, along with the type: ignore assignments.
  • Both clients make one load_settings call with the regular settings type. When a client is injected, the required fields are relaxed ([] for chat, ["embedding_model"] for embeddings). The loaded api_key and server_url are then ignored on the SDK-client path.
  • Removed the two tests that spied on which settings type was loaded. The endpoint-precedence tests stay.

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.

🔵 Needs a closer look

The injected-SDK paths still validate credential and server settings that are ignored afterward, allowing invalid overrides to break construction; both clients need model-only schema resolution and regression coverage.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@Mahdi-Hasan

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg) The python-tests-coverage failure (and merge-gatekeeper with it) is not from this change. It is a test-order flake in core.

  • Failing test: test_function_invocation_logic.py::test_mixed_declaration_only_batch_defers_siblings_until_all_host_results, with KeyError: 'value' in _sessions.py:437.
  • Cause: test_sessions.py::test_registered_child_tag_does_not_hijack_message_payload registers a global "text" state type and never unregisters it. When both tests run on the same xdist worker, the leaked decoder catches the {"type": "text", ...} content items during session restore.
  • This PR only touches packages/mistral. All 9 Python Tests matrix jobs pass.

I can't re-run the job from a fork. Could you re-run it when you review?

This branch was successfully deployed

1 active deployment
github-app-auth — 6dfb80eb Deployed Nov 6, 2026 by Mahdi-Hasan via add_label #27223
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

3 participants