Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Workflow:Mistralai Client python Azure Chat Completion

From Leeroopedia
Revision as of 11:01, 16 February 2026 by Admin (talk | contribs) (Auto-imported from workflows/Mistralai_Client_python_Azure_Chat_Completion.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains LLMs, Chat_Completion, Azure, Cloud_Deployment
Last Updated 2026-02-15 14:00 GMT

Overview

End-to-end process for using Mistral AI models deployed on Azure AI through the dedicated Azure Python SDK wrapper.

Description

This workflow covers how to interact with Mistral AI models that are deployed as Azure AI endpoints. It uses the mistralai_azure package, which wraps the standard Mistral SDK with Azure-specific authentication (Azure API key), endpoint URL configuration, and request routing. The Azure wrapper automatically appends the /v1/ path to the endpoint URL and provides access to Chat Completion and OCR APIs. Both synchronous and asynchronous request patterns are supported, along with streaming via Server-Sent Events.

Usage

Execute this workflow when you have deployed a Mistral model on Azure AI and need to interact with it through the Azure-hosted endpoint. This is appropriate for organizations that require Azure-managed infrastructure, compliance, or data residency requirements, rather than using Mistral's direct API endpoint.

Execution Steps

Step 1: Deploy Mistral on Azure and Obtain Credentials

Deploy a Mistral model on Azure AI following the official deployment guide. Obtain the Azure endpoint URL and Azure API key from the Azure portal after deployment is complete.

Key considerations:

  • Requires an active Azure subscription with Azure AI resources provisioned
  • Store credentials as environment variables (AZURE_ENDPOINT, AZURE_API_KEY)
  • The endpoint URL should point to the Azure AI deployment, not the Mistral API directly

Step 2: Install the Azure SDK Package

Install the mistralai package which includes the mistralai_azure sub-package. The Azure wrapper is distributed as part of the main SDK but lives in a separate package under packages/mistralai_azure.

Key considerations:

  • Install with pip install mistralai or pip install mistralai_azure directly
  • The Azure SDK has the same base dependencies as the main SDK (httpx, pydantic)

Step 3: Initialize the MistralAzure Client

Create an instance of MistralAzure, passing the Azure API key and Azure endpoint URL. The client automatically normalizes the endpoint URL by appending /v1/ if not present, and configures bearer token authentication.

Key considerations:

  • The client auto-appends /v1/ to the endpoint if not already present
  • SDK hooks rewrite the User-Agent header for Azure-specific identification
  • Context manager pattern is recommended for proper connection cleanup

Step 4: Send Chat Completion Request

Call chat.complete() (sync), chat.complete_async() (async), or chat.stream() (streaming) with the message payload. The model parameter defaults to "azureai" since the model is determined by the Azure deployment endpoint.

Key considerations:

  • The model parameter is typically omitted or set to "azureai" as the deployment determines the model
  • Message format is identical to the standard Mistral SDK
  • All standard parameters (temperature, max_tokens, tools, response_format) are supported
  • Streaming follows the same SSE pattern as the standard SDK

Step 5: Process the Response

Extract the generated text from the response object, which follows the same structure as the standard Mistral chat completion response.

Key considerations:

  • Response structure is identical to the standard Mistral SDK
  • Error handling uses HTTPValidationError and SDKError exception classes
  • Retry configuration can be set per-operation or SDK-wide

Execution Diagram

GitHub URL

Workflow Repository