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:Cohere ai Cohere python AssistantMessageResponseContentItem Model

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

Overview

The AssistantMessageResponseContentItem is a discriminated union type representing individual content items in an assistant message response, which can be either text or thinking content.

Description

AssistantMessageResponseContentItem is a type alias defined as an annotated union of two Pydantic model classes: TextAssistantMessageResponseContentItem and ThinkingAssistantMessageResponseContentItem. The union is discriminated on the type field. The TextAssistantMessageResponseContentItem variant has type="text" and a text string field containing the generated text. The ThinkingAssistantMessageResponseContentItem variant has type="thinking" and a thinking string field containing the model's internal reasoning. Both variants extend UncheckedBaseModel and are auto-generated from the Cohere API definition by Fern.

Usage

Use this type when iterating over the content list of an AssistantMessageResponse. Each item in the list is an instance of one of the two variants, and the type field can be used to determine which variant is present and access the appropriate content field.

Code Reference

Source Location

  • Repository: Cohere Python SDK
  • File: src/cohere/types/assistant_message_response_content_item.py

Signature

class TextAssistantMessageResponseContentItem(UncheckedBaseModel):
    type: typing.Literal["text"] = "text"
    text: str

class ThinkingAssistantMessageResponseContentItem(UncheckedBaseModel):
    type: typing.Literal["thinking"] = "thinking"
    thinking: str

AssistantMessageResponseContentItem = typing_extensions.Annotated[
    typing.Union[
        TextAssistantMessageResponseContentItem,
        ThinkingAssistantMessageResponseContentItem,
    ],
    UnionMetadata(discriminant="type"),
]

Import

from cohere.types import AssistantMessageResponseContentItem
from cohere.types.assistant_message_response_content_item import (
    TextAssistantMessageResponseContentItem,
    ThinkingAssistantMessageResponseContentItem,
)

I/O Contract

TextAssistantMessageResponseContentItem

Field Type Required Default Description
type Literal["text"] No "text" Discriminant field identifying this as a text content item.
text str Yes - The text content generated by the assistant.

ThinkingAssistantMessageResponseContentItem

Field Type Required Default Description
type Literal["thinking"] No "thinking" Discriminant field identifying this as a thinking content item.
thinking str Yes - The internal reasoning or thought process of the assistant.

Usage Examples

import cohere

client = cohere.ClientV2(api_key="YOUR_API_KEY")

response = client.chat(
    model="command-r-plus",
    messages=[
        {"role": "user", "content": "What is 25 * 43?"},
    ],
)

# Process content items from the assistant message response
if response.message.content:
    for item in response.message.content:
        if item.type == "text":
            print(f"Assistant said: {item.text}")
        elif item.type == "thinking":
            print(f"Assistant thought: {item.thinking}")

# Construct content items manually
from cohere.types.assistant_message_response_content_item import (
    TextAssistantMessageResponseContentItem,
    ThinkingAssistantMessageResponseContentItem,
)

text_item = TextAssistantMessageResponseContentItem(text="The result is 1075.")
thinking_item = ThinkingAssistantMessageResponseContentItem(
    thinking="I need to multiply 25 by 43. 25 * 40 = 1000, 25 * 3 = 75, so 1075."
)

Related Pages

Page Connections

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