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.

Implementation:Mistralai Client python Azure ChatCompletionRequest

From Leeroopedia
Knowledge Sources
Domains Chat_Completion, Cloud_Integration
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for defining the request body of non-streaming chat completions in the Azure Mistral SDK.

Description

The ChatCompletionRequest class is a Pydantic model that defines the full request schema for non-streaming chat completions via Azure-hosted Mistral models. It includes the message list (discriminated union of UserMessage, SystemMessage, AssistantMessage, ToolMessage), sampling parameters (temperature, top_p, max_tokens), tool calling configuration (tools, tool_choice, parallel_tool_calls), response formatting (response_format), and Azure-specific defaults (model defaults to "azureai", safe_prompt, prompt_mode). The class uses a custom serialize_model method to handle optional/nullable field semantics.

Usage

Import this model when constructing chat completion request payloads for Azure-deployed Mistral models. The Chat.complete() method constructs this internally, but direct instantiation is useful for type-checked request building or custom API calls.

Code Reference

Source Location

Signature

class ChatCompletionRequest(BaseModel):
    messages: List[ChatCompletionRequestMessages]
    model: Optional[str] = "azureai"
    temperature: OptionalNullable[float] = UNSET
    top_p: Optional[float] = None
    max_tokens: OptionalNullable[int] = UNSET
    stream: Optional[bool] = False
    stop: Optional[ChatCompletionRequestStop] = None
    random_seed: OptionalNullable[int] = UNSET
    metadata: OptionalNullable[Dict[str, Any]] = UNSET
    response_format: Optional[ResponseFormat] = None
    tools: OptionalNullable[List[Tool]] = UNSET
    tool_choice: Optional[ChatCompletionRequestToolChoice] = None
    presence_penalty: Optional[float] = None
    frequency_penalty: Optional[float] = None
    n: OptionalNullable[int] = UNSET
    prediction: Optional[Prediction] = None
    parallel_tool_calls: Optional[bool] = None
    prompt_mode: OptionalNullable[MistralPromptMode] = UNSET
    safe_prompt: Optional[bool] = None

Import

from mistralai_azure.models import ChatCompletionRequest

I/O Contract

Inputs

Name Type Required Description
messages List[ChatCompletionRequestMessages] Yes List of conversation messages (System, User, Assistant, Tool)
model Optional[str] No Model ID (defaults to "azureai")
temperature OptionalNullable[float] No Sampling temperature (0.0-0.7 recommended)
top_p Optional[float] No Nucleus sampling probability mass
max_tokens OptionalNullable[int] No Maximum tokens to generate
stream Optional[bool] No Whether to stream (default False)
stop Optional[Union[str, List[str]]] No Stop token(s)
tools OptionalNullable[List[Tool]] No Available tools for function calling
tool_choice Optional[Union[ToolChoice, ToolChoiceEnum]] No Tool selection strategy
response_format Optional[ResponseFormat] No Output format (text, json_object, json_schema)
safe_prompt Optional[bool] No Whether to inject safety prompt

Outputs

Name Type Description
Serialized dict Dict[str, Any] JSON-serializable request body via serialize_model()

Usage Examples

Building a Chat Request

from mistralai_azure.models import (
    ChatCompletionRequest,
    UserMessage,
    SystemMessage,
)

request = ChatCompletionRequest(
    messages=[
        SystemMessage(content="You are a helpful assistant."),
        UserMessage(content="What is the capital of France?"),
    ],
    temperature=0.3,
    max_tokens=100,
)

# Serialize for API call
payload = request.model_dump()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment