Skip to content

Commit 54fb56a

Browse files
authored
Add base_url to Mistral Provider (#1617)
1 parent dcfa821 commit 54fb56a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/models/mistral.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ from pydantic_ai.models.mistral import MistralModel
5252
from pydantic_ai.providers.mistral import MistralProvider
5353

5454
model = MistralModel(
55-
'mistral-large-latest', provider=MistralProvider(api_key='your-api-key')
55+
'mistral-large-latest', provider=MistralProvider(api_key='your-api-key', base_url='https://<mistral-provider-endpoint>')
5656
)
5757
agent = Agent(model)
5858
...

pydantic_ai_slim/pydantic_ai/providers/mistral.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444
*,
4545
api_key: str | None = None,
4646
mistral_client: Mistral | None = None,
47+
base_url: str | None = None,
4748
http_client: AsyncHTTPClient | None = None,
4849
) -> None:
4950
"""Create a new Mistral provider.
@@ -52,11 +53,13 @@ def __init__(
5253
api_key: The API key to use for authentication, if not provided, the `MISTRAL_API_KEY` environment variable
5354
will be used if available.
5455
mistral_client: An existing `Mistral` client to use, if provided, `api_key` and `http_client` must be `None`.
56+
base_url: The base url for the Mistral requests.
5557
http_client: An existing async client to use for making HTTP requests.
5658
"""
5759
if mistral_client is not None:
5860
assert http_client is None, 'Cannot provide both `mistral_client` and `http_client`'
5961
assert api_key is None, 'Cannot provide both `mistral_client` and `api_key`'
62+
assert base_url is None, 'Cannot provide both `mistral_client` and `base_url`'
6063
self._client = mistral_client
6164
else:
6265
api_key = api_key or os.environ.get('MISTRAL_API_KEY')
@@ -67,7 +70,7 @@ def __init__(
6770
'to use the Mistral provider.'
6871
)
6972
elif http_client is not None:
70-
self._client = Mistral(api_key=api_key, async_client=http_client)
73+
self._client = Mistral(api_key=api_key, async_client=http_client, server_url=base_url)
7174
else:
7275
http_client = cached_async_http_client(provider='mistral')
73-
self._client = Mistral(api_key=api_key, async_client=http_client)
76+
self._client = Mistral(api_key=api_key, async_client=http_client, server_url=base_url)

0 commit comments

Comments
 (0)