Implementation:Mistralai Client python GCP ChatCompletionRequest
| 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 GCP Mistral SDK.
Description
The ChatCompletionRequest class in the mistralai_gcp package is a Pydantic model that defines the full request schema for non-streaming chat completions via GCP-hosted Mistral models. Unlike the Azure variant where model defaults to "azureai", the GCP version requires model as a mandatory string field (no default). It includes the same parameter set: message list (discriminated union of UserMessage, SystemMessage, AssistantMessage, ToolMessage), sampling parameters, tool calling configuration, and response formatting. Notably, GCP does not include the safe_prompt parameter present in the Azure variant.
Usage
Import this model when constructing chat completion request payloads for GCP-deployed Mistral models. The Chat.complete() method constructs this internally, but direct instantiation is useful for type-checked request building.
Code Reference
Source Location
- Repository: Mistralai_Client_python
- File: packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py
- Lines: 1-219
Signature
class ChatCompletionRequest(BaseModel):
model: str
messages: List[ChatCompletionRequestMessages]
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
Import
from mistralai_gcp.models import ChatCompletionRequest
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Model ID (required, no default) |
| messages | List[ChatCompletionRequestMessages] | Yes | List of conversation messages (System, User, Assistant, Tool) |
| 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) |
Outputs
| Name | Type | Description |
|---|---|---|
| Serialized dict | Dict[str, Any] | JSON-serializable request body via serialize_model() |
Usage Examples
Building a GCP Chat Request
from mistralai_gcp.models import (
ChatCompletionRequest,
UserMessage,
SystemMessage,
)
request = ChatCompletionRequest(
model="mistral-large-latest", # Required for GCP
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()