Skip to content
This repository was archived by the owner on Aug 29, 2026. It is now read-only.

Commit c38ab5b

Browse files
feat(mistral): make Mistral SDK base URL configurable
Add a single optional `MISTRAL_BASE_URL` setting that overrides the `server_url` passed to every `Mistral(...)` SDK client constructed in the backend: the dense embedder, the OCR client, and the chat LLM adapter. When unset (the default), the SDK continues to use its built-in `https://api.mistral.ai` endpoint, so behavior is unchanged for existing deployments. When set, requests are routed to the override URL — useful for hitting a self-hosted Mistral deployment or a corporate proxy. Also expose the new setting in `.env.example` and update the `_create_dense_embedder` factory and the `MistralDenseEmbedder` ctor to forward the value. Assisted-by: Mistral-Vibe:foundry-opus-4.7 Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
1 parent 569f6d6 commit c38ab5b

7 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ SPARSE_EMBEDDER=fastembed_bm25
4747
OPENAI_API_KEY=
4848
ANTHROPIC_API_KEY=
4949
MISTRAL_API_KEY=
50+
# Optional — override the base URL used by every Mistral client (embedder,
51+
# OCR, LLM). Unset to use the default (https://api.mistral.ai). Set this to
52+
# point at a self-hosted Mistral endpoint or a corporate proxy.
53+
# MISTRAL_BASE_URL=
5054

5155
# Development Settings
5256
LOCAL_DEVELOPMENT=false

‎backend/airweave/adapters/llm/mistral.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def __init__(
4848
)
4949

5050
try:
51-
self._client = Mistral(api_key=api_key)
51+
self._client = Mistral(
52+
api_key=api_key,
53+
server_url=settings.MISTRAL_BASE_URL,
54+
)
5255
except Exception as e:
5356
raise RuntimeError(f"Failed to initialize Mistral client: {e}") from e
5457

‎backend/airweave/core/config/settings.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class Settings(BaseSettings):
7474
TEXT2VEC_INFERENCE_URL (str): The URL for text2vec-transformers inference service.
7575
OPENAI_API_KEY (Optional[str]): The OpenAI API key.
7676
MISTRAL_API_KEY (Optional[str]): The Mistral AI API key.
77+
MISTRAL_BASE_URL (Optional[str]): Override the base URL used by every
78+
Mistral SDK client (embeddings, OCR, chat). Unset → use the SDK
79+
default (``https://api.mistral.ai``). Useful for routing to a
80+
self-hosted Mistral endpoint or a corporate proxy.
7781
EMBEDDING_DIMENSIONS (int): Embedding dimensions for the stack (provider, Vespa).
7882
FIRECRAWL_API_KEY (Optional[str]): The FireCrawl API key.
7983
TEMPORAL_HOST (str): The host of the Temporal server.
@@ -200,6 +204,9 @@ class Settings(BaseSettings):
200204
OPENAI_API_KEY: Optional[str] = None
201205
ANTHROPIC_API_KEY: Optional[str] = None
202206
MISTRAL_API_KEY: Optional[str] = None
207+
# Optional override for the Mistral SDK base URL. When set, applied to all
208+
# Mistral clients (embedder, OCR, LLM). Unset → SDK default.
209+
MISTRAL_BASE_URL: Optional[str] = None
203210
FIRECRAWL_API_KEY: Optional[str] = None
204211
GROQ_API_KEY: Optional[str] = None
205212
COHERE_API_KEY: Optional[str] = None

‎backend/airweave/core/container/factory.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ def _create_dense_embedder(
809809
api_key=settings.MISTRAL_API_KEY,
810810
model=spec.api_model_name,
811811
dimensions=EMBEDDING_DIMENSIONS,
812+
server_url=settings.MISTRAL_BASE_URL,
812813
)
813814

814815
if spec.embedder_class_ref is LocalDenseEmbedder:

‎backend/airweave/domains/embedders/dense/mistral.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@ def __init__(
4545
api_key: str,
4646
model: str,
4747
dimensions: int,
48+
server_url: str | None = None,
4849
) -> None:
4950
"""Initialize the Mistral dense embedder.
5051
5152
Args:
5253
api_key: Mistral API key.
5354
model: Model name (e.g. "mistral-embed").
5455
dimensions: Expected output dimensions (validated on response only).
56+
server_url: Optional override for the Mistral API base URL. When
57+
``None`` (default), the SDK uses ``https://api.mistral.ai``.
5558
"""
5659
self._model = model
5760
self._dimensions = dimensions
58-
self._client = Mistral(api_key=api_key)
61+
self._client = Mistral(api_key=api_key, server_url=server_url)
5962
self._tokenizer = get_tokenizer(model)
6063
self._semaphore = asyncio.Semaphore(self._MAX_CONCURRENT_REQUESTS)
6164

‎backend/airweave/domains/ocr/mistral/ocr_client.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def ensure_initialized(self) -> None:
8686

8787
self._client = Mistral(
8888
api_key=settings.MISTRAL_API_KEY,
89+
server_url=settings.MISTRAL_BASE_URL,
8990
timeout_ms=120_000, # 2 minutes per OCR call
9091
)
9192
self._initialized = True

‎backend/tests/unit/core/test_dense_embedder_factory.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def _make_settings(**overrides):
1818
defaults = dict(
1919
OPENAI_API_KEY="sk-test-openai",
2020
MISTRAL_API_KEY="test-mistral-key",
21+
MISTRAL_BASE_URL=None,
2122
TEXT2VEC_INFERENCE_URL="http://localhost:9878",
2223
)
2324
defaults.update(overrides)

0 commit comments

Comments
 (0)