Logging and Chat History

The Dify client provides comprehensive logging functionality for both workflow and chat applications.

Quick Examples

# Get workflow logs
workflow_app = client.get_app(app_id="your-workflow-app-id")

# Get paginated logs
logs = workflow_app.get_logs(page=1, limit=10)
for entry in logs.data:
    print(f"Workflow run {entry.workflow_run.id}: {entry.workflow_run.status}")

# Iterate through all logs
for entry in workflow_app.iter_logs(limit=10):
    print(f"Log entry {entry.id} created at {entry.created_at}")

# Get workflow node executions
workflow_run_id = logs.data[0].workflow_run.id
executions = workflow_app.get_node_executions(workflow_run_id)
for node in executions.data:
    print(f"Node {node.title} ({node.node_type}): {node.status}")
    if node.error:
        print(f"Error: {node.error}")

Chat Session

class Chat

Represents a chat conversation session. Used for tracking and retrieving message history.

__init__(client: DifyBaseClient, app: App, id: str, info: dict = None)

Initialize a new chat session.

Parameters:
  • client – The Dify client instance

  • app – The parent application instance

  • id – Unique identifier for the chat session

  • info – Optional additional information about the chat session

property messages(max_pages: int = 10) list

Retrieves chat messages for the conversation, with pagination support. Returns a list of message dictionaries.

Parameters:

max_pages – Maximum number of pages to retrieve (default: 10)

Returns:

List of message dictionaries containing conversation history

Workflow Logging

class WorkflowLogEntry

Represents a single workflow execution log entry.

id: str

Unique identifier for the log entry.

workflow_run: WorkflowRun

Details about the workflow run.

created_at: int

Timestamp when the log entry was created.

class WorkflowRun

Contains information about a specific workflow run.

id: str

Unique identifier for the workflow run.

status: str

Current status of the workflow run.

elapsed_time: float

Time taken to execute the workflow.

Workflow Node Executions

class WorkflowNodeExecution

Represents the execution of a single node in a workflow.

id: str

Unique identifier for the node execution.

node_type: str

Type of the workflow node.

title: str

Title of the node.

status: str

Execution status of the node.

error: str | None

Error message if the node execution failed.

elapsed_time: float

Time taken to execute the node.

inputs: Dict[str, Any] | None

Input parameters provided to the node.

outputs: Dict[str, Any] | None

Output values produced by the node.

class WorkflowNodeExecutions

Container for a list of node executions.

data: List[WorkflowNodeExecution]

List of node executions.