Implementation:Cohere ai Cohere python Type Aliases
| Knowledge Sources | |
|---|---|
| Domains | SDK, Type System |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Defines type aliases that map v2 API response types to simplified and backward-compatible naming conventions.
Description
The aliases module creates convenience type aliases for the Cohere v2 chat API response classes. It maps verbose v2-prefixed class names (such as V2ChatResponse and V2ChatStreamResponse) to shorter, more user-friendly names (such as ChatResponse and StreamedChatResponseV2). This module also imports overrides early to ensure backward-compatibility patches (e.g., making ToolCallV2.id optional) are applied before any types are used.
Usage
Import these aliases when you want to reference Cohere chat response types by their simplified names rather than the full v2 class names. They are especially useful for type annotations and when working with chat or streaming response objects in application code.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/aliases.py
Signature
from .v2 import (
ContentDeltaV2ChatStreamResponse,
ContentEndV2ChatStreamResponse,
ContentStartV2ChatStreamResponse,
MessageEndV2ChatStreamResponse,
MessageStartV2ChatStreamResponse,
ToolCallDeltaV2ChatStreamResponse,
ToolCallEndV2ChatStreamResponse,
ToolCallStartV2ChatStreamResponse,
V2ChatStreamResponse,
V2ChatResponse,
)
# alias classes
StreamedChatResponseV2 = V2ChatStreamResponse
MessageStartStreamedChatResponseV2 = MessageStartV2ChatStreamResponse
MessageEndStreamedChatResponseV2 = MessageEndV2ChatStreamResponse
ContentStartStreamedChatResponseV2 = ContentStartV2ChatStreamResponse
ContentDeltaStreamedChatResponseV2 = ContentDeltaV2ChatStreamResponse
ContentEndStreamedChatResponseV2 = ContentEndV2ChatStreamResponse
ToolCallStartStreamedChatResponseV2 = ToolCallStartV2ChatStreamResponse
ToolCallDeltaStreamedChatResponseV2 = ToolCallDeltaV2ChatStreamResponse
ToolCallEndStreamedChatResponseV2 = ToolCallEndV2ChatStreamResponse
ChatResponse = V2ChatResponse
Import
from cohere.aliases import ChatResponse, StreamedChatResponseV2
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This module defines type aliases only; it takes no runtime inputs. |
Outputs
| Name | Type | Description |
|---|---|---|
| ChatResponse | Type alias for V2ChatResponse | Simplified name for the v2 chat response type. |
| StreamedChatResponseV2 | Type alias for V2ChatStreamResponse | Simplified name for the v2 streaming chat response type. |
| MessageStartStreamedChatResponseV2 | Type alias for MessageStartV2ChatStreamResponse | Alias for the message-start streaming event type. |
| MessageEndStreamedChatResponseV2 | Type alias for MessageEndV2ChatStreamResponse | Alias for the message-end streaming event type. |
| ContentStartStreamedChatResponseV2 | Type alias for ContentStartV2ChatStreamResponse | Alias for the content-start streaming event type. |
| ContentDeltaStreamedChatResponseV2 | Type alias for ContentDeltaV2ChatStreamResponse | Alias for the content-delta streaming event type. |
| ContentEndStreamedChatResponseV2 | Type alias for ContentEndV2ChatStreamResponse | Alias for the content-end streaming event type. |
| ToolCallStartStreamedChatResponseV2 | Type alias for ToolCallStartV2ChatStreamResponse | Alias for the tool-call-start streaming event type. |
| ToolCallDeltaStreamedChatResponseV2 | Type alias for ToolCallDeltaV2ChatStreamResponse | Alias for the tool-call-delta streaming event type. |
| ToolCallEndStreamedChatResponseV2 | Type alias for ToolCallEndV2ChatStreamResponse | Alias for the tool-call-end streaming event type. |
Usage Examples
from cohere.aliases import ChatResponse, StreamedChatResponseV2
# Use ChatResponse as a type annotation for non-streaming responses
def handle_chat(response: ChatResponse) -> str:
return response.text
# Use StreamedChatResponseV2 for streaming event type checks
def process_stream_event(event: StreamedChatResponseV2) -> None:
print(event)