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 NonStreamedChatResponse Model

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

Overview

NonStreamedChatResponse is a Pydantic model representing the complete response from a non-streaming Cohere chat API call, including generated text, citations, documents, search results, tool calls, and metadata.

Description

The NonStreamedChatResponse class extends UncheckedBaseModel and encapsulates all the data returned by the Cohere chat endpoint in non-streaming mode. The primary field is text, which contains the model's generated reply. Additional fields provide supporting information for RAG (Retrieval-Augmented Generation) workflows: citations for inline source references, documents for referenced documents, search_queries for generated search queries, and search_results for retrieved documents. The response also includes generation_id and response_id for tracking, tool_calls for function calling workflows, chat_history for conversational context, finish_reason for completion status, and meta for API metadata.

Usage

Use NonStreamedChatResponse when processing the result of a non-streaming chat API call. This is the primary response type returned by client.chat() when streaming is not enabled. It provides access to the generated text, any citations or documents used in RAG flows, tool call results, and the updated conversation history.

Code Reference

Source Location

Signature

class NonStreamedChatResponse(UncheckedBaseModel):
    text: str = pydantic.Field()
    generation_id: typing.Optional[str] = pydantic.Field(default=None)
    response_id: typing.Optional[str] = pydantic.Field(default=None)
    citations: typing.Optional[typing.List[ChatCitation]] = pydantic.Field(default=None)
    documents: typing.Optional[typing.List[ChatDocument]] = pydantic.Field(default=None)
    is_search_required: typing.Optional[bool] = pydantic.Field(default=None)
    search_queries: typing.Optional[typing.List[ChatSearchQuery]] = pydantic.Field(default=None)
    search_results: typing.Optional[typing.List[ChatSearchResult]] = pydantic.Field(default=None)
    finish_reason: typing.Optional[FinishReason] = None
    tool_calls: typing.Optional[typing.List[ToolCall]] = None
    chat_history: typing.Optional[typing.List[Message]] = pydantic.Field(default=None)
    meta: typing.Optional[ApiMeta] = None

Import

from cohere.types import NonStreamedChatResponse

I/O Contract

Fields

Field Type Required Default Description
text str Yes -- Contents of the reply generated by the model.
generation_id Optional[str] No None Unique identifier for the generated reply, useful for submitting feedback.
response_id Optional[str] No None Unique identifier for the response.
citations Optional[List[ChatCitation]] No None Inline citations for the generated reply.
documents Optional[List[ChatDocument]] No None Documents seen by the model when generating the reply.
is_search_required Optional[bool] No None Denotes that a search for documents is required during the RAG flow.
search_queries Optional[List[ChatSearchQuery]] No None Generated search queries for the RAG flow.
search_results Optional[List[ChatSearchResult]] No None Documents retrieved from each of the conducted searches.
finish_reason Optional[FinishReason] No None The reason the model stopped generating tokens.
tool_calls Optional[List[ToolCall]] No None Tool calls generated by the model.
chat_history Optional[List[Message]] No None A list of previous messages between the user and the model for conversational context.
meta Optional[ApiMeta] No None API metadata for the response.

Usage Examples

import cohere

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

# Basic non-streaming chat call
response = client.chat(
    model="command-r-plus",
    message="Explain quantum computing in simple terms.",
)

# Access the generated text
print(response.text)

# Check generation metadata
print(f"Generation ID: {response.generation_id}")
print(f"Finish reason: {response.finish_reason}")

# Access citations in a RAG response
if response.citations:
    for citation in response.citations:
        print(f"Citation: {citation}")

# Access search results from RAG flow
if response.search_results:
    for result in response.search_results:
        print(f"Search result: {result}")

# Inspect chat history for multi-turn context
if response.chat_history:
    for msg in response.chat_history:
        if hasattr(msg, "message"):
            print(f"[{msg.role}] {msg.message}")

# Check for tool calls
if response.tool_calls:
    for tool_call in response.tool_calls:
        print(f"Tool call: {tool_call.name}({tool_call.parameters})")

Related Pages

Page Connections

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