> ## Documentation Index
> Fetch the complete documentation index at: https://chatbase.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming Events

> Reference for ChatStreamEvent, StreamMessageMetadata, ToolCallInfo, and related streaming types.

## ChatStreamEvent

`sealed interface ChatStreamEvent` — **Package:** `com.chatbase.sdk.streaming`

Events emitted by `sendMessageStream()` and `retryStream()`.

**Text Events**

### TextStart

A new text block is starting.

```kotlin theme={null}
data class TextStart(val id: String) : ChatStreamEvent
```

### TextDelta

An incremental text chunk. Append to the current text.

```kotlin theme={null}
data class TextDelta(val id: String, val delta: String) : ChatStreamEvent
```

### TextEnd

The current text block is complete.

```kotlin theme={null}
data class TextEnd(val id: String) : ChatStreamEvent
```

**Tool Events**

### ToolInputStart

A tool call is starting — input will stream incrementally.

```kotlin theme={null}
data class ToolInputStart(
    val toolCallId: String,
    val toolName: String
) : ChatStreamEvent
```

### ToolInputDelta

Incremental tool input text.

```kotlin theme={null}
data class ToolInputDelta(
    val toolCallId: String,
    val inputTextDelta: String
) : ChatStreamEvent
```

### ToolInputAvailable

The tool call's full input is ready.

```kotlin theme={null}
data class ToolInputAvailable(
    val toolCallId: String,
    val toolName: String,
    val input: JsonElement
) : ChatStreamEvent
```

> [!TIP]
>
> Read the full `input` object directly from this event — no need to concatenate preceding deltas.

### ToolOutputAvailable

A tool's execution result is available.

```kotlin theme={null}
data class ToolOutputAvailable(
    val toolCallId: String,
    val output: JsonElement
) : ChatStreamEvent
```

**Step & Lifecycle**

### StepStart / StepFinish

```kotlin theme={null}
object StepStart : ChatStreamEvent
object StepFinish : ChatStreamEvent
```

### Start

The message stream is starting.

```kotlin theme={null}
data class Start(
    val messageId: String?,
    val messageMetadata: StreamMessageMetadata?
) : ChatStreamEvent
```

### Finish

The stream is complete.

```kotlin theme={null}
data class Finish(
    val finishReason: String,
    val messageMetadata: StreamMessageMetadata?
) : ChatStreamEvent
```

`finishReason` is usually `"stop"`, `"error"`, or `"tool-calls"`. Other values (`"length"`, `"content-filter"`, `"other"`, `"unknown"`) are possible and map to `FinishReason.UNKNOWN` in the aggregated `ChatResponse`.

### MessageMetadataEvent

Updated metadata arrived mid-stream.

```kotlin theme={null}
data class MessageMetadataEvent(
    val messageMetadata: StreamMessageMetadata
) : ChatStreamEvent
```

**Error**

### Error

An error occurred during streaming.

```kotlin theme={null}
data class Error(val exception: ChatbaseException) : ChatStreamEvent
```

The `exception` may be an `ApiException` or `NetworkException`. See [Error Handling](https://chatbase.co/docs/android-sdk/error-handling.md).

## StreamMessageMetadata

`data class StreamMessageMetadata` — **Package:** `com.chatbase.sdk.streaming`

Accompanies `Start`, `Finish`, and `MessageMetadataEvent` events.

```kotlin theme={null}
data class StreamMessageMetadata(
    val messageId: String?,
    val userMessageId: String?,
    val conversationId: String?,
    val usage: StreamUsage?
)
```

### StreamUsage

```kotlin theme={null}
data class StreamUsage(val credits: Double = 0.0)
```

## ToolCallInfo

`data class ToolCallInfo` — **Package:** `com.chatbase.sdk`

Passed to the `onToolCall` callback before handler execution.

```kotlin theme={null}
data class ToolCallInfo(
    val toolCallId: String,
    val toolName: String,
    val input: JsonElement
)
```

```kotlin theme={null}
fun inputAsMap(): Map<String, Any?>
```

Parse the JSON input into a `Map<String, Any?>` for easy access.

## ToolResultInfo

`data class ToolResultInfo` — **Package:** `com.chatbase.sdk`

Passed to the `onToolResult` callback after handler execution.

```kotlin theme={null}
data class ToolResultInfo(
    val toolCallId: String,
    val toolName: String,
    val output: Any
)
```

```kotlin theme={null}
fun outputAsString(): String
```

Serialize the output to a JSON string.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.