Implementation:Groq Groq python ChatCompletionMessageParam
| Knowledge Sources | |
|---|---|
| Domains | NLP, API_Design |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
Concrete type alias for constructing typed chat messages in the Groq Python SDK.
Description
ChatCompletionMessageParam is a Union type alias that accepts any of the five role-specific message TypedDicts: ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, ChatCompletionAssistantMessageParam, ChatCompletionToolMessageParam, and ChatCompletionFunctionMessageParam. Each TypedDict requires a role field and a content field (with role-specific variations).
In practice, users construct messages as plain Python dicts with role and content keys. The SDK's maybe_transform() function validates and transforms these dicts against the TypedDict schemas before sending.
Usage
Use this type when constructing the messages parameter for client.chat.completions.create(). Messages can be plain dicts or typed TypedDict instances. At minimum, provide one user message.
Code Reference
Source Location
- Repository: groq-python
- File: src/groq/types/chat/chat_completion_message_param.py
- Lines: L1-22
Signature
ChatCompletionMessageParam: TypeAlias = Union[
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
ChatCompletionAssistantMessageParam,
ChatCompletionToolMessageParam,
ChatCompletionFunctionMessageParam,
]
Import
from groq.types.chat import ChatCompletionMessageParam
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| role | Literal["system", "user", "assistant", "tool", "function"] | Yes | The role of the message author |
| content | str or List[ContentPart] | Yes | The message content (text or multipart) |
| name | str | No | Optional name for the message author |
| tool_calls | List[ToolCall] | No | Tool call requests (assistant messages only) |
| tool_call_id | str | No | ID of the tool call this message responds to (tool messages only) |
Outputs
| Name | Type | Description |
|---|---|---|
| (value) | ChatCompletionMessageParam | A typed message dict ready for the create() call |
Usage Examples
Basic Message List
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the importance of low latency LLMs"},
]
Multi-turn Conversation
messages = [
{"role": "system", "content": "You are a coding assistant."},
{"role": "user", "content": "Write a Python function to sort a list."},
{"role": "assistant", "content": "def sort_list(lst):\n return sorted(lst)"},
{"role": "user", "content": "Now make it sort in descending order."},
]
With Tool Message
messages = [
{"role": "user", "content": "What is the weather in Paris?"},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": '{"city": "Paris"}'
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": '{"temperature": 18, "condition": "sunny"}'
},
]