Implementation:Mistralai Client python MistralAzure Init
| Knowledge Sources | |
|---|---|
| Domains | Cloud_Deployment, Azure, API_Client |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for creating an Azure-specific Mistral API client provided by the mistralai_azure package.
Description
The MistralAzure class initializes a client for Mistral models deployed on Azure AI. It accepts azure_api_key (string or callable) and azure_endpoint (the Azure deployment URL). The constructor normalizes the endpoint by stripping trailing slashes and appending /v1/ if not already present. It registers a CustomUserAgentHook that rewrites the User-Agent header to identify Azure SDK traffic. The client exposes lazy-loaded .chat and .ocr sub-SDKs.
Usage
Install mistralai_azure and instantiate with Azure credentials obtained from the Azure portal after deploying a Mistral model.
Code Reference
Source Location
- Repository: client-python
- File: packages/mistralai_azure/src/mistralai_azure/sdk.py
- Lines: L32-128
Signature
class MistralAzure:
def __init__(
self,
azure_api_key: Union[str, Callable[[], str]],
azure_endpoint: str,
retry_config: OptionalNullable[RetryConfig] = UNSET,
timeout_ms: Optional[int] = None,
http_client: Optional[HttpClient] = None,
async_http_client: Optional[AsyncHttpClient] = None,
debug_logger: Optional[Logger] = None,
):
"""
Args:
azure_api_key: Azure API key or callable returning a key.
azure_endpoint: Azure AI deployment endpoint URL.
retry_config: Retry settings.
timeout_ms: Request timeout in milliseconds.
"""
Import
from mistralai_azure import MistralAzure
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| azure_api_key | Union[str, Callable] | Yes | Azure API key from Azure portal |
| azure_endpoint | str | Yes | Azure AI deployment endpoint URL |
| retry_config | OptionalNullable[RetryConfig] | No | Retry configuration |
| timeout_ms | Optional[int] | No | Timeout in milliseconds |
Outputs
| Name | Type | Description |
|---|---|---|
| MistralAzure instance | MistralAzure | Configured client with .chat and .ocr sub-SDKs |
Usage Examples
Basic Azure Client
import os
from mistralai_azure import MistralAzure
client = MistralAzure(
azure_api_key=os.environ["AZURE_API_KEY"],
azure_endpoint=os.environ["AZURE_ENDPOINT"],
)
# Use chat completion
response = client.chat.complete(
model="azureai",
messages=[{"role": "user", "content": "Hello from Azure!"}],
)
print(response.choices[0].message.content)